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.blueprint;
23 import java.util.LinkedHashMap;
24 import java.util.TreeMap;
26 import org.onap.blueprintgenerator.models.componentspec.CallsObj;
27 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
28 import org.onap.blueprintgenerator.models.componentspec.Parameters;
29 import org.onap.blueprintgenerator.models.componentspec.Publishes;
30 import org.onap.blueprintgenerator.models.componentspec.Subscribes;
32 import com.fasterxml.jackson.annotation.JsonAnyGetter;
40 public class Appconfig {
41 private CallsObj[] service_calls;
42 private TreeMap<String, DmaapObj> streams_publishes;
43 private TreeMap<String, DmaapObj> streams_subscribes;
44 private TreeMap<String, Object> params;
47 public TreeMap<String, Object> getParams(){
51 public TreeMap<String, LinkedHashMap<String, Object>> createAppconfig(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override,
53 TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>();
57 CallsObj[] call = new CallsObj[0];
58 this.setService_calls(call);
60 //set the stream publishes
61 TreeMap<String, DmaapObj> streamPublishes = new TreeMap<String, DmaapObj>();
62 if(cs.getStreams().getPublishes().length != 0) {
63 for(Publishes p: cs.getStreams().getPublishes()) {
64 if(p.getType().equals("data_router") || p.getType().equals("data router")) {
65 //in this case the data router information gets added to the params so for now leave it alone
66 String config = p.getConfig_key();
67 DmaapObj pub = new DmaapObj();
68 String name = p.getConfig_key() +"_feed";
69 retInputs = pub.createOnapDmaapDRObj(retInputs, config, 'p', name, name, isDmaap);
70 pub.setType(p.getType());
71 streamPublishes.put(config, pub);
72 } else if(p.getType().equals("message_router") || p.getType().equals("message router")) {
73 String config = p.getConfig_key();
74 DmaapObj pub = new DmaapObj();
75 String name = p.getConfig_key() + "_topic";
76 retInputs = pub.createOnapDmaapMRObj(retInputs, config, 'p', name, name, isDmaap);
77 pub.setType(p.getType());
78 streamPublishes.put(config, pub);
83 //set the stream publishes
84 TreeMap<String, DmaapObj> streamSubscribes = new TreeMap<String, DmaapObj>();
86 if(cs.getStreams().getSubscribes().length != 0) {
87 for(Subscribes s: cs.getStreams().getSubscribes()) {
88 if(s.getType().equals("data_router") || s.getType().equals("data router")) {
89 //in this case the data router information gets added to the params so for now leave it alone
90 String config = s.getConfig_key();
91 DmaapObj sub = new DmaapObj();
92 String name = s.getConfig_key() + "_feed";
93 retInputs = sub.createOnapDmaapDRObj(retInputs, config, 'p', name, name, isDmaap);
94 sub.setType(s.getType());
95 streamSubscribes.put(config, sub);
96 } else if(s.getType().equals("message_router") || s.getType().equals("message router")) {
97 String config = s.getConfig_key();
98 DmaapObj sub = new DmaapObj();
99 String name = s.getConfig_key() + "_topic";
100 retInputs = sub.createOnapDmaapMRObj(retInputs, config, 's', name, name, isDmaap);
101 sub.setType(s.getType());
102 streamSubscribes.put(config, sub);
107 this.setStreams_publishes(streamPublishes);
108 this.setStreams_subscribes(streamSubscribes);
110 //set the parameters into the appconfig
111 TreeMap<String, Object> parameters = new TreeMap<String, Object>();
112 for(Parameters p: cs.getParameters()) {
113 String pName = p.getName();
114 if(p.isSourced_at_deployment()) {
115 GetInput paramInput = new GetInput();
116 paramInput.setGet_input(pName);
117 parameters.put(pName, paramInput);
119 if(!p.getValue().equals("")) {
120 LinkedHashMap<String, Object> inputs = new LinkedHashMap<String, Object>();
121 inputs.put("type", "string");
122 inputs.put("default", p.getValue());
123 retInputs.put(pName, inputs);
125 LinkedHashMap<String, Object> inputs = new LinkedHashMap<String, Object>();
126 inputs.put("type", "string");
127 retInputs.put(pName, inputs);
130 if(p.getType() == "string") {
131 String val =(String) p.getValue();
132 val = '"' + val + '"';
133 parameters.put(pName, val);
136 parameters.put(pName, p.getValue());
140 if(override != null) {
141 GetInput ov = new GetInput();
142 ov.setGet_input("service_component_name_override");
143 parameters.put("service_component_name_override", ov);
144 LinkedHashMap<String, Object> over = new LinkedHashMap<String, Object>();
145 over.put("type", "string");
146 over.put("default", override);
147 retInputs.put("service_component_name_override", over);
149 this.setParams(parameters);