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.base;
28 import org.onap.blueprintgenerator.constants.Constants;
29 import org.springframework.stereotype.Service;
31 import java.util.LinkedHashMap;
34 * @author : Ravi Mantena
35 * @date 10/16/2020 Application: DCAE/ONAP - Blueprint Generator Common Module: Used by both ONAp and DCAE Blueprint
36 * Applications Service: An interface for Common Functions used across Blueprint
39 public class BlueprintHelperService {
42 * creates Input value by contatinating Type, Description and Default value
44 * @param type Input Type
45 * @param description Description
46 * @param defaultValue Default value of Type
49 public LinkedHashMap<String, Object> createInputValue(
50 String type, String description, Object defaultValue) {
51 LinkedHashMap<String, Object> inputMap = new LinkedHashMap<>();
52 inputMap.put("type", type);
53 inputMap.put("description", description);
54 inputMap.put("default", defaultValue);
59 * creates Input value by contatinating Type and Description
61 * @param type Input Type
62 * @param description Description
65 public LinkedHashMap<String, Object> createInputValue(String type, String description) {
66 LinkedHashMap<String, Object> inputMap = new LinkedHashMap<>();
67 inputMap.put("type", type);
68 inputMap.put("description", description);
73 * creates Input value by contatinating Type and Default value
75 * @param type Input Type
76 * @param defaultValue Default value of Type
79 public LinkedHashMap<String, Object> createInputValue(String type, Object defaultValue) {
80 LinkedHashMap<String, Object> inputMap = new LinkedHashMap<>();
81 inputMap.put("type", type);
82 inputMap.put("default", defaultValue);
87 * creates Input value by contatinating Description and Default value
89 * @param description Description
90 * @param defaultValue Default value of Type
93 public LinkedHashMap<String, Object> createIntegerInput(String description,
94 Object defaultValue) {
95 return createInputValue(Constants.INTEGER_TYPE, description, defaultValue);
99 * creates Integer Input value for given Description
101 * @param description Description
104 public LinkedHashMap<String, Object> createIntegerInput(String description) {
105 return createInputValue(Constants.INTEGER_TYPE, description);
109 * creates Integer Input value for given Default value
111 * @param defaultValue Default value of Type
114 public LinkedHashMap<String, Object> createIntegerInput(Object defaultValue) {
115 return createInputValue(Constants.INTEGER_TYPE, defaultValue);
119 * creates Integer Input value for given Description and Default value
121 * @param description Description
122 * @param defaultValue Default value of Type
125 public LinkedHashMap<String, Object> createBooleanInput(String description,
126 Object defaultValue) {
127 return createInputValue(Constants.BOOLEAN_TYPE, description, defaultValue);
131 * creates Boolean Input value for given Description
133 * @param description Description
136 public LinkedHashMap<String, Object> createBooleanInput(String description) {
137 return createInputValue(Constants.BOOLEAN_TYPE, description);
141 * creates Boolean Input value for given Default value
143 * @param defaultValue Default value of Type
146 public LinkedHashMap<String, Object> createBooleanInput(Object defaultValue) {
147 return createInputValue(Constants.BOOLEAN_TYPE, defaultValue);
151 * creates String Input value for given Default value
153 * @param description Description
154 * @param defaultValue Default value of Type
157 public LinkedHashMap<String, Object> createStringInput(String description,
158 Object defaultValue) {
159 return createInputValue(Constants.STRING_TYPE, description, defaultValue);
162 /* public LinkedHashMap<String, Object> createStringInput(String description){
163 return createInputValue(Constants.STRING_TYPE, description);
167 * creates String Input value for given Default value
169 * @param defaultValue Default value of Type
172 public LinkedHashMap<String, Object> createStringInput(Object defaultValue) {
173 return createInputValue(Constants.STRING_TYPE, defaultValue);
177 * creates proper Input for given inputType and defaultValue.
179 * Default input type: "string".
181 * @param inputType Input type, supported: "boolean", "integer", "number"
182 * @param defaultValue Default value of Type
185 public LinkedHashMap<String, Object> createInputByType(String inputType, Object defaultValue) {
188 return createBooleanInput(defaultValue);
191 return createIntegerInput(defaultValue);
193 return createStringInput(defaultValue);
199 * Concatenates String Input values with Underscore
201 * @param firstValue Value
202 * @param secondValue Value
205 public String joinUnderscore(String firstValue, String secondValue) {
206 return firstValue + "_" + secondValue;
210 * Returns if the type is Data Router or not
212 * @param type Input Type
215 public boolean isDataRouterType(String type) {
216 return type.equals(Constants.DATA_ROUTER) || type.equals(Constants.DATAROUTER_VALUE);
220 * Returns if the type is Message Router or not
222 * @param type Input Type
225 public boolean isMessageRouterType(String type) {
226 return type.equals(Constants.MESSAGE_ROUTER) || type.equals(Constants.MESSAGEROUTER_VALUE);
230 * Returns if the type is Kafka or not
232 * @param type Input Type
235 public boolean isKafkaStreamType(String type) {
236 return type.equals(Constants.KAFKA_TYPE);
240 * Returns name with underscore for empty input
245 public String getNamePrefix(String name) {
246 return name.isEmpty() ? "" : name + "_";