bp-gen code clone from cli repo
[dcaegen2/platform.git] / mod / bpgenerator / src / main / java / org / onap / blueprintgenerator / models / blueprint / Appconfig.java
1 /**============LICENSE_START======================================================= 
2  org.onap.dcae 
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 
9
10       http://www.apache.org/licenses/LICENSE-2.0 
11
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========================================================= 
18
19  */
20
21 package org.onap.blueprintgenerator.models.blueprint;
22
23 import java.util.LinkedHashMap;
24 import java.util.TreeMap;
25
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;
31
32 import com.fasterxml.jackson.annotation.JsonAnyGetter;
33
34
35 import lombok.Getter;
36 import lombok.Setter;
37
38 @Getter
39 @Setter
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;
45
46         @JsonAnyGetter
47         public TreeMap<String, Object> getParams(){
48                 return params;
49         }
50
51         public TreeMap<String, LinkedHashMap<String, Object>> createAppconfig(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override) {
52                 TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>();
53                 retInputs = inps;
54
55                 //set service calls
56                 CallsObj[] call = new CallsObj[0];
57                 this.setService_calls(call);
58
59                 //set the stream publishes
60                 TreeMap<String, DmaapObj> streamPublishes = new TreeMap<String, DmaapObj>();
61                 int counter = 0;
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 = "feed" + counter;
69                                         retInputs = pub.createOnapDmaapDRObj(retInputs, config, 'p', "feed" + counter, name);
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 = "topic" + counter;
76                                         retInputs = pub.createOnapDmaapMRObj(retInputs, config, 'p', "topic" + counter, name);
77                                         pub.setType(p.getType());
78                                         streamPublishes.put(config, pub);
79                                 }
80                                 counter++;
81                         }
82                 }
83
84                 //set the stream publishes
85                 TreeMap<String, DmaapObj> streamSubscribes = new TreeMap<String, DmaapObj>();
86
87                 if(cs.getStreams().getSubscribes().length != 0) {
88                         for(Subscribes s: cs.getStreams().getSubscribes()) {
89                                 if(s.getType().equals("data_router") || s.getType().equals("data router")) {
90                                         //in this case the data router information gets added to the params so for now leave it alone
91                                         String config = s.getConfig_key();
92                                         DmaapObj sub = new DmaapObj();
93                                         String name = "feed" + counter;
94                                         retInputs = sub.createOnapDmaapDRObj(retInputs, config, 'p', "feed" + counter, name);
95                                         sub.setType(s.getType());
96                                         streamSubscribes.put(config, sub);
97                                 } else if(s.getType().equals("message_router") || s.getType().equals("message router")) {
98                                         String config = s.getConfig_key();
99                                         DmaapObj sub = new DmaapObj();
100                                         String name = "topic" + counter;
101                                         retInputs = sub.createOnapDmaapMRObj(retInputs, config, 's', "topic" + counter, name);
102                                         sub.setType(s.getType());
103                                         streamSubscribes.put(config, sub);
104                                 }
105                                 counter++;
106                         }
107                 }
108
109                 this.setStreams_publishes(streamPublishes);
110                 this.setStreams_subscribes(streamSubscribes);
111
112                 //set the parameters into the appconfig
113                 TreeMap<String, Object> parameters = new TreeMap<String, Object>();
114                 for(Parameters p: cs.getParameters()) {
115                         String pName = p.getName();
116                         if(p.isSourced_at_deployment()) {
117                                 GetInput paramInput = new GetInput();
118                                 paramInput.setGet_input(pName);
119                                 parameters.put(pName, paramInput);
120
121                                 if(!p.getValue().equals("")) {
122                                         LinkedHashMap<String, Object> inputs = new LinkedHashMap<String, Object>();
123                                         inputs.put("type", "string");
124                                         inputs.put("default", p.getValue());
125                                         retInputs.put(pName, inputs);
126                                 } else {
127                                         LinkedHashMap<String, Object> inputs = new LinkedHashMap<String, Object>();
128                                         inputs.put("type", "string");
129                                         retInputs.put(pName, inputs);
130                                 }
131                         } else {
132                                 if(p.getType() == "string") {
133                                         String val  =(String) p.getValue();
134                                         val = '"' + val + '"';
135                                         parameters.put(pName, val);
136                                 }
137                                 else {
138                                         parameters.put(pName, p.getValue());
139                                 }
140                         }
141                 }
142                 if(override != null) {
143                         GetInput ov = new GetInput();
144                         ov.setGet_input("service_component_name_override");
145                         parameters.put("service_component_name_override", ov);
146                         LinkedHashMap<String, Object> over = new LinkedHashMap<String, Object>();
147                         over.put("type", "string");
148                         over.put("default", override);
149                         retInputs.put("service_component_name_override", over);
150                 }
151                 this.setParams(parameters);
152                 return retInputs;
153         }
154
155
156 }