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 / dmaap / StreamsService.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.dmaap;
25
26 import org.onap.blueprintgenerator.model.common.GetInput;
27 import org.onap.blueprintgenerator.model.dmaap.Streams;
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 Streams
41  */
42
43
44 @Service
45 public class StreamsService {
46
47     @Autowired
48     private BlueprintHelperService blueprintHelperService;
49
50     //Methos to create streams for Dmaap Blueprint
51     public Map<String, Object> createStreams(Map<String, LinkedHashMap<String, Object>> inputs, String name, String type, String key, String route, char o){
52         Map<String,Object> response = new HashMap<>();
53         Streams streams = new Streams();
54
55         LinkedHashMap<String, Object> stringType = new LinkedHashMap();
56         stringType.put("type", "string");
57
58         streams.setName(name);
59         streams.setType(type);
60
61         GetInput location = new GetInput();
62         location.setBpInputName(key + "_" + name + "_location");
63         inputs.put(key + "_" + name + "_location", stringType);
64         streams.setLocation(location);
65
66         if(blueprintHelperService.isDataRouterType(type)) {
67             if('s' == o) {
68                 GetInput username = new GetInput();
69                 username.setBpInputName(key + "_" + name + "_username");
70                 streams.setUsername(username);
71                 inputs.put(key + "_" + name + "_username", stringType);
72
73                 GetInput password = new GetInput();
74                 password.setBpInputName(key + "_" + name + "_password");
75                 streams.setPassword(password);
76                 inputs.put(key + "_" + name + "_password", stringType);
77
78                 GetInput priviliged = new GetInput();
79                 priviliged.setBpInputName(key + "_" + name + "_priviliged");
80                 streams.setPrivileged(priviliged);
81                 inputs.put(key + "_" + name + "_priviliged", stringType);
82
83                 GetInput decompress = new GetInput();
84                 decompress.setBpInputName(key + "_" + name + "_decompress");
85                 streams.setDecompress(decompress);
86                 inputs.put(key + "_" + name + "_decompress", stringType);
87
88                 streams.setRoute(route);
89                 streams.setScheme("https");
90             }
91
92
93         } else {
94             GetInput client = new GetInput();
95             client.setBpInputName(key + "_" + name + "_client_role");
96             streams.setClient_role(client);
97             inputs.put(key + "_" + name + "_client_role", stringType);
98         }
99         response.put("streams", streams);
100         response.put("inputs", inputs);
101         return response;
102     }
103
104 }