Update the license for 2017-2018 license
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / db / schema / ScriptDriver.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.aai.db.schema;
21
22 import java.io.IOException;
23 import java.util.UUID;
24
25 import org.apache.commons.configuration.ConfigurationException;
26 import org.codehaus.jackson.JsonGenerationException;
27 import org.codehaus.jackson.map.JsonMappingException;
28 import org.codehaus.jackson.map.ObjectMapper;
29 import org.onap.aai.dbmap.AAIGraphConfig;
30 import org.onap.aai.exceptions.AAIException;
31 import org.onap.aai.introspection.Version;
32 import org.onap.aai.logging.LoggingContext;
33 import org.onap.aai.logging.LoggingContext.StatusCode;
34 import org.onap.aai.util.AAIConfig;
35 import com.beust.jcommander.JCommander;
36 import com.beust.jcommander.Parameter;
37 import com.thinkaurelius.titan.core.TitanFactory;
38 import com.thinkaurelius.titan.core.TitanGraph;
39
40 public class ScriptDriver {
41
42
43         /**
44          * The main method.
45          *
46          * @param args the arguments
47          * @throws AAIException the AAI exception
48          * @throws JsonGenerationException the json generation exception
49          * @throws JsonMappingException the json mapping exception
50          * @throws IOException Signals that an I/O exception has occurred.
51          */
52         public static void main (String[] args) throws AAIException, IOException, ConfigurationException {
53                 CommandLineArgs cArgs = new CommandLineArgs();
54                 
55                 LoggingContext.init();
56                 LoggingContext.component("DBSchemaScriptDriver");
57                 LoggingContext.partnerName("NA");
58                 LoggingContext.targetEntity("AAI");
59                 LoggingContext.requestId(UUID.randomUUID().toString());
60                 LoggingContext.serviceName("AAI");
61                 LoggingContext.targetServiceName("main");
62                 LoggingContext.statusCode(StatusCode.COMPLETE);
63                 LoggingContext.responseCode(LoggingContext.SUCCESS);
64                 
65                 new JCommander(cArgs, args);
66                 
67                 if (cArgs.help) {
68                         System.out.println("-c [path to graph configuration] -type [what you want to audit - oxm or graph]");
69                 }
70                 String config = cArgs.config;
71                 AAIConfig.init();
72                 try (TitanGraph graph = TitanFactory.open(new AAIGraphConfig.Builder(config).forService(ScriptDriver.class.getSimpleName()).withGraphType("NA").buildConfiguration())) {
73                         if (!("oxm".equals(cArgs.type) || "graph".equals(cArgs.type))) {
74                                 System.out.println("type: " + cArgs.type + " not recognized.");
75                                 System.exit(1);
76                         }
77
78                         AuditDoc doc = null;
79                         if ("oxm".equals(cArgs.type)) {
80                                 doc = AuditorFactory.getOXMAuditor(Version.v8).getAuditDoc();
81                         } else if ("graph".equals(cArgs.type)) {
82                                 doc = AuditorFactory.getGraphAuditor(graph).getAuditDoc();
83                         }
84
85                         ObjectMapper mapper = new ObjectMapper();
86
87                         String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(doc);
88                         System.out.println(json);
89                 }
90         }
91         
92 }
93
94 class CommandLineArgs {
95         
96         @Parameter(names = "--help", description = "Help")
97         public boolean help = false;
98         
99         @Parameter(names = "-c", description = "Configuration", required=true)
100         public String config;
101         
102         @Parameter(names = "-type", description = "Type", required=true)
103         public String type = "graph";
104         
105
106 }