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.Dmaap;
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.model.componentspec.common.Publishes;
36 import org.onap.blueprintgenerator.model.componentspec.common.Subscribes;
37 import org.onap.blueprintgenerator.service.base.BlueprintHelperService;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.stereotype.Service;
41 import java.util.HashMap;
42 import java.util.LinkedHashMap;
44 import java.util.TreeMap;
47 * @author : Ravi Mantena
48 * @date 10/16/2020 Application: ONAP - Blueprint Generator Common ONAP Service used to create App
51 @Service("onapAppConfigService")
52 public class AppConfigService {
55 private DmaapService dmaapService;
58 private BlueprintHelperService blueprintHelperService;
61 private StreamService streamService;
64 * Creates Inputs section under App Config with Publishes, Subscribes, Parameters sections by
65 * checking Datarouter/MessageRouter/override/Dmaap values
67 * @param inputs Inputs
68 * @param onapComponentSpec Onap Component Specification
69 * @param override Parameter to Service Component Override
70 * @param isDmaap Dmaap Argument
73 public Map<String, Object> createAppconfig(
74 Map<String, LinkedHashMap<String, Object>> inputs,
75 OnapComponentSpec onapComponentSpec,
79 Map<String, Object> response = new HashMap<>();
80 Appconfig appconfig = new Appconfig();
82 Calls[] call = new Calls[0];
83 appconfig.setService_calls(call);
85 Map<String, Dmaap> streamPublishes = streamService.createStreamPublishes(
86 onapComponentSpec, blueprintHelperService, dmaapService, inputs, isDmaap);
87 Map<String, Dmaap> streamSubscribes = streamService.createStreamSubscribes(
88 onapComponentSpec, blueprintHelperService, dmaapService, inputs, isDmaap);
90 appconfig.setStreams_publishes(streamPublishes);
91 appconfig.setStreams_subscribes(streamSubscribes);
93 Map<String, Object> parameters = new TreeMap<>();
94 for (Parameters p : onapComponentSpec.getParameters()) {
95 String pName = p.getName();
96 if (p.isSourced_at_deployment()) {
97 GetInput paramInput = new GetInput();
98 paramInput.setBpInputName(pName);
99 parameters.put(pName, paramInput);
100 if (!"".equals(p.getValue())) {
101 LinkedHashMap<String, Object> pInputs =
102 blueprintHelperService.createStringInput(p.getValue());
103 inputs.put(pName, pInputs);
105 LinkedHashMap<String, Object> pInputs = new LinkedHashMap<>();
106 pInputs.put("type", "string");
107 inputs.put(pName, pInputs);
110 if ("string".equals(p.getType())) {
111 String val = (String) p.getValue();
112 val = '"' + val + '"';
113 parameters.put(pName, val);
115 parameters.put(pName, p.getValue());
116 // Updated code to resolve the issue of missing \ for collector.schema.file
117 // parameters.put(pName, pName.equals("collector.schema.file") ?
118 // ((String)p.getValue()).replace("\"", "\\\"") : p.getValue());
122 if (override != null) {
123 GetInput ov = new GetInput();
124 ov.setBpInputName(Constants.SERVICE_COMPONENT_NAME_OVERRIDE);
125 parameters.put(Constants.SERVICE_COMPONENT_NAME_OVERRIDE, ov);
126 LinkedHashMap<String, Object> over = blueprintHelperService.createStringInput(override);
127 inputs.put(Constants.SERVICE_COMPONENT_NAME_OVERRIDE, over);
129 appconfig.setParams(parameters);
131 response.put("appconfig", appconfig);
132 response.put("inputs", inputs);