1 /*============LICENSE_START=======================================================
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
11 http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.blueprintgenerator.models.blueprint;
24 import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.isDataRouterType;
25 import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.isMessageRouterType;
26 import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.createStringInput;
28 import com.fasterxml.jackson.annotation.JsonAnyGetter;
29 import java.util.LinkedHashMap;
30 import java.util.TreeMap;
33 import org.onap.blueprintgenerator.models.blueprint.dmaap.DmaapObj;
34 import org.onap.blueprintgenerator.models.componentspec.CallsObj;
35 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
36 import org.onap.blueprintgenerator.models.componentspec.Parameters;
37 import org.onap.blueprintgenerator.models.componentspec.Publishes;
38 import org.onap.blueprintgenerator.models.componentspec.Subscribes;
42 public class Appconfig {
44 private CallsObj[] service_calls;
45 private TreeMap<String, DmaapObj> streams_publishes;
46 private TreeMap<String, DmaapObj> streams_subscribes;
47 private TreeMap<String, Object> params;
50 public TreeMap<String, Object> getParams() {
54 public TreeMap<String, LinkedHashMap<String, Object>> createAppconfig(
55 TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec componentSpec, String override,
58 service_calls = new CallsObj[0];
59 streams_publishes = createStreamPublishes(componentSpec, inps, isDmaap);
60 streams_subscribes = createStreamSubscribes(componentSpec, inps, isDmaap);
61 params = createParameters(componentSpec, inps, override);
66 private TreeMap<String, DmaapObj> createStreamPublishes(ComponentSpec componentSpec,
67 TreeMap<String, LinkedHashMap<String, Object>> inps, boolean isDmaap) {
68 TreeMap<String, DmaapObj> streamPublishes = new TreeMap<>();
69 for (Publishes publishes : componentSpec.getStreams().getPublishes()) {
70 String config = publishes.getConfig_key();
71 DmaapObj pub = new DmaapObj();
72 if (isDataRouterType(publishes.getType())) {
73 //in this case the data router information gets added to the params so for now leave it alone
74 String name = publishes.getConfig_key() + "_feed";
75 pub.createOnapDmaapDRObj(inps, config, 'p', name, name, isDmaap);
76 } else if (isMessageRouterType(publishes.getType())) {
77 String name = publishes.getConfig_key() + "_topic";
78 pub.createOnapDmaapMRObj(inps, config, 'p', name, name, isDmaap);
80 pub.setType(publishes.getType());
81 streamPublishes.put(config, pub);
83 return streamPublishes;
86 private TreeMap<String, DmaapObj> createStreamSubscribes(ComponentSpec componentSpec,
87 TreeMap<String, LinkedHashMap<String, Object>> inputs, boolean isDmaap) {
88 TreeMap<String, DmaapObj> streamSubscribes = new TreeMap<>();
89 for (Subscribes subscribes : componentSpec.getStreams().getSubscribes()) {
90 String config = subscribes.getConfig_key();
91 DmaapObj sub = new DmaapObj();
92 if (isDataRouterType(subscribes.getType())) {
93 //in this case the data router information gets added to the params so for now leave it alone
94 String name = subscribes.getConfig_key() + "_feed";
95 sub.createOnapDmaapDRObj(inputs, config, 'p', name, name, isDmaap);
96 } else if (isMessageRouterType(subscribes.getType())) {
97 String name = subscribes.getConfig_key() + "_topic";
98 sub.createOnapDmaapMRObj(inputs, config, 's', name, name, isDmaap);
100 sub.setType(subscribes.getType());
101 streamSubscribes.put(config, sub);
103 return streamSubscribes;
106 private TreeMap<String, Object> createParameters(ComponentSpec componentSpec,
107 TreeMap<String, LinkedHashMap<String, Object>> inputs,
109 TreeMap<String, Object> parameters = new TreeMap<>();
110 for (Parameters params : componentSpec.getParameters()) {
111 String pName = params.getName();
112 if (params.isSourced_at_deployment()) {
113 GetInput paramInput = new GetInput();
114 paramInput.setBpInputName(pName);
115 parameters.put(pName, paramInput);
117 if (!params.getValue().equals("")) {
118 LinkedHashMap<String, Object> input = createStringInput(params.getValue());
119 inputs.put(pName, input);
121 LinkedHashMap<String, Object> input = new LinkedHashMap<>();
122 input.put("type", "string");
123 inputs.put(pName, input);
126 if ("string".equals(params.getType())) {
127 String val = (String) params.getValue();
128 val = '"' + val + '"';
129 parameters.put(pName, val);
131 parameters.put(pName, params.getValue());
135 handleOverride(override, parameters, inputs);
139 private void handleOverride(String override, TreeMap<String, Object> parameters,
140 TreeMap<String, LinkedHashMap<String, Object>> inps) {
141 if (override != null) {
142 GetInput ov = new GetInput();
143 ov.setBpInputName("service_component_name_override");
144 parameters.put("service_component_name_override", ov);
145 LinkedHashMap<String, Object> over = new LinkedHashMap<>();
146 over.put("type", "string");
147 over.put("default", override);
148 inps.put("service_component_name_override", over);