Merge "Changes to Regex for Name and version Issue-ID: DCAEGEN2-1867"
[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
27 import org.onap.blueprintgenerator.constants.Constants;
28 import org.springframework.stereotype.Service;
29
30 import java.util.LinkedHashMap;
31
32 /**
33  * @author : Ravi Mantena
34  * @date 10/16/2020
35  * Application: DCAE/ONAP - Blueprint Generator
36  * Common Module: Used by both ONAp and DCAE Blueprint Applications
37  * Service: For Common Functions used across
38  */
39
40 @Service
41 public class BlueprintHelperService {
42
43
44   public LinkedHashMap<String, Object> createInputValue(String type, String description, Object defaultValue) {
45     LinkedHashMap<String, Object> inputMap = new LinkedHashMap<>();
46     inputMap.put("type", type);
47     inputMap.put("description", description);
48     inputMap.put("default", defaultValue);
49     return inputMap;
50   }
51
52   public LinkedHashMap<String, Object> createInputValue(String type, String description) {
53     LinkedHashMap<String, Object> inputMap = new LinkedHashMap<>();
54     inputMap.put("type", type);
55     inputMap.put("description", description);
56     return inputMap;
57   }
58
59   public LinkedHashMap<String, Object> createInputValue(String type, Object defaultValue) {
60     LinkedHashMap<String, Object> inputMap = new LinkedHashMap<>();
61     inputMap.put("type", type);
62     inputMap.put("default", defaultValue);
63     return inputMap;
64   }
65
66   public LinkedHashMap<String, Object> createIntegerInput(String description, Object defaultValue){
67     return createInputValue(Constants.INTEGER_TYPE, description, defaultValue);
68   }
69
70   public LinkedHashMap<String, Object> createIntegerInput(String description){
71     return createInputValue(Constants.INTEGER_TYPE, description);
72   }
73
74   public LinkedHashMap<String, Object> createIntegerInput(Object defaultValue){
75     return createInputValue(Constants.INTEGER_TYPE, defaultValue);
76   }
77
78   public LinkedHashMap<String, Object> createBooleanInput(String description, Object defaultValue){
79     return createInputValue(Constants.BOOLEAN_TYPE, description, defaultValue);
80   }
81
82   public LinkedHashMap<String, Object> createBooleanInput(String description){
83     return createInputValue(Constants.BOOLEAN_TYPE, description);
84   }
85
86   public LinkedHashMap<String, Object> createBooleanInput(Object defaultValue){
87     return createInputValue(Constants.BOOLEAN_TYPE, defaultValue);
88   }
89
90   public LinkedHashMap<String, Object> createStringInput(String description, Object defaultValue){
91     return createInputValue(Constants.STRING_TYPE, description, defaultValue);
92   }
93
94 /*  public LinkedHashMap<String, Object> createStringInput(String description){
95     return createInputValue(Constants.STRING_TYPE, description);
96   }*/
97
98   public LinkedHashMap<String, Object> createStringInput(Object defaultValue){
99     return createInputValue(Constants.STRING_TYPE, defaultValue);
100   }
101
102   public String joinUnderscore(String firstValue, String secondValue){
103     return firstValue + "_" + secondValue;
104   }
105
106   public boolean isDataRouterType(String type) {
107     return type.equals(Constants.DATA_ROUTER) || type.equals(Constants.DATAROUTER_VALUE);
108   }
109
110   public boolean isMessageRouterType(String type) {
111     return type.equals(Constants.MESSAGE_ROUTER) || type.equals(Constants.MESSAGEROUTER_VALUE);
112   }
113
114   public String getNamePrefix(String name) {
115     return name.isEmpty() ? "" : name + "_";
116   }
117
118 }