View Javadoc

1   /*
2    * GUMS2MapUser.java
3    *
4    * Created on June 9, 2004, 1:44 PM
5    */
6   package gov.bnl.gums.admin;
7   
8   
9   import org.apache.axis.AxisFault;
10  
11  import org.apache.commons.cli.*;
12  
13  import java.net.ConnectException;
14  import java.net.InetAddress;
15  import java.net.URL;
16  import gov.bnl.gums.command.AbstractCommand;
17  
18  
19  /**
20   * @author carcassi
21   * @depricated
22   */
23  public class Pool_AddRange extends RemoteCommand {
24      static {
25          command = new Pool_AddRange();
26      }
27  
28      /**
29       * Creates a new ManualGroup_Add object.
30       */
31      public Pool_AddRange() {
32          syntax = "PERSISTANCE GROUP RANGE";
33          description = "Adds range of accounts to a pool. " +
34              "PERSISTANCE is the 'persistenceFactory' as defined in the configuration for the group. " +
35              "GROUP is the 'name' as defined in the configuration for the pool. " +
36              "RANGE is the group of accounts to be added (i.e. grid0050-125)." +
37              "NOTE: This command is depricated in favor of PoolAddRange; required with 1.1 server";
38      }
39  
40      protected org.apache.commons.cli.Options buildOptions() {
41          Options options = new Options();
42  
43          return options;
44      }
45  
46      protected void execute(org.apache.commons.cli.CommandLine cmd)
47          throws Exception {
48          if (cmd.getArgs().length < 3) {
49              failForWrongParameters("Missing parameters...");
50          }
51  
52          String[] userDN = (cmd.getArgs());
53          String persistenceFactory = cmd.getArgs()[0];
54          String groupName = cmd.getArgs()[1];
55  
56          for (int nArg = 2; nArg < cmd.getArgs().length; nArg++) {
57              addRange(persistenceFactory, groupName,
58                  cmd.getArgs()[nArg]);
59          }
60      }
61  
62      private void addRange(String persistenceFactory, String groupName, String range) throws Exception {
63          String firstAccount = range.substring(0, range.indexOf('-'));
64          String lastAccountN = range.substring(range.indexOf('-') + 1);
65          String firstAccountN = firstAccount.substring(firstAccount.length() - lastAccountN.length());
66          String accountBase = firstAccount.substring(0, firstAccount.length() - lastAccountN.length());
67          int nFirstAccount = Integer.parseInt(firstAccountN);
68          int nLastAccount = Integer.parseInt(lastAccountN);
69  
70          StringBuffer last = new StringBuffer(firstAccount);
71          String nLastAccountString = Integer.toString(nLastAccount);
72          last.replace(firstAccount.length() - nLastAccountString.length(), firstAccount.length(), nLastAccountString);
73          
74          System.out.println("Adding accounts between '" + firstAccount + "' and '" + last.toString() + "' to pool '" + groupName + "'");
75          
76          StringBuffer buf = new StringBuffer(firstAccount);
77          int len = firstAccount.length();
78          for (int account = nFirstAccount; account <= nLastAccount; account++) {
79              String nAccount = Integer.toString(account);
80              buf.replace(len - nAccount.length(), len, nAccount);
81              getGums().poolAddAccount(persistenceFactory, groupName, buf.toString());
82              System.out.println(buf.toString() + " added");
83          }
84      }
85  }