3 * * ============LICENSE_START=======================================================
5 * * ================================================================================
6 * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
7 * * Copyright (c) 2021 Nokia. All rights reserved.
8 * * ================================================================================
9 * * Modifications Copyright (c) 2021 Nokia
10 * * ================================================================================
11 * * Licensed under the Apache License, Version 2.0 (the "License");
12 * * you may not use this file except in compliance with the License.
13 * * You may obtain a copy of the License at
15 * * http://www.apache.org/licenses/LICENSE-2.0
17 * * Unless required by applicable law or agreed to in writing, software
18 * * distributed under the License is distributed on an "AS IS" BASIS,
19 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * * See the License for the specific language governing permissions and
21 * * limitations under the License.
22 * * ============LICENSE_END=========================================================
27 package org.onap.blueprintgenerator.service.common;
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 isDmaap Dmaap Argument
71 public Map<String, Object> createAppconfig(
72 Map<String, LinkedHashMap<String, Object>> inputs,
73 OnapComponentSpec onapComponentSpec,
76 Map<String, Object> response = new HashMap<>();
77 Appconfig appconfig = new Appconfig();
79 Calls[] call = new Calls[0];
80 appconfig.setService_calls(call);
82 Map<String, BaseStream> streamPublishes = streamService.createStreamPublishes(
83 onapComponentSpec, blueprintHelperService, dmaapService, inputs, isDmaap);
84 Map<String, BaseStream> streamSubscribes = streamService.createStreamSubscribes(
85 onapComponentSpec, blueprintHelperService, dmaapService, inputs, isDmaap);
87 appconfig.setStreams_publishes(streamPublishes);
88 appconfig.setStreams_subscribes(streamSubscribes);
90 Map<String, Object> parameters = new TreeMap<>();
91 for (Parameters p : onapComponentSpec.getParameters()) {
92 String pName = p.getName();
93 if (p.isSourced_at_deployment()) {
94 GetInput paramInput = new GetInput();
95 paramInput.setBpInputName(pName);
96 parameters.put(pName, paramInput);
97 if (!"".equals(p.getValue())) {
98 LinkedHashMap<String, Object> pInputs =
99 blueprintHelperService.createStringInput(p.getValue());
100 inputs.put(pName, pInputs);
102 LinkedHashMap<String, Object> pInputs = new LinkedHashMap<>();
103 pInputs.put("type", "string");
104 inputs.put(pName, pInputs);
107 if ("string".equals(p.getType())) {
108 String val = (String) p.getValue();
109 val = '"' + val + '"';
110 parameters.put(pName, val);
112 parameters.put(pName, p.getValue());
113 // Updated code to resolve the issue of missing \ for collector.schema.file
114 // parameters.put(pName, pName.equals("collector.schema.file") ?
115 // ((String)p.getValue()).replace("\"", "\\\"") : p.getValue());
120 appconfig.setParams(parameters);
122 response.put("appconfig", appconfig);
123 response.put("inputs", inputs);