Commit for the blueprint generator java tool
[dcaegen2/platform/cli.git] / blueprint-generator / src / main / java / org / onap / blueprintgenerator / core / BlueprintGenerator.java
1 /**============LICENSE_START======================================================= 
2  org.onap.dcae 
3  ================================================================================ 
4  Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. 
5  ================================================================================ 
6  Licensed under the Apache License, Version 2.0 (the "License"); 
7  you may not use this file except in compliance with the License. 
8  You may obtain a copy of the License at 
9
10       http://www.apache.org/licenses/LICENSE-2.0 
11
12  Unless required by applicable law or agreed to in writing, software 
13  distributed under the License is distributed on an "AS IS" BASIS, 
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
15  See the License for the specific language governing permissions and 
16  limitations under the License. 
17  ============LICENSE_END========================================================= 
18
19  */
20
21 package org.onap.blueprintgenerator.core;
22
23
24
25 import org.apache.commons.cli.BasicParser;
26 import org.apache.commons.cli.CommandLine;
27 import org.apache.commons.cli.Options;
28 import org.onap.blueprintgenerator.models.blueprint.Blueprint;
29 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
30
31
32
33 @SuppressWarnings("deprecation")
34 public class BlueprintGenerator {
35
36         private static String componentSpecPath = "";
37
38         private static String bluePrintName = "";
39
40         private static String outputPath = "";
41
42         private static char bpType = 'o';
43         
44         private static String importPath = "";
45
46
47         public static void main(String[] args) throws Exception {
48
49                 printInstructions();
50                 
51                 parseInputs(args);
52                 
53
54                 //create the component Spec we are going to be working with
55                 ComponentSpec cs = new ComponentSpec();
56                 cs.createComponentSpecFromFile(componentSpecPath);
57 //              if(bpType != 't') {
58 //                      cs.createComponentSpecFromFile(componentSpecPath);
59 //              }
60 //              if(bpType == 't') {
61 //                      Self self = new Self();
62 //                      self.setName("blueprint_template");
63 //                      self.setDescription("A template yaml file for blueprints");
64 //                      self.setVersion("1.0.0");
65 //                      self.setComponent_type("template");
66 //                      cs.setSelf(self);
67 //              }
68
69                 Blueprint bp = new Blueprint();
70                 bp = bp.createBlueprint(cs, bluePrintName, bpType, importPath);
71                 bp.blueprintToYaml(outputPath, bluePrintName, cs);
72         }
73
74
75         public static void printInstructions() {
76                 System.out.println("OPTIONS:");
77                 System.out.println("-i: The path to the JSON spec file (required)");
78                 System.out.println("-n: Name of the blueprint (optional)");
79                 System.out.println("-p: The path to the final blueprint (required)");
80                 System.out.println("-t: The path to the yaml import file (optional)");
81                 //System.out.println("-t: This flag will create a template of how a blueprint will look. No ComponentSpec is required if you add this flag (optional");
82
83         }
84
85
86         public static void parseInputs(String[] args) throws Exception {
87                 //convert the arguments array to a string to make it easier
88                 String commands = "";
89                 for(String s: args) {
90                         if(commands.length() == 0) {
91                                 commands = s;
92                         }
93                         else {
94                                 commands = commands + " " + s;
95                         }       
96                 }
97                 //check if it has the required inputs
98 //              if(commands.contains("-t")) {
99 //                      bpType = 't';
100 //                      CommandLineParser parser = new BasicParser();
101 //                      Options options = new Options();
102 //                      options.addOption("p", "Path", true, "Path to the final blueprint");
103 //                      options.addOption("i", "Spec", true, "ComponentSpec import file");
104 //                      options.addOption("n", "name", true, "Name of the blueprint");
105 //                      options.addOption("t", "Template", false, "Create a bp tempalte");
106 //                      CommandLine commandLine = parser.parse(options, args);
107 //                      outputPath = commandLine.getOptionValue("p");
108 //              }
109                 if(!commands.contains("-p") || !commands.contains("-i")) {
110                         System.out.println("did not enter the required inputs");
111                 }
112                 else {
113                         BasicParser parser = new BasicParser();
114                         Options options = new Options();
115                         options.addOption("i", "Spec", true, "ComponentSpec import file");
116                         options.addOption("p", "Path", true, "Path to the final blueprint");
117                         options.addOption("n", "Name", true, "Name of the blueprint");
118                         options.addOption("t", "imports", true, "Path to the import file");
119
120                         CommandLine commandLine = parser.parse(options, args);
121                         componentSpecPath = commandLine.getOptionValue("i");
122                         outputPath = commandLine.getOptionValue("p");
123                         if(!(commandLine.getOptionValue("n") == null)){
124                                 bluePrintName = commandLine.getOptionValue("n");
125                         }
126                         if(!(commandLine.getOptionValue("t") == null)) {
127                                 importPath = commandLine.getOptionValue("t");
128                         }
129                 }
130
131         }
132
133
134
135 }
136