3 * * ============LICENSE_START=======================================================
5 * * ================================================================================
6 * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
7 * * ================================================================================
8 * * Modifications Copyright (c) 2021 Nokia
9 * * ================================================================================
10 * * Licensed under the Apache License, Version 2.0 (the "License");
11 * * you may not use this file except in compliance with the License.
12 * * You may obtain a copy of the License at
14 * * http://www.apache.org/licenses/LICENSE-2.0
16 * * Unless required by applicable law or agreed to in writing, software
17 * * distributed under the License is distributed on an "AS IS" BASIS,
18 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * * See the License for the specific language governing permissions and
20 * * limitations under the License.
21 * * ============LICENSE_END=========================================================
26 package org.onap.blueprintgenerator.service.common;
28 import org.onap.blueprintgenerator.constants.Constants;
29 import org.onap.blueprintgenerator.model.common.Appconfig;
30 import org.onap.blueprintgenerator.model.common.BaseStream;
31 import org.onap.blueprintgenerator.model.common.GetInput;
32 import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
33 import org.onap.blueprintgenerator.model.componentspec.common.Calls;
34 import org.onap.blueprintgenerator.model.componentspec.common.Parameters;
35 import org.onap.blueprintgenerator.service.base.BlueprintHelperService;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.stereotype.Service;
39 import java.util.HashMap;
40 import java.util.LinkedHashMap;
42 import java.util.TreeMap;
45 * @author : Ravi Mantena
46 * @date 10/16/2020 Application: ONAP - Blueprint Generator Common ONAP Service used to create App
49 @Service("onapAppConfigService")
50 public class AppConfigService {
53 private DmaapService dmaapService;
56 private BlueprintHelperService blueprintHelperService;
59 private StreamService streamService;
63 * Creates Inputs section under App Config with Publishes, Subscribes, Parameters sections by
64 * checking Datarouter/MessageRouter/override/Dmaap values
66 * @param inputs Inputs
67 * @param onapComponentSpec Onap Component Specification
68 * @param override Parameter to Service Component Override
69 * @param isDmaap Dmaap Argument
72 public Map<String, Object> createAppconfig(
73 Map<String, LinkedHashMap<String, Object>> inputs,
74 OnapComponentSpec onapComponentSpec,
78 Map<String, Object> response = new HashMap<>();
79 Appconfig appconfig = new Appconfig();
81 Calls[] call = new Calls[0];
82 appconfig.setService_calls(call);
84 Map<String, BaseStream> streamPublishes = streamService.createStreamPublishes(
85 onapComponentSpec, blueprintHelperService, dmaapService, inputs, isDmaap);
86 Map<String, BaseStream> streamSubscribes = streamService.createStreamSubscribes(
87 onapComponentSpec, blueprintHelperService, dmaapService, inputs, isDmaap);
89 appconfig.setStreams_publishes(streamPublishes);
90 appconfig.setStreams_subscribes(streamSubscribes);
92 Map<String, Object> parameters = new TreeMap<>();
93 for (Parameters p : onapComponentSpec.getParameters()) {
94 String pName = p.getName();
95 if (p.isSourced_at_deployment()) {
96 GetInput paramInput = new GetInput();
97 paramInput.setBpInputName(pName);
98 parameters.put(pName, paramInput);
99 if (!"".equals(p.getValue())) {
100 LinkedHashMap<String, Object> pInputs =
101 blueprintHelperService.createStringInput(p.getValue());
102 inputs.put(pName, pInputs);
104 LinkedHashMap<String, Object> pInputs = new LinkedHashMap<>();
105 pInputs.put("type", "string");
106 inputs.put(pName, pInputs);
109 if ("string".equals(p.getType())) {
110 String val = (String) p.getValue();
111 val = '"' + val + '"';
112 parameters.put(pName, val);
114 parameters.put(pName, p.getValue());
115 // Updated code to resolve the issue of missing \ for collector.schema.file
116 // parameters.put(pName, pName.equals("collector.schema.file") ?
117 // ((String)p.getValue()).replace("\"", "\\\"") : p.getValue());
121 if (override != null) {
122 GetInput ov = new GetInput();
123 ov.setBpInputName(Constants.SERVICE_COMPONENT_NAME_OVERRIDE);
124 parameters.put(Constants.SERVICE_COMPONENT_NAME_OVERRIDE, ov);
125 LinkedHashMap<String, Object> over = blueprintHelperService.createStringInput(override);
126 inputs.put(Constants.SERVICE_COMPONENT_NAME_OVERRIDE, over);
128 appconfig.setParams(parameters);
130 response.put("appconfig", appconfig);
131 response.put("inputs", inputs);