Update shema for VFC
[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, 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                 try (TitanGraph graph = TitanFactory.open(config)) {
60                         if (!("oxm".equals(cArgs.type) || "graph".equals(cArgs.type))) {
61                                 System.out.println("type: " + cArgs.type + " not recognized.");
62                                 System.exit(1);
63                         }
64
65                         AuditDoc doc = null;
66                         if ("oxm".equals(cArgs.type)) {
67                                 doc = AuditorFactory.getOXMAuditor(Version.v8).getAuditDoc();
68                         } else if ("graph".equals(cArgs.type)) {
69                                 doc = AuditorFactory.getGraphAuditor(graph).getAuditDoc();
70                         }
71
72                         ObjectMapper mapper = new ObjectMapper();
73
74                         String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(doc);
75                         System.out.println(json);
76                 }
77         }
78         
79 }
80
81 class CommandLineArgs {
82         
83         @Parameter(names = "--help", description = "Help")
84         public boolean help = false;
85         
86         @Parameter(names = "-c", description = "Configuration", required=true)
87         public String config;
88         
89         @Parameter(names = "-type", description = "Type", required=true)
90         public String type = "graph";
91         
92
93 }