Merge "Add factories for Ext tls parameters"
[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  Copyright (c) 2020 Nokia. All rights reserved.
6  ================================================================================
7  Licensed under the Apache License, Version 2.0 (the "License"); 
8  you may not use this file except in compliance with the License. 
9  You may obtain a copy of the License at 
10
11       http://www.apache.org/licenses/LICENSE-2.0 
12
13  Unless required by applicable law or agreed to in writing, software 
14  distributed under the License is distributed on an "AS IS" BASIS, 
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
16  See the License for the specific language governing permissions and 
17  limitations under the License. 
18  ============LICENSE_END========================================================= 
19
20  */
21
22 package org.onap.blueprintgenerator.models.blueprint;
23
24 import java.util.LinkedHashMap;
25 import java.util.TreeMap;
26
27 import org.onap.blueprintgenerator.models.blueprint.dmaap.DmaapObj;
28 import org.onap.blueprintgenerator.models.componentspec.CallsObj;
29 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
30 import org.onap.blueprintgenerator.models.componentspec.Parameters;
31 import org.onap.blueprintgenerator.models.componentspec.Publishes;
32 import org.onap.blueprintgenerator.models.componentspec.Subscribes;
33
34 import com.fasterxml.jackson.annotation.JsonAnyGetter;
35
36
37 import lombok.Getter;
38 import lombok.Setter;
39
40 @Getter
41 @Setter
42 public class Appconfig {
43         private CallsObj[] service_calls;
44         private TreeMap<String, DmaapObj> streams_publishes;
45         private TreeMap<String, DmaapObj> streams_subscribes;
46         private TreeMap<String, Object> params;
47
48         @JsonAnyGetter
49         public TreeMap<String, Object> getParams(){
50                 return params;
51         }
52
53         public TreeMap<String, LinkedHashMap<String, Object>> createAppconfig(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String override,
54                                                                                                                                                   boolean isDmaap) {
55                 TreeMap<String, LinkedHashMap<String, Object>> retInputs = new TreeMap<String, LinkedHashMap<String, Object>>();
56                 retInputs = inps;
57
58                 //set service calls
59                 CallsObj[] call = new CallsObj[0];
60                 this.setService_calls(call);
61
62                 //set the stream publishes
63                 TreeMap<String, DmaapObj> streamPublishes = new TreeMap<String, DmaapObj>();
64                 if(cs.getStreams().getPublishes().length != 0) {
65                         for(Publishes p: cs.getStreams().getPublishes()) {
66                                 if(p.getType().equals("data_router") || p.getType().equals("data router")) {
67                                         //in this case the data router information gets added to the params so for now leave it alone
68                                         String config = p.getConfig_key();
69                                         DmaapObj pub = new DmaapObj();
70                                         String name = p.getConfig_key() +"_feed";
71                                         retInputs = pub.createOnapDmaapDRObj(retInputs, config, 'p', name, name, isDmaap);
72                                         pub.setType(p.getType());
73                                         streamPublishes.put(config, pub);
74                                 } else if(p.getType().equals("message_router") || p.getType().equals("message router")) {
75                                         String config = p.getConfig_key();
76                                         DmaapObj pub = new DmaapObj();
77                                         String name =  p.getConfig_key() + "_topic";
78                                         retInputs = pub.createOnapDmaapMRObj(retInputs, config, 'p', name, name, isDmaap);
79                                         pub.setType(p.getType());
80                                         streamPublishes.put(config, pub);
81                                 }
82                         }
83                 }
84
85                 //set the stream publishes
86                 TreeMap<String, DmaapObj> streamSubscribes = new TreeMap<String, DmaapObj>();
87
88                 if(cs.getStreams().getSubscribes().length != 0) {
89                         for(Subscribes s: cs.getStreams().getSubscribes()) {
90                                 if(s.getType().equals("data_router") || s.getType().equals("data router")) {
91                                         //in this case the data router information gets added to the params so for now leave it alone
92                                         String config = s.getConfig_key();
93                                         DmaapObj sub = new DmaapObj();
94                                         String name = s.getConfig_key() + "_feed";
95                                         retInputs = sub.createOnapDmaapDRObj(retInputs, config, 'p', name, name, isDmaap);
96                                         sub.setType(s.getType());
97                                         streamSubscribes.put(config, sub);
98                                 } else if(s.getType().equals("message_router") || s.getType().equals("message router")) {
99                                         String config = s.getConfig_key();
100                                         DmaapObj sub = new DmaapObj();
101                                         String name = s.getConfig_key() + "_topic";
102                                         retInputs = sub.createOnapDmaapMRObj(retInputs, config, 's', name, name, isDmaap);
103                                         sub.setType(s.getType());
104                                         streamSubscribes.put(config, sub);
105                                 }
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.setBpInputName(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.setBpInputName("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 }