This project has retired. For details please refer to its Attic page.
App xref
View Javadoc
1   /*
2    * Copyright 2013 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.juddi.v3.migration.tool;
17  
18  import java.util.Random;
19  import org.apache.commons.cli.BasicParser;
20  import org.apache.commons.cli.CommandLine;
21  import org.apache.commons.cli.CommandLineParser;
22  import org.apache.commons.cli.HelpFormatter;
23  import org.apache.commons.cli.Options;
24  import org.apache.commons.cli.ParseException;
25  
26  /**
27   * Main entry point for the UDDI migration tool
28   *
29   * @author Alex O'Ree
30   * @since 3.2
31   *
32   */
33  public class App {
34  
35      public static void main(String[] args) throws ParseException, Exception {
36          System.out.println("This tool is used to export and import UDDI data from a UDDI v3 registry");
37          System.out.println("Random TIP: " + RandomTip());
38          System.out.println();
39  
40          Options options = new Options();
41          options.addOption("import", false, "Imports data into a UDDIv3 registry");
42          options.addOption("export", false, "Exports data into a UDDIv3 registry");
43          options.addOption("user", true, "Username, if not defined, those is uddi.xml will be used");
44          options.addOption("pass", true, "Password, if not defined, those is uddi.xml will be used");
45          //options.addOption("safeMode", false, "Prevents overriding existing entities, saves items one at a time");
46          options.addOption("config", true, "Use an alternate config file default is 'uddi.xml'");
47          options.addOption("node", true, "The node 'name' in the config, default is 'default'");
48          options.addOption("isJuddi", false, "Is this a jUDDI registry? If so we can in/export more stuff");
49          options.addOption("tmodel", true, "Im/Export for tmodels, file to store tmodel data, default is 'tmodel-export.xml'");
50          options.addOption("business", true, "Im/Export option, file to store the business data, default is 'business-export.xml'");
51          options.addOption("mappings", true, "Im/Export option, file that maps keys to owners, default is 'entityusermappings.properties'");
52          options.addOption("publishers", true, "jUDDI only - In/Export option, file to store publishers, default is 'publishers-export.xml'");
53          options.addOption("myItemsOnly", false, "Export option, Only export items owned by yourself");
54          options.addOption("preserveOwnership", false, "Im/Export option, saves owership data to the 'mappings' file");
55          options.addOption("credFile", true, "Import option with -preserveOwnership, this is a properties file mapping with user=pass");
56          options.addOption("stripSignatures", false, "Im/Export option, removes digital signatures from all signed items, default is false");
57  
58  
59          // create the parser
60          CommandLineParser parser = new BasicParser();
61          CommandLine line = null;
62          try {
63              // parse the command line arguments
64              line = parser.parse(options, args);
65  
66              if (line.hasOption("import") && line.hasOption("export")) {
67                  ShowHelp(options);
68                  return;
69              }
70              if (!line.hasOption("import") && !line.hasOption("export")) {
71                  ShowHelp(options);
72                  return;
73              }
74              String config = line.getOptionValue("config", "uddi.xml");
75              boolean stripSig = line.hasOption("stripSignatures");
76              String node = line.getOptionValue("node", "default");
77  
78              String pass = line.getOptionValue("pass", null);
79              String user = line.getOptionValue("user", null);
80  
81              String tmodel = line.getOptionValue("tmodel", "tmodel-export.xml");
82              String business = line.getOptionValue("business", "business-export.xml");
83              String publishers = line.getOptionValue("publishers", "publishers-export.xml");
84              //username to password
85              String credFile = line.getOptionValue("credFile", "credentials.properties");
86              //key to username
87              String mappings = line.getOptionValue("mappings", "entityusermappings.properties");
88              boolean preserveOwnership = line.hasOption("preserveOwnership");
89              boolean juddi = line.hasOption("isJuddi");
90              boolean myItemsOnly = line.hasOption("myItemsOnly");
91              boolean safe = true;//line.hasOption("safeMode");
92              if (line.hasOption("export")) //CommandLine cmd = parser.parse(options, args);
93              {
94                  System.out.println("Exporting...");
95                  new Export().Execute(config, node, user, pass, tmodel, business, juddi, safe, publishers, myItemsOnly, mappings, preserveOwnership, credFile,stripSig);
96                  System.out.println();
97                  if (preserveOwnership) {
98                      System.out.println("Next step(s), Edit the " + credFile + " and make any adjustments that are necessary.");
99                      System.out.println("TIP: if you're using juddi, you can temporarily switch to the 'JuddiAuthenticator' which doesn't validate passwords.");
100                 }
101                 System.out.println("Next step(s), Edit " + config + " to point to the next registry. Then try -import. You can also specify a different node.");
102             }
103             if (line.hasOption("import")) //CommandLine cmd = parser.parse(options, args);
104             {
105                 System.out.println("Importing...");
106                 new Import().Execute(config, node, user, pass, tmodel, business, juddi, safe, publishers, preserveOwnership, mappings, credFile,stripSig);
107             }
108 
109 
110         } catch (Exception exp) {
111             // oops, something went wrong
112             ShowHelp(options);
113             System.err.println("Failed!");
114             exp.printStackTrace();
115         }
116 
117 
118     }
119 
120     private static void ShowHelp(Options options) {
121         HelpFormatter formatter = new HelpFormatter();
122         formatter.printHelp("java -jar juddi-migration-tool-(VERSION)-jar-with-dependencies.jar", options);
123     }
124 
125     private static String RandomTip() {
126         String[] tips = new String[]{
127             "You can use setup custom SSL trust/key stores using -Djavax.net.ssl.keyStore=file -javax.net.ssl.keyStorePassword=pwd -Djavax.net.ssl.trustStore=file "
128             + "-Djavax.net.ssl.trustStorePassword=pwd",
129             "You can easily script the UDDI migration tool and use it as a backup mechanism.",
130             "You can protect credentials by storing them in uddi client config file.",
131             "This tool can only work with UDDI v3 registries.",
132             "With the preserveOwnership flag, you can maintain entity ownership.",
133             "Without the preserveOwnership flag, all imported data will be owned by the username that imported it."
134         };
135         Random r = new Random();
136         return tips[r.nextInt(tips.length)];
137     }
138 }