Merge "Changes to Regex for Name and version Issue-ID: DCAEGEN2-1867"
[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
39  * Application: ONAP - Blueprint Generator
40  * Service to create Message Router and Data Router Information
41  */
42
43 @Service
44 public class InfoService {
45
46     @Autowired
47     private BlueprintHelperService blueprintHelperService;
48
49     // Method to create info for Message Router
50     public Map<String,Object> createMessageRouterInfo(Map<String, LinkedHashMap<String, Object>> inputs, String config, char type) {
51
52         Map<String,Object> response = new HashMap<>();
53         Info info = new Info();
54
55         LinkedHashMap<String, Object> stringType = new LinkedHashMap<>();
56         stringType.put("type", "string");
57
58         config = config.replaceAll("-", "_");
59         if(type == 'p') {
60             config = config + "_publish_url";
61         }
62         else if(type == 's') {
63             config = config+ "_subscribe_url";
64         }
65
66         GetInput topic = new GetInput();
67         topic.setBpInputName(config);
68         info.setTopic_url(topic);
69
70         inputs.put(config, stringType);
71
72         response.put("info", info);
73         response.put("inputs", inputs);
74         return response;
75     }
76
77     // Method to create info for Data Router
78     public Map<String,Object> createDataRouterInfo(Map<String, LinkedHashMap<String, Object>> inputs, String config) {
79
80         Map<String,Object> response = new HashMap<>();
81         Info info = new Info();
82
83         LinkedHashMap<String, Object> stringType = new LinkedHashMap<>();
84         stringType.put("type", "string");
85
86         String userNameInputName = blueprintHelperService.joinUnderscore(config, "username");
87         GetInput username = new GetInput(userNameInputName);
88         info.setUsername(username);
89         inputs.put(userNameInputName, stringType);
90
91         String userpasswordInputName = blueprintHelperService.joinUnderscore(config, "password");
92         GetInput password = new GetInput(userpasswordInputName);
93         info.setPassword(password);
94         inputs.put(userpasswordInputName, stringType);
95
96         String userlocationInputName = blueprintHelperService.joinUnderscore(config, "location");
97         GetInput location = new GetInput(userlocationInputName);
98         info.setLocation(location);
99         inputs.put(userlocationInputName, stringType);
100
101         String userdeliveryUrlInputName = blueprintHelperService.joinUnderscore(config, "delivery_url");
102         GetInput deliveryUrl = new GetInput(userdeliveryUrlInputName);
103         info.setDelivery_url(deliveryUrl);
104         inputs.put(userdeliveryUrlInputName, stringType);
105
106         String usersubscriberIDInputName = blueprintHelperService.joinUnderscore(config, "subscriber_id");
107         GetInput subscriberID = new GetInput(usersubscriberIDInputName);
108         info.setSubscriber_id(subscriberID);
109         inputs.put(usersubscriberIDInputName, stringType);
110
111         response.put("info", info);
112         response.put("inputs", inputs);
113         return response;
114     }
115
116 }