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