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