Fix sonar issues
[dcaegen2/platform.git] / mod / bpgenerator / onap / src / main / java / org / onap / blueprintgenerator / service / common / DmaapService.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.common;
26
27 import org.onap.blueprintgenerator.model.common.Dmaap;
28 import org.onap.blueprintgenerator.model.common.GetInput;
29 import org.onap.blueprintgenerator.service.InfoService;
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 Common ONAP Service to add DMAAP Message
40  * and Data Routers
41  */
42 @Service
43 public class DmaapService {
44
45     @Autowired
46     private InfoService infoService;
47
48     /**
49      * Creates Dmaap Message Router from given inputs
50      *
51      * @param inputs Input Arguments
52      * @param config Configuration
53      * @param type BP Type
54      * @param counter Counter
55      * @param num Number Incrementor
56      * @param isDmaap Dmaap Argument
57      * @return
58      */
59     public Map<String, Object> createDmaapMessageRouter(
60         Map<String, Map<String, Object>> inputs,
61         String config,
62         char type,
63         String counter,
64         String num,
65         boolean isDmaap) {
66
67         Map<String, Object> response = new HashMap<>();
68         Dmaap dmaap = new Dmaap();
69
70         LinkedHashMap<String, Object> stringType = new LinkedHashMap();
71         stringType.put("type", "string");
72
73         if (!isDmaap) {
74             Map<String, Object> infoResponse = infoService
75                 .createMessageRouterInfo(inputs, config, type);
76             inputs = (Map<String, Map<String, Object>>) infoResponse.get("inputs");
77             dmaap.setDmaap_info(infoResponse.get("info"));
78         } else {
79             String infoType = "<<" + counter + ">>";
80             dmaap.setDmaap_info(infoType);
81
82             GetInput u = new GetInput();
83             u.setBpInputName(config + "_" + num + "_aaf_username");
84             dmaap.setUser(u);
85             inputs.put(config + "_" + num + "_aaf_username", stringType);
86
87             GetInput p = new GetInput();
88             p.setBpInputName(config + "_" + num + "_aaf_password");
89             dmaap.setPass(p);
90             inputs.put(config + "_" + num + "_aaf_password", stringType);
91         }
92         response.put("dmaap", dmaap);
93         response.put("inputs", inputs);
94         return response;
95     }
96
97     /**
98      * Creates Dmaap Data Router from given inputs
99      *
100      * @param inputs Input Arguments
101      * @param config Configuration
102      * @param counter Counter
103      * @param isDmaap Dmaap Argument
104      * @return
105      */
106     public Map<String, Object> createDmaapDataRouter(
107         Map<String, Map<String, Object>> inputs,
108         String config,
109         String counter,
110         boolean isDmaap) {
111
112         Map<String, Object> response = new HashMap<>();
113         Dmaap dmaap = new Dmaap();
114
115         if (!isDmaap) {
116             Map<String, Object> infoResponse = infoService.createDataRouterInfo(inputs, config);
117             inputs = (Map<String, Map<String, Object>>) infoResponse.get("inputs");
118             dmaap.setDmaap_info(infoResponse.get("info"));
119         } else {
120             String infoType = "<<" + counter + ">>";
121             dmaap.setDmaap_info(infoType);
122         }
123         response.put("dmaap", dmaap);
124         response.put("inputs", inputs);
125         return response;
126     }
127 }