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;
32 import java.util.LinkedHashMap;
35 * @author : Ravi Mantena
36 * @date 10/16/2020 Application: DCAE/ONAP - Blueprint Generator Common Module: Used by both ONAp and DCAE Blueprint
37 * Applications Service: An interface for Common Functions used across Blueprint
40 public class BlueprintHelperService {
43 * creates Input value by contatinating Type, Description and Default value
45 * @param type Input Type
46 * @param description Description
47 * @param defaultValue Default value of Type
50 public Map<String, Object> createInputValue(
51 String type, String description, Object defaultValue) {
52 LinkedHashMap<String, Object> inputMap = new LinkedHashMap<>();
53 inputMap.put("type", type);
54 inputMap.put("description", description);
55 inputMap.put("default", defaultValue);
60 * creates Input value by contatinating Type and Description
62 * @param type Input Type
63 * @param description Description
66 public Map<String, Object> createInputValue(String type, String description) {
67 LinkedHashMap<String, Object> inputMap = new LinkedHashMap<>();
68 inputMap.put("type", type);
69 inputMap.put("description", description);
74 * creates Input value by contatinating Type and Default value
76 * @param type Input Type
77 * @param defaultValue Default value of Type
80 public Map<String, Object> createInputValue(String type, Object defaultValue) {
81 LinkedHashMap<String, Object> inputMap = new LinkedHashMap<>();
82 inputMap.put("type", type);
83 inputMap.put("default", defaultValue);
88 * creates Input value by contatinating Description and Default value
90 * @param description Description
91 * @param defaultValue Default value of Type
94 public Map<String, Object> createIntegerInput(String description,
95 Object defaultValue) {
96 return createInputValue(Constants.INTEGER_TYPE, description, defaultValue);
100 * creates Integer Input value for given Description
102 * @param description Description
105 public Map<String, Object> createIntegerInput(String description) {
106 return createInputValue(Constants.INTEGER_TYPE, description);
110 * creates Integer Input value for given Default value
112 * @param defaultValue Default value of Type
115 public Map<String, Object> createIntegerInput(Object defaultValue) {
116 return createInputValue(Constants.INTEGER_TYPE, defaultValue);
120 * creates Integer Input value for given Description and Default value
122 * @param description Description
123 * @param defaultValue Default value of Type
126 public Map<String, Object> createBooleanInput(String description,
127 Object defaultValue) {
128 return createInputValue(Constants.BOOLEAN_TYPE, description, defaultValue);
132 * creates Boolean Input value for given Description
134 * @param description Description
137 public Map<String, Object> createBooleanInput(String description) {
138 return createInputValue(Constants.BOOLEAN_TYPE, description);
142 * creates Boolean Input value for given Default value
144 * @param defaultValue Default value of Type
147 public Map<String, Object> createBooleanInput(Object defaultValue) {
148 return createInputValue(Constants.BOOLEAN_TYPE, defaultValue);
152 * creates String Input value for given Default value
154 * @param description Description
155 * @param defaultValue Default value of Type
158 public Map<String, Object> createStringInput(String description,
159 Object defaultValue) {
160 return createInputValue(Constants.STRING_TYPE, description, defaultValue);
164 * creates String Input value for given Default value
166 * @param defaultValue Default value of Type
169 public Map<String, Object> createStringInput(Object defaultValue) {
170 return createInputValue(Constants.STRING_TYPE, defaultValue);
174 * creates proper Input for given inputType and defaultValue.
176 * Default input type: "string".
178 * @param inputType Input type, supported: "boolean", "integer", "number"
179 * @param defaultValue Default value of Type
182 public Map<String, Object> createInputByType(String inputType, Object defaultValue) {
185 return createBooleanInput(defaultValue);
188 return createIntegerInput(defaultValue);
190 return createStringInput(defaultValue);
196 * Concatenates String Input values with Underscore
198 * @param firstValue Value
199 * @param secondValue Value
202 public String joinUnderscore(String firstValue, String secondValue) {
203 return firstValue + "_" + secondValue;
207 * Returns if the type is Data Router or not
209 * @param type Input Type
212 public boolean isDataRouterType(String type) {
213 return type.equals(Constants.DATA_ROUTER) || type.equals(Constants.DATAROUTER_VALUE);
217 * Returns if the type is Message Router or not
219 * @param type Input Type
222 public boolean isMessageRouterType(String type) {
223 return type.equals(Constants.MESSAGE_ROUTER) || type.equals(Constants.MESSAGEROUTER_VALUE);
227 * Returns if the type is Kafka or not
229 * @param type Input Type
232 public boolean isKafkaStreamType(String type) {
233 return type.equals(Constants.KAFKA_TYPE);
237 * Returns name with underscore for empty input
242 public String getNamePrefix(String name) {
243 return name.isEmpty() ? "" : name + "_";