66f71daae86a42ade247b2889ef939213604e80b
[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  *  *  ================================================================================
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;
25
26 import org.onap.blueprintgenerator.model.common.GetInput;
27 import org.onap.blueprintgenerator.model.common.Info;
28 import org.onap.blueprintgenerator.service.base.BlueprintHelperService;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.stereotype.Service;
31
32 import java.util.HashMap;
33 import java.util.LinkedHashMap;
34 import java.util.Map;
35
36 /**
37  * @author : Ravi Mantena
38  * @date 10/16/2020 Application: ONAP - Blueprint Generator Service to create Message Router and
39  * Data Router Information
40  */
41 @Service
42 public class InfoService {
43
44     @Autowired
45     private BlueprintHelperService blueprintHelperService;
46
47     /**
48      * Creates info for Message Router
49      *
50      * @param inputs Inputs
51      * @param config Config
52      * @param type BP Type
53      * @return
54      */
55     public Map<String, Object> createMessageRouterInfo(
56         Map<String, LinkedHashMap<String, Object>> inputs, String config, char type) {
57
58         Map<String, Object> response = new HashMap<>();
59         Info info = new Info();
60
61         LinkedHashMap<String, Object> stringType = new LinkedHashMap<>();
62         stringType.put("type", "string");
63
64         config = config.replaceAll("-", "_");
65         if (type == 'p') {
66             config = config + "_publish_url";
67         } else if (type == 's') {
68             config = config + "_subscribe_url";
69         }
70
71         GetInput topic = new GetInput();
72         topic.setBpInputName(config);
73         info.setTopic_url(topic);
74
75         inputs.put(config, stringType);
76
77         response.put("info", info);
78         response.put("inputs", inputs);
79         return response;
80     }
81
82     /**
83      * Creates info for Data Router
84      *
85      * @param inputs Inputs
86      * @param config Config
87      * @return
88      */
89     public Map<String, Object> createDataRouterInfo(
90         Map<String, LinkedHashMap<String, Object>> inputs, String config) {
91
92         Map<String, Object> response = new HashMap<>();
93         Info info = new Info();
94
95         LinkedHashMap<String, Object> stringType = new LinkedHashMap<>();
96         stringType.put("type", "string");
97
98         String userNameInputName = blueprintHelperService.joinUnderscore(config, "username");
99         GetInput username = new GetInput(userNameInputName);
100         info.setUsername(username);
101         inputs.put(userNameInputName, stringType);
102
103         String userpasswordInputName = blueprintHelperService.joinUnderscore(config, "password");
104         GetInput password = new GetInput(userpasswordInputName);
105         info.setPassword(password);
106         inputs.put(userpasswordInputName, stringType);
107
108         String userlocationInputName = blueprintHelperService.joinUnderscore(config, "location");
109         GetInput location = new GetInput(userlocationInputName);
110         info.setLocation(location);
111         inputs.put(userlocationInputName, stringType);
112
113         String userdeliveryUrlInputName = blueprintHelperService
114             .joinUnderscore(config, "delivery_url");
115         GetInput deliveryUrl = new GetInput(userdeliveryUrlInputName);
116         info.setDelivery_url(deliveryUrl);
117         inputs.put(userdeliveryUrlInputName, stringType);
118
119         String usersubscriberIDInputName =
120             blueprintHelperService.joinUnderscore(config, "subscriber_id");
121         GetInput subscriberID = new GetInput(usersubscriberIDInputName);
122         info.setSubscriber_id(subscriberID);
123         inputs.put(usersubscriberIDInputName, stringType);
124
125         response.put("info", info);
126         response.put("inputs", inputs);
127         return response;
128     }
129 }