BpGen refactor Code Quality Issue-ID: DCAEGEN2-2502
[dcaegen2/platform.git] / mod / bpgenerator / onap / src / main / java / org / onap / blueprintgenerator / BlueprintGeneratorMainApplication.java
1 /*
2  *
3  *  * ============LICENSE_START=======================================================
4  *  *  org.onap.dcae
5  *  *  ================================================================================
6  *  *  Copyright (c) 2020  AT&T Intellectual Property. All rights reserved.
7  *  *  ================================================================================
8  *  *  Licensed under the Apache License, Version 2.0 (the "License");
9  *  *  you may not use this file except in compliance with the License.
10  *  *  You may obtain a copy of the License at
11  *  *
12  *  *       http://www.apache.org/licenses/LICENSE-2.0
13  *  *
14  *  *  Unless required by applicable law or agreed to in writing, software
15  *  *  distributed under the License is distributed on an "AS IS" BASIS,
16  *  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *  *  See the License for the specific language governing permissions and
18  *  *  limitations under the License.
19  *  *  ============LICENSE_END=========================================================
20  *
21  *
22  */
23
24 package org.onap.blueprintgenerator;
25
26 import org.onap.blueprintgenerator.model.base.Blueprint;
27 import org.onap.blueprintgenerator.model.common.Input;
28 import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
29 import org.onap.blueprintgenerator.model.componentspec.base.ComponentSpec;
30 import org.onap.blueprintgenerator.service.OnapBlueprintService;
31 import org.onap.blueprintgenerator.service.common.CommonUtils;
32 import org.onap.blueprintgenerator.service.common.ComponentSpecService;
33 import org.onap.blueprintgenerator.service.dmaap.DmaapBlueprintService;
34 import org.onap.policycreate.service.PolicyModelService;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.boot.CommandLineRunner;
37 import org.springframework.boot.SpringApplication;
38 import org.springframework.boot.autoconfigure.SpringBootApplication;
39 import org.springframework.context.annotation.ComponentScan;
40
41 import static java.lang.System.exit;
42
43 /**
44  * @author : Ravi Mantena
45  * @date 10/16/2020 Application: ONAP - Blueprint Generator ONAP - Blueprint Generator Main
46  * Application to create Policy Models or Blueprints
47  */
48 @ComponentScan({"org.onap.blueprintgenerator", "org.onap.policycreate"})
49 @SpringBootApplication
50 public class BlueprintGeneratorMainApplication implements CommandLineRunner {
51
52     @Autowired
53     private ComponentSpecService componentSpecService;
54
55     @Autowired
56     private PolicyModelService policyModelService;
57
58     @Autowired
59     private CommonUtils commonUtils;
60
61     @Autowired
62     private PolicyModelService onapPolicyModelNodeService;
63
64     @Autowired
65     private ComponentSpecService onapComponentSpecService;
66
67     @Autowired
68     private CommonUtils onapCommonUtils;
69
70     @Autowired
71     private OnapBlueprintService onapBlueprintService;
72
73     @Autowired
74     private DmaapBlueprintService dmaapBlueprintService;
75
76     /**
77      * Main Application to run BPGen to generate Policies/Blueprint based on Input Arguments values
78      *
79      * @param args Input Arguments
80      */
81     public static void main(String[] args) {
82         SpringApplication.run(BlueprintGeneratorMainApplication.class, args);
83     }
84
85     /**
86      * Creates Policies/Blueprint based on Input Arguments values
87      *
88      * @param args Input Arguments
89      */
90     @Override
91     public void run(String... args) {
92         if (args.length >= 2 && args[0].equals("app") && args[1].equals("ONAP")) {
93             onapCommonUtils.printInstructions();
94             if (args.length >= 4 && args[2].equals("-type") && args[3].equals("policycreate")) {
95                 Input input = onapCommonUtils.parseInputs(args);
96                 ComponentSpec componentSpec =
97                     componentSpecService.createComponentSpecFromFile(input.getComponentSpecPath());
98                 onapPolicyModelNodeService.createPolicyModels(
99                     componentSpec.getParameters(), input.getOutputPath());
100             } else {
101                 Input input = onapCommonUtils.parseInputs(args);
102                 OnapComponentSpec onapComponentSpec =
103                     onapComponentSpecService
104                         .createComponentSpecFromFile(input.getComponentSpecPath());
105                 if (input.getBpType().equals("o")) {
106                     Blueprint blueprint = onapBlueprintService
107                         .createBlueprint(onapComponentSpec, input);
108                     onapBlueprintService.blueprintToYaml(onapComponentSpec, blueprint, input);
109                     System.out.println(
110                         onapBlueprintService
111                             .blueprintToString(onapComponentSpec, blueprint, input));
112                 } else if (input.getBpType().equals("d")) {
113                     Blueprint blueprint = dmaapBlueprintService
114                         .createBlueprint(onapComponentSpec, input);
115                     dmaapBlueprintService.blueprintToYaml(onapComponentSpec, blueprint, input);
116                     System.out.println(
117                         dmaapBlueprintService
118                             .blueprintToString(onapComponentSpec, blueprint, input));
119                 }
120             }
121         }
122
123         exit(0);
124     }
125 }