Add Native Kafka streams support in bp-generator
[dcaegen2/platform.git] / mod / bpgenerator / common / src / main / java / org / onap / blueprintgenerator / service / base / BlueprintHelperService.java
1 /*
2  *
3  *  * ============LICENSE_START=======================================================
4  *  *  org.onap.dcae
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
13  *  *
14  *  *   http://www.apache.org/licenses/LICENSE-2.0
15  *  *
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=========================================================
22  *
23  *
24  */
25
26 package org.onap.blueprintgenerator.service.base;
27
28 import org.onap.blueprintgenerator.constants.Constants;
29 import org.springframework.stereotype.Service;
30
31 import java.util.LinkedHashMap;
32
33 /**
34  * @author : Ravi Mantena
35  * @date 10/16/2020 Application: DCAE/ONAP - Blueprint Generator Common Module: Used by both ONAp
36  * and DCAE Blueprint Applications Service: An interface for Common Functions used across Blueprint
37  */
38 @Service
39 public class BlueprintHelperService {
40
41     /**
42      * creates Input value by contatinating Type, Description and Default value
43      *
44      * @param type Input Type
45      * @param description Description
46      * @param defaultValue Default value of Type
47      * @return
48      */
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);
55         return inputMap;
56     }
57
58     /**
59      * creates Input value by contatinating Type and Description
60      *
61      * @param type Input Type
62      * @param description Description
63      * @return
64      */
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);
69         return inputMap;
70     }
71
72     /**
73      * creates Input value by contatinating Type and Default value
74      *
75      * @param type Input Type
76      * @param defaultValue Default value of Type
77      * @return
78      */
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);
83         return inputMap;
84     }
85
86     /**
87      * creates Input value by contatinating Description and Default value
88      *
89      * @param description Description
90      * @param defaultValue Default value of Type
91      * @return
92      */
93     public LinkedHashMap<String, Object> createIntegerInput(String description,
94         Object defaultValue) {
95         return createInputValue(Constants.INTEGER_TYPE, description, defaultValue);
96     }
97
98     /**
99      * creates Integer Input value for given Description
100      *
101      * @param description Description
102      * @return
103      */
104     public LinkedHashMap<String, Object> createIntegerInput(String description) {
105         return createInputValue(Constants.INTEGER_TYPE, description);
106     }
107
108     /**
109      * creates Integer Input value for given Default value
110      *
111      * @param defaultValue Default value of Type
112      * @return
113      */
114     public LinkedHashMap<String, Object> createIntegerInput(Object defaultValue) {
115         return createInputValue(Constants.INTEGER_TYPE, defaultValue);
116     }
117
118     /**
119      * creates Integer Input value for given Description and Default value
120      *
121      * @param description Description
122      * @param defaultValue Default value of Type
123      * @return
124      */
125     public LinkedHashMap<String, Object> createBooleanInput(String description,
126         Object defaultValue) {
127         return createInputValue(Constants.BOOLEAN_TYPE, description, defaultValue);
128     }
129
130     /**
131      * creates Boolean Input value for given Description
132      *
133      * @param description Description
134      * @return
135      */
136     public LinkedHashMap<String, Object> createBooleanInput(String description) {
137         return createInputValue(Constants.BOOLEAN_TYPE, description);
138     }
139
140     /**
141      * creates Boolean Input value for given Default value
142      *
143      * @param defaultValue Default value of Type
144      * @return
145      */
146     public LinkedHashMap<String, Object> createBooleanInput(Object defaultValue) {
147         return createInputValue(Constants.BOOLEAN_TYPE, defaultValue);
148     }
149
150     /**
151      * creates String Input value for given Default value
152      * @param description Description
153      * @param defaultValue Default value of Type
154      * @return
155      */
156     public LinkedHashMap<String, Object> createStringInput(String description,
157         Object defaultValue) {
158         return createInputValue(Constants.STRING_TYPE, description, defaultValue);
159     }
160
161   /*  public LinkedHashMap<String, Object> createStringInput(String description){
162     return createInputValue(Constants.STRING_TYPE, description);
163   }*/
164
165     /**
166      * creates String Input value for given Default value
167      *
168      * @param defaultValue Default value of Type
169      * @return
170      */
171     public LinkedHashMap<String, Object> createStringInput(Object defaultValue) {
172         return createInputValue(Constants.STRING_TYPE, defaultValue);
173     }
174
175     /**
176      * Concatenates String Input values with Underscore
177      *
178      * @param firstValue Value
179      * @param secondValue Value
180      * @return
181      */
182     public String joinUnderscore(String firstValue, String secondValue) {
183         return firstValue + "_" + secondValue;
184     }
185
186     /**
187      * Returns if the type is Data Router or not
188      *
189      * @param type Input Type
190      * @return
191      */
192     public boolean isDataRouterType(String type) {
193         return type.equals(Constants.DATA_ROUTER) || type.equals(Constants.DATAROUTER_VALUE);
194     }
195
196     /**
197      * Returns if the type is Message Router or not
198      *
199      * @param type Input Type
200      * @return
201      */
202     public boolean isMessageRouterType(String type) {
203         return type.equals(Constants.MESSAGE_ROUTER) || type.equals(Constants.MESSAGEROUTER_VALUE);
204     }
205
206     /**
207      * Returns if the type is Kafka or not
208      *
209      * @param type Input Type
210      * @return
211      */
212     public boolean isKafkaStreamType(String type) {
213         return type.equals(Constants.KAFKA_TYPE);
214     }
215
216     /**
217      * Returns name with underscore for empty input
218      *
219      * @param name Name
220      * @return
221      */
222     public String getNamePrefix(String name) {
223         return name.isEmpty() ? "" : name + "_";
224     }
225 }