Adjust BP-gen to correctly support DFC component spec - types
[dcaegen2/platform.git] / mod / bpgenerator / src / main / java / org / onap / blueprintgenerator / models / onapbp / OnapBlueprint.java
1 /*============LICENSE_START=======================================================
2  org.onap.dcae 
3  ================================================================================ 
4  Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. 
5  ================================================================================
6  Modifications Copyright (c) 2020 Nokia. 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 package org.onap.blueprintgenerator.models.onapbp;
24
25 import static org.onap.blueprintgenerator.models.blueprint.BpConstants.CLOUDIFY_DSL_1_3;
26
27 import com.fasterxml.jackson.annotation.JsonInclude;
28 import com.fasterxml.jackson.annotation.JsonInclude.Include;
29 import java.util.LinkedHashMap;
30 import java.util.TreeMap;
31 import lombok.Getter;
32 import lombok.Setter;
33 import org.onap.blueprintgenerator.core.PgaasNodeBuilder;
34 import org.onap.blueprintgenerator.core.PolicyNodeBuilder;
35 import org.onap.blueprintgenerator.models.blueprint.Blueprint;
36 import org.onap.blueprintgenerator.models.blueprint.Imports;
37 import org.onap.blueprintgenerator.models.blueprint.Node;
38 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
39
40
41 @Getter
42 @Setter
43 @JsonInclude(value = Include.NON_NULL)
44
45 public class OnapBlueprint extends Blueprint {
46
47     public Blueprint createOnapBlueprint(ComponentSpec cs, String importPath, String override) {
48
49         //create the inputs that will be used
50         TreeMap<String, LinkedHashMap<String, Object>> inputs = new TreeMap<String, LinkedHashMap<String, Object>>();
51         //set the tosca definition which is the same for everything
52         this.setTosca_definitions_version(CLOUDIFY_DSL_1_3);
53
54         //set the imports
55         if (!"".equals(importPath)) {
56             Imports imps = new Imports();
57             this.setImports(imps.createImportsFromFile(importPath));
58         } else {
59             Imports imps = new Imports();
60             this.setImports(imps.createOnapImports());
61         }
62
63         //create the node template
64         TreeMap<String, Node> nodeTemplate = new TreeMap<String, Node>();
65         String nodeName = cs.getSelf().getName();
66
67         //create the onap node that will be used
68         OnapNode node = new OnapNode();
69         inputs = node.createOnapNode(inputs, cs, override);
70         nodeTemplate.put(nodeName, node);
71         this.setNode_templates(nodeTemplate);
72
73         //if present in component spec, populate policyNode information in the blueprint
74         if (cs.getPolicyInfo() != null) {
75             PolicyNodeBuilder.addPolicyNodesAndInputs(cs, nodeTemplate, inputs);
76         }
77
78         //if present in component spec, populate pgaasNodes information in the blueprint
79         if (cs.getAuxilary().getDatabases() != null) {
80             PgaasNodeBuilder.addPgaasNodesAndInputs(cs, nodeTemplate, inputs);
81         }
82
83         //set the inputs
84         this.setInputs(inputs);
85
86         Blueprint bp = new Blueprint();
87         bp.setImports(this.getImports());
88         bp.setInputs(this.getInputs());
89         bp.setNode_templates(this.getNode_templates());
90         bp.setTosca_definitions_version(this.getTosca_definitions_version());
91
92         return bp;
93
94     }
95 }