1 /**============LICENSE_START=======================================================
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
10 http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.blueprintgenerator.models.policymodel;
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.LinkedHashMap;
26 import java.util.TreeMap;
28 import org.onap.blueprintgenerator.models.blueprint.Node;
29 import org.onap.blueprintgenerator.models.componentspec.EntrySchemaObj;
30 import org.onap.blueprintgenerator.models.componentspec.Parameters;
31 import org.onap.blueprintgenerator.models.componentspec.PolicySchemaObj;
33 import com.fasterxml.jackson.annotation.JsonInclude;
39 @JsonInclude(JsonInclude.Include.NON_NULL)
40 public class PolicyModelNode {
42 private String derived_from;
43 private TreeMap<String, PolicyProperties> properties;
45 public String createNodeType(String policyName, Parameters[] params) {
46 String hasEntrySchema = "";
48 TreeMap<String, PolicyProperties> props = new TreeMap();
49 for(Parameters p: params) {
50 if(p.getPolicy_group() != null) {
51 if(p.getPolicy_group().equals(policyName)) {
52 String name = p.getName();
53 String type = p.getType();
54 PolicyProperties polProps = new PolicyProperties();
55 if(p.getPolicy_schema() != null) {
56 polProps.setType("map");
57 HashMap<String, String> entrySchema = new HashMap();
58 entrySchema.put("type", "onap.datatypes." + name);
59 //ArrayList<String> entrySchema = new ArrayList<String>();
60 //entrySchema.add("type: onap.data." + name);
61 polProps.setEntry_schema(entrySchema);
62 hasEntrySchema = name;
63 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());
108 PolicyProperties prop = new PolicyProperties();
109 prop.setType(pol.getType());
110 properties.put(pol.getName(), prop);
114 node.setProperties(properties);
115 dataType.put("onap.datatypes." + param, node);
119 private TreeMap<String, PolicyModelNode> translateEntrySchema(TreeMap<String, PolicyModelNode> dataType, 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);