Refactor, fix code formatting and add unittests
[dcaegen2/platform.git] / mod / bpgenerator / src / main / java / org / onap / blueprintgenerator / models / dmaapbp / DmaapStreams.java
1 /*============LICENSE_START=======================================================
2  org.onap.dcae
3  ================================================================================
4  Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
5  Copyright (c) 2020 Nokia. All rights reserved.
6  ================================================================================
7  Licensed under the Apache License, Version 2.0 (the "License");
8  you may not use this file except in compliance with the License.
9  You may obtain a copy of the License at
10
11       http://www.apache.org/licenses/LICENSE-2.0
12  
13  Unless required by applicable law or agreed to in writing, software
14  distributed under the License is distributed on an "AS IS" BASIS,
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  See the License for the specific language governing permissions and
17  limitations under the License.
18  ============LICENSE_END=========================================================
19  
20  */
21
22 package org.onap.blueprintgenerator.models.dmaapbp;
23
24 import java.util.LinkedHashMap;
25 import java.util.TreeMap;
26
27 import org.onap.blueprintgenerator.models.blueprint.GetInput;
28 import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
29
30 import com.fasterxml.jackson.annotation.JsonInclude;
31 import com.fasterxml.jackson.annotation.JsonInclude.Include;
32
33 import lombok.Getter;
34 import lombok.Setter;
35
36 import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.isDataRouterType;
37
38 @Getter
39 @Setter
40 @JsonInclude(value = Include.NON_NULL)
41 public class DmaapStreams {
42
43     private String name;
44     private GetInput location;
45     private GetInput client_role;
46     private String type;
47
48     private GetInput username;
49     private GetInput password;
50     //private GetInput delivery_url;
51
52     private GetInput privileged;
53     private GetInput decompress;
54
55     private String route;
56     private String scheme;
57
58     public TreeMap<String, LinkedHashMap<String, Object>> createStreams(
59         TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec cs, String name, String type, String key,
60         String route, char o) {
61         TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;
62         LinkedHashMap<String, Object> stringType = new LinkedHashMap();
63         stringType.put("type", "string");
64
65         //set the name
66         this.setName(name);
67
68         //set the type
69         this.setType(type);
70
71         //set the location
72         GetInput location = new GetInput();
73         location.setBpInputName(key + "_" + name + "_location");
74         retInputs.put(key + "_" + name + "_location", stringType);
75         this.setLocation(location);
76
77         //if its data router we need to add some more
78         if (isDataRouterType(type)) {
79             if ('s' == o) {
80                 //set the username
81                 GetInput username = new GetInput();
82                 username.setBpInputName(key + "_" + name + "_username");
83                 this.setUsername(username);
84                 retInputs.put(key + "_" + name + "_username", stringType);
85
86                 //set the password
87                 GetInput password = new GetInput();
88                 password.setBpInputName(key + "_" + name + "_password");
89                 this.setPassword(password);
90                 retInputs.put(key + "_" + name + "_password", stringType);
91
92                 //set privileged
93                 GetInput priviliged = new GetInput();
94                 priviliged.setBpInputName(key + "_" + name + "_priviliged");
95                 this.setPrivileged(priviliged);
96                 retInputs.put(key + "_" + name + "_priviliged", stringType);
97
98                 //set decompress
99                 GetInput decompress = new GetInput();
100                 decompress.setBpInputName(key + "_" + name + "_decompress");
101                 this.setDecompress(decompress);
102                 retInputs.put(key + "_" + name + "_decompress", stringType);
103
104                 this.setRoute(route);
105                 this.setScheme("https");
106             }
107
108 //                      //set the delivery url
109 //                      GetInput delivery = new GetInput();
110 //                      delivery.setGet_input(name + "_delivery_url");
111 //                      this.setDelivery_url(delivery);
112 //                      retInputs.put(name + "delivery_url", stringType);
113
114         } else {
115             //set the client role
116             GetInput client = new GetInput();
117             client.setBpInputName(key + "_" + name + "_client_role");
118             this.setClient_role(client);
119             retInputs.put(key + "_" + name + "_client_role", stringType);
120         }
121         return retInputs;
122     }
123 }