1 /*============LICENSE_START=======================================================
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
12 http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.blueprintgenerator.models.policymodel;
25 import static org.onap.blueprintgenerator.models.blueprint.BpConstants.TOSCA_DATATYPES_ROOT;
26 import static org.onap.blueprintgenerator.models.blueprint.BpConstants.TOSCA_NODES_ROOT;
28 import com.fasterxml.jackson.annotation.JsonInclude;
29 import java.util.ArrayList;
30 import java.util.HashMap;
31 import java.util.TreeMap;
34 import org.onap.blueprintgenerator.models.componentspec.EntrySchemaObj;
35 import org.onap.blueprintgenerator.models.componentspec.Parameters;
36 import org.onap.blueprintgenerator.models.componentspec.PolicySchemaObj;
40 @JsonInclude(JsonInclude.Include.NON_NULL)
41 public class PolicyModelNode {
43 private String derived_from;
44 private TreeMap<String, PolicyProperties> properties;
46 public String createNodeType(String policyName, Parameters[] params) {
47 String hasEntrySchema = "";
49 TreeMap<String, PolicyProperties> props = new TreeMap();
50 for (Parameters p : params) {
51 if (p.getPolicy_group() != null) {
52 if (p.getPolicy_group().equals(policyName)) {
53 String name = p.getName();
54 String type = p.getType();
55 PolicyProperties polProps = new PolicyProperties();
56 if (p.getPolicy_schema() != null) {
57 polProps.setType("map");
58 HashMap<String, String> entrySchema = new HashMap();
59 entrySchema.put("type", "onap.datatypes." + name);
60 //ArrayList<String> entrySchema = new ArrayList<String>();
61 //entrySchema.add("type: onap.data." + name);
62 polProps.setEntry_schema(entrySchema);
63 hasEntrySchema = name;
64 props.put(name, polProps);
66 polProps.setType(type);
67 props.put(name, polProps);
73 this.setDerived_from(TOSCA_DATATYPES_ROOT);
74 this.setProperties(props);
75 return hasEntrySchema;
78 public TreeMap<String, PolicyModelNode> createDataTypes(String param, Parameters[] parameters) {
79 TreeMap<String, PolicyModelNode> dataType = new TreeMap<String, PolicyModelNode>();
81 PolicyModelNode node = new PolicyModelNode();
82 node.setDerived_from(TOSCA_DATATYPES_ROOT);
84 TreeMap<String, PolicyProperties> properties = new TreeMap();
86 Parameters par = new Parameters();
87 for (Parameters p : parameters) {
88 if (p.getName().equals(param)) {
94 for (PolicySchemaObj pol : par.getPolicy_schema()) {
95 if (pol.getEntry_schema() != null) {
96 PolicyProperties prop = new PolicyProperties();
98 HashMap<String, String> schema = new HashMap();
99 schema.put("type", "onap.datatypes." + pol.getName());
100 // prop.setType("list");
101 // ArrayList<String> schema = new ArrayList();
102 // schema.add("type: onap.data." + pol.getName());
103 prop.setEntry_schema(schema);
104 properties.put(pol.getName(), prop);
105 dataType = translateEntrySchema(dataType, pol.getEntry_schema(), pol.getName());
107 PolicyProperties prop = new PolicyProperties();
108 prop.setType(pol.getType());
109 properties.put(pol.getName(), prop);
113 node.setProperties(properties);
114 dataType.put("onap.datatypes." + param, node);
118 private TreeMap<String, PolicyModelNode> translateEntrySchema(TreeMap<String, PolicyModelNode> dataType,
119 EntrySchemaObj[] entry, String name) {
120 TreeMap<String, PolicyModelNode> data = dataType;
121 PolicyModelNode node = new PolicyModelNode();
122 node.setDerived_from(TOSCA_NODES_ROOT);
123 TreeMap<String, PolicyProperties> properties = new TreeMap<String, PolicyProperties>();
125 for (EntrySchemaObj e : entry) {
126 if (e.getEntry_schema() != null) {
127 PolicyProperties prop = new PolicyProperties();
128 prop.setType("list");
129 ArrayList<String> schema = new ArrayList<String>();
130 schema.add("type: onap.datatypes." + e.getName());
131 prop.setEntry_schema(schema);
132 properties.put(e.getName(), prop);
133 data = translateEntrySchema(data, e.getEntry_schema(), e.getName());
134 node.setProperties(properties);
136 PolicyProperties prop = new PolicyProperties();
137 prop.setType(e.getType());
138 properties.put(e.getName(), prop);
139 node.setProperties(properties);
143 dataType.put("onap.datatypes." + name, node);