Merge "Update to Policy Model to use sigle map to wrap object Issue-ID: DCAEGEN2...
[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  *  *  Licensed under the Apache License, Version 2.0 (the "License");
9  *  *  you may not use this file except in compliance with the License.
10  *  *  You may obtain a copy of the License at
11  *  *
12  *  *   http://www.apache.org/licenses/LICENSE-2.0
13  *  *
14  *  *  Unless required by applicable law or agreed to in writing, software
15  *  *  distributed under the License is distributed on an "AS IS" BASIS,
16  *  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *  *  See the License for the specific language governing permissions and
18  *  *  limitations under the License.
19  *  *  ============LICENSE_END=========================================================
20  *
21  *
22  */
23
24 package org.onap.blueprintgenerator.service.base;
25
26 import org.onap.blueprintgenerator.constants.Constants;
27 import org.springframework.stereotype.Service;
28
29 import java.util.LinkedHashMap;
30
31 /**
32  * @author : Ravi Mantena
33  * @date 10/16/2020 Application: DCAE/ONAP - Blueprint Generator Common Module: Used by both ONAp
34  * and DCAE Blueprint Applications Service: An interface for Common Functions used across Blueprint
35  */
36 @Service
37 public class BlueprintHelperService {
38
39     /**
40      * creates Input value by contatinating Type, Description and Default value
41      *
42      * @param type Input Type
43      * @param description Description
44      * @param defaultValue Default value of Type
45      * @return
46      */
47     public LinkedHashMap<String, Object> createInputValue(
48         String type, String description, Object defaultValue) {
49         LinkedHashMap<String, Object> inputMap = new LinkedHashMap<>();
50         inputMap.put("type", type);
51         inputMap.put("description", description);
52         inputMap.put("default", defaultValue);
53         return inputMap;
54     }
55
56     /**
57      * creates Input value by contatinating Type and Description
58      *
59      * @param type Input Type
60      * @param description Description
61      * @return
62      */
63     public LinkedHashMap<String, Object> createInputValue(String type, String description) {
64         LinkedHashMap<String, Object> inputMap = new LinkedHashMap<>();
65         inputMap.put("type", type);
66         inputMap.put("description", description);
67         return inputMap;
68     }
69
70     /**
71      * creates Input value by contatinating Type and Default value
72      *
73      * @param type Input Type
74      * @param defaultValue Default value of Type
75      * @return
76      */
77     public LinkedHashMap<String, Object> createInputValue(String type, Object defaultValue) {
78         LinkedHashMap<String, Object> inputMap = new LinkedHashMap<>();
79         inputMap.put("type", type);
80         inputMap.put("default", defaultValue);
81         return inputMap;
82     }
83
84     /**
85      * creates Input value by contatinating Description and Default value
86      *
87      * @param description Description
88      * @param defaultValue Default value of Type
89      * @return
90      */
91     public LinkedHashMap<String, Object> createIntegerInput(String description,
92         Object defaultValue) {
93         return createInputValue(Constants.INTEGER_TYPE, description, defaultValue);
94     }
95
96     /**
97      * creates Integer Input value for given Description
98      *
99      * @param description Description
100      * @return
101      */
102     public LinkedHashMap<String, Object> createIntegerInput(String description) {
103         return createInputValue(Constants.INTEGER_TYPE, description);
104     }
105
106     /**
107      * creates Integer Input value for given Default value
108      *
109      * @param defaultValue Default value of Type
110      * @return
111      */
112     public LinkedHashMap<String, Object> createIntegerInput(Object defaultValue) {
113         return createInputValue(Constants.INTEGER_TYPE, defaultValue);
114     }
115
116     /**
117      * creates Integer Input value for given Description and Default value
118      *
119      * @param description Description
120      * @param defaultValue Default value of Type
121      * @return
122      */
123     public LinkedHashMap<String, Object> createBooleanInput(String description,
124         Object defaultValue) {
125         return createInputValue(Constants.BOOLEAN_TYPE, description, defaultValue);
126     }
127
128     /**
129      * creates Boolean Input value for given Description
130      *
131      * @param description Description
132      * @return
133      */
134     public LinkedHashMap<String, Object> createBooleanInput(String description) {
135         return createInputValue(Constants.BOOLEAN_TYPE, description);
136     }
137
138     /**
139      * creates Boolean Input value for given Default value
140      *
141      * @param defaultValue Default value of Type
142      * @return
143      */
144     public LinkedHashMap<String, Object> createBooleanInput(Object defaultValue) {
145         return createInputValue(Constants.BOOLEAN_TYPE, defaultValue);
146     }
147
148     /**
149      * creates String Input value for given Default value
150      * @param description Description
151      * @param defaultValue Default value of Type
152      * @return
153      */
154     public LinkedHashMap<String, Object> createStringInput(String description,
155         Object defaultValue) {
156         return createInputValue(Constants.STRING_TYPE, description, defaultValue);
157     }
158
159   /*  public LinkedHashMap<String, Object> createStringInput(String description){
160     return createInputValue(Constants.STRING_TYPE, description);
161   }*/
162
163     /**
164      * creates String Input value for given Default value
165      *
166      * @param defaultValue Default value of Type
167      * @return
168      */
169     public LinkedHashMap<String, Object> createStringInput(Object defaultValue) {
170         return createInputValue(Constants.STRING_TYPE, defaultValue);
171     }
172
173     /**
174      * Concatenates String Input values with Underscore
175      *
176      * @param firstValue Value
177      * @param secondValue Value
178      * @return
179      */
180     public String joinUnderscore(String firstValue, String secondValue) {
181         return firstValue + "_" + secondValue;
182     }
183
184     /**
185      * Returns if the type is Data Router or not
186      *
187      * @param type Input Type
188      * @return
189      */
190     public boolean isDataRouterType(String type) {
191         return type.equals(Constants.DATA_ROUTER) || type.equals(Constants.DATAROUTER_VALUE);
192     }
193
194     /**
195      * Returns if the type is Message Router or not
196      *
197      * @param type Input Type
198      * @return
199      */
200     public boolean isMessageRouterType(String type) {
201         return type.equals(Constants.MESSAGE_ROUTER) || type.equals(Constants.MESSAGEROUTER_VALUE);
202     }
203
204     /**
205      * Returns name with underscore for empty input
206      *
207      * @param name Name
208      * @return
209      */
210     public String getNamePrefix(String name) {
211         return name.isEmpty() ? "" : name + "_";
212     }
213 }