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> stream_publishes;
43 private TreeMap<String, DmaapObj> stream_subcribes;
44 private TreeMap<String, Object> params;
47 public TreeMap<String, Object> getParams(){
51 public TreeMap<String, LinkedHashMap<String, Object>> createOnapAppconfig(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs) {
52 TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>();
56 CallsObj[] call = new CallsObj[0];
57 this.setService_calls(call);
59 //set the stream publishes
60 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 retInputs = pub.createOnapDmaapDRObj(retInputs, config, 'p');
69 pub.setType(p.getType());
70 streamPublishes.put(config, pub);
71 } else if(p.getType().equals("message_router") || p.getType().equals("message router")) {
72 String config = p.getConfig_key();
73 DmaapObj pub = new DmaapObj();
74 retInputs = pub.createOnapDmaapMRObj(retInputs, config, 'p');
75 pub.setType(p.getType());
76 streamPublishes.put(config, pub);
81 //set the stream publishes
82 TreeMap<String, DmaapObj> streamSubscribes = new TreeMap<String, DmaapObj>();
84 if(cs.getStreams().getSubscribes().length != 0) {
85 for(Subscribes s: cs.getStreams().getSubscribes()) {
86 if(s.getType().equals("data_router") || s.getType().equals("data router")) {
87 //in this case the data router information gets added to the params so for now leave it alone
88 String config = s.getConfig_key();
89 DmaapObj sub = new DmaapObj();
90 retInputs = sub.createOnapDmaapDRObj(retInputs, config, 'p');
91 sub.setType(s.getType());
92 streamSubscribes.put(config, sub);
93 } else if(s.getType().equals("message_router") || s.getType().equals("message router")) {
94 String config = s.getConfig_key();
95 DmaapObj sub = new DmaapObj();
96 retInputs = sub.createOnapDmaapMRObj(retInputs, config, 's');
97 sub.setType(s.getType());
98 streamSubscribes.put(config, sub);
103 this.setStream_publishes(streamPublishes);
104 this.setStream_subcribes(streamSubscribes);
106 //set the parameters into the appconfig
107 TreeMap<String, Object> parameters = new TreeMap<String, Object>();
108 for(Parameters p: cs.getParameters()) {
109 String pName = p.getName();
110 if(p.isSourced_at_deployment()) {
111 GetInput paramInput = new GetInput();
112 paramInput.setGet_input(pName);
113 parameters.put(pName, paramInput);
115 if(!p.getValue().equals("")) {
116 LinkedHashMap<String, Object> inputs = new LinkedHashMap<String, Object>();
117 inputs.put("type", "string");
118 inputs.put("default", p.getValue());
119 retInputs.put(pName, inputs);
121 LinkedHashMap<String, Object> inputs = new LinkedHashMap<String, Object>();
122 inputs.put("type", "string");
123 retInputs.put(pName, inputs);
126 if(p.getType() == "string") {
127 String val =(String) p.getValue();
128 val = '"' + val + '"';
129 parameters.put(pName, val);
132 parameters.put(pName, p.getValue());
137 this.setParams(parameters);
141 // public void createTemplateAppconfig() {
142 // //set service calls
143 // CallsObj[] call = new CallsObj[0];
144 // this.setService_calls(call);
146 // //set the stream publishes
147 // TreeMap<String, DmaapObj> streamPublishes = new TreeMap<String, DmaapObj>();
148 // this.setStream_publishes(streamPublishes);
150 // //set the stream subscribes
151 // TreeMap<String, DmaapObj> streamSubscribes = new TreeMap<String, DmaapObj>();
152 // this.setStream_subcribes(streamSubscribes);