Fix sonar issues
[dcaegen2/platform.git] / mod / bpgenerator / onap / src / main / java / org / onap / blueprintgenerator / service / InfoService.java
1 /*
2  *
3  *  * ============LICENSE_START=======================================================
4  *  *  org.onap.dcae
5  *  *  ================================================================================
6  *  *  Copyright (c) 2020  AT&T Intellectual Property. All rights reserved.
7  *  *  Copyright (c) 2021 Nokia. All rights reserved.
8  *  *  ================================================================================
9  *  *  Licensed under the Apache License, Version 2.0 (the "License");
10  *  *  you may not use this file except in compliance with the License.
11  *  *  You may obtain a copy of the License at
12  *  *
13  *  *       http://www.apache.org/licenses/LICENSE-2.0
14  *  *
15  *  *  Unless required by applicable law or agreed to in writing, software
16  *  *  distributed under the License is distributed on an "AS IS" BASIS,
17  *  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  *  *  See the License for the specific language governing permissions and
19  *  *  limitations under the License.
20  *  *  ============LICENSE_END=========================================================
21  *
22  *
23  */
24
25 package org.onap.blueprintgenerator.service;
26
27 import org.onap.blueprintgenerator.model.common.GetInput;
28 import org.onap.blueprintgenerator.model.common.Info;
29 import org.onap.blueprintgenerator.service.base.BlueprintHelperService;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.stereotype.Service;
32
33 import java.util.HashMap;
34 import java.util.LinkedHashMap;
35 import java.util.Map;
36
37 /**
38  * @author : Ravi Mantena
39  * @date 10/16/2020 Application: ONAP - Blueprint Generator Service to create Message Router and
40  * Data Router Information
41  */
42 @Service
43 public class InfoService {
44
45     @Autowired
46     private BlueprintHelperService blueprintHelperService;
47
48     /**
49      * Creates info for Message Router
50      *
51      * @param inputs Inputs
52      * @param config Config
53      * @param type BP Type
54      * @return
55      */
56     public Map<String, Object> createMessageRouterInfo(
57         Map<String, Map<String, Object>> inputs, String config, char type) {
58
59         Map<String, Object> response = new HashMap<>();
60         Info info = new Info();
61
62         Map<String, Object> stringType = new LinkedHashMap<>();
63         stringType.put("type", "string");
64
65         config = config.replaceAll("-", "_");
66         if (type == 'p') {
67             config = config + "_publish_url";
68         } else if (type == 's') {
69             config = config + "_subscribe_url";
70         }
71
72         GetInput topic = new GetInput();
73         topic.setBpInputName(config);
74         info.setTopic_url(topic);
75
76         inputs.put(config, stringType);
77
78         response.put("info", info);
79         response.put("inputs", inputs);
80         return response;
81     }
82
83     /**
84      * Creates info for Data Router
85      *
86      * @param inputs Inputs
87      * @param config Config
88      * @return
89      */
90     public Map<String, Object> createDataRouterInfo(
91         Map<String, Map<String, Object>> inputs, String config) {
92
93         Map<String, Object> response = new HashMap<>();
94         Info info = new Info();
95
96         Map<String, Object> stringType = new LinkedHashMap<>();
97         stringType.put("type", "string");
98
99         String userNameInputName = blueprintHelperService.joinUnderscore(config, "username");
100         GetInput username = new GetInput(userNameInputName);
101         info.setUsername(username);
102         inputs.put(userNameInputName, stringType);
103
104         String userpasswordInputName = blueprintHelperService.joinUnderscore(config, "password");
105         GetInput password = new GetInput(userpasswordInputName);
106         info.setPassword(password);
107         inputs.put(userpasswordInputName, stringType);
108
109         String userlocationInputName = blueprintHelperService.joinUnderscore(config, "location");
110         GetInput location = new GetInput(userlocationInputName);
111         info.setLocation(location);
112         inputs.put(userlocationInputName, stringType);
113
114         String userdeliveryUrlInputName = blueprintHelperService
115             .joinUnderscore(config, "delivery_url");
116         GetInput deliveryUrl = new GetInput(userdeliveryUrlInputName);
117         info.setDelivery_url(deliveryUrl);
118         inputs.put(userdeliveryUrlInputName, stringType);
119
120         String usersubscriberIDInputName =
121             blueprintHelperService.joinUnderscore(config, "subscriber_id");
122         GetInput subscriberID = new GetInput(usersubscriberIDInputName);
123         info.setSubscriber_id(subscriberID);
124         inputs.put(usersubscriberIDInputName, stringType);
125
126         response.put("info", info);
127         response.put("inputs", inputs);
128         return response;
129     }
130 }