Commit for the blueprint generator java tool
[dcaegen2/platform/cli.git] / blueprint-generator / 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> stream_publishes;
43         private TreeMap<String, DmaapObj> stream_subcribes;
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>> createOnapAppconfig(TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs) {
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
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);
77                                 }
78                         }
79                 }
80
81                 //set the stream publishes
82                 TreeMap<String, DmaapObj> streamSubscribes = new TreeMap<String, DmaapObj>();
83
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);
99                                 }
100                         }
101                 }
102
103                 this.setStream_publishes(streamPublishes);
104                 this.setStream_subcribes(streamSubscribes);
105
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);
114
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);
120                                 } else {
121                                         LinkedHashMap<String, Object> inputs = new LinkedHashMap<String, Object>();
122                                         inputs.put("type", "string");
123                                         retInputs.put(pName, inputs);
124                                 }
125                         } else {
126                                 if(p.getType() == "string") {
127                                         String val  =(String) p.getValue();
128                                         val = '"' + val + '"';
129                                         parameters.put(pName, val);
130                                 }
131                                 else {
132                                         parameters.put(pName, p.getValue());
133                                 }
134                                 
135                         }
136                 }
137                 this.setParams(parameters);
138                 return retInputs;
139         }
140
141 //      public void createTemplateAppconfig() {
142 //              //set service calls
143 //              CallsObj[] call = new CallsObj[0];
144 //              this.setService_calls(call);
145 //
146 //              //set the stream publishes
147 //              TreeMap<String, DmaapObj> streamPublishes = new TreeMap<String, DmaapObj>();
148 //              this.setStream_publishes(streamPublishes);
149 //              
150 //              //set the stream subscribes
151 //              TreeMap<String, DmaapObj> streamSubscribes = new TreeMap<String, DmaapObj>();
152 //              this.setStream_subcribes(streamSubscribes);
153 //      }
154 }