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