Initial commit with all the necessary files
[aai/aai-common.git] / aai-core / src / main / java / org / openecomp / aai / db / schema / ScriptDriver.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.openecomp.aai
4  * ================================================================================
5  * Copyright (C) 2017 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
21 package org.openecomp.aai.db.schema;
22
23 import java.io.IOException;
24
25 import org.codehaus.jackson.JsonGenerationException;
26 import org.codehaus.jackson.map.JsonMappingException;
27 import org.codehaus.jackson.map.ObjectMapper;
28
29 import org.openecomp.aai.exceptions.AAIException;
30 import org.openecomp.aai.introspection.Version;
31 import org.openecomp.aai.util.AAIConfig;
32 import com.beust.jcommander.JCommander;
33 import com.beust.jcommander.Parameter;
34 import com.thinkaurelius.titan.core.TitanFactory;
35 import com.thinkaurelius.titan.core.TitanGraph;
36
37 public class ScriptDriver {
38
39         
40         /**
41          * The main method.
42          *
43          * @param args the arguments
44          * @throws AAIException the AAI exception
45          * @throws JsonGenerationException the json generation exception
46          * @throws JsonMappingException the json mapping exception
47          * @throws IOException Signals that an I/O exception has occurred.
48          */
49         public static void main (String[] args) throws AAIException, JsonGenerationException, JsonMappingException, IOException {
50                 CommandLineArgs cArgs = new CommandLineArgs();
51                 
52                 new JCommander(cArgs, args);
53                 
54                 if (cArgs.help) {
55                         System.out.println("-c [path to graph configuration] -type [what you want to audit - oxm or graph]");
56                 }
57                 String config = cArgs.config;
58                 AAIConfig.init();
59                 TitanGraph graph = TitanFactory.open(config);
60                 if (!(cArgs.type.equals("oxm") || cArgs.type.equals("graph"))) {
61                         System.out.println("type: " + cArgs.type + " not recognized.");
62                         System.exit(1);
63                 }
64                 
65                 Auditor a = null;
66                 if (cArgs.type.equals("oxm")) {
67                         a = AuditorFactory.getOXMAuditor(Version.v8);
68                 } else if (cArgs.type.equals("graph")) {
69                         a = AuditorFactory.getGraphAuditor(graph);
70                 }
71                 
72                 AuditDoc doc = a.getAuditDoc();
73                 
74                 ObjectMapper mapper = new ObjectMapper();
75                 
76                 String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(doc);
77                 System.out.println(json);
78                 
79         }
80         
81 }
82
83 class CommandLineArgs {
84         
85         @Parameter(names = "--help", description = "Help")
86         public boolean help = false;
87         
88         @Parameter(names = "-c", description = "Configuration", required=true)
89         public String config;
90         
91         @Parameter(names = "-type", description = "Type", required=true)
92         public String type = "graph";
93         
94
95 }