Merge "Policy Model Distribution POC Issue-ID: DCAEGEN2-1868"
[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
39  * Application: ONAP - Blueprint Generator
40  * Common ONAP Service used by ONAP and DMAAP Blueprint to add DMAAP Message and Data Routers
41  */
42
43
44 @Service
45 public class DmaapService {
46
47     @Autowired
48     private InfoService infoService;
49
50     // Method is used to create the Dmaap Message Router
51     public Map<String,Object> createDmaapMessageRouter(Map<String, LinkedHashMap<String, Object>> inputs,String config, char type, String counter, String num, boolean isDmaap) {
52
53         Map<String,Object> response = new HashMap<>();
54         Dmaap dmaap = new Dmaap();
55
56         LinkedHashMap<String, Object> stringType = new LinkedHashMap();
57         stringType.put("type", "string");
58
59         if(!isDmaap){
60             Map<String, Object> infoResponse = infoService.createMessageRouterInfo(inputs, config, type);
61             inputs = (Map<String, LinkedHashMap<String, Object>>) infoResponse.get("inputs");
62             dmaap.setDmaap_info(infoResponse.get("info"));
63         }
64         else{
65             String infoType = "<<" + counter + ">>";
66             dmaap.setDmaap_info(infoType);
67
68             GetInput u = new GetInput();
69             u.setBpInputName(config + "_" + num +"_aaf_username");
70             dmaap.setUser(u);
71             inputs.put(config + "_" + num +"_aaf_username", stringType);
72
73             GetInput p = new GetInput();
74             p.setBpInputName(config + "_" + num +"_aaf_password");
75             dmaap.setPass(p);
76             inputs.put(config + "_" + num +"_aaf_password", stringType);
77         }
78         response.put("dmaap", dmaap);
79         response.put("inputs", inputs);
80         return response;
81     }
82
83     // Method is used to create the Dmaap Data Router
84     public Map<String,Object> createDmaapDataRouter(Map<String, LinkedHashMap<String, Object>> inputs, String config, String counter, boolean isDmaap) {
85
86         Map<String,Object> response = new HashMap<>();
87         Dmaap dmaap = new Dmaap();
88
89         if(!isDmaap){
90             Map<String, Object> infoResponse = infoService.createDataRouterInfo(inputs, config);
91             inputs = (Map<String, LinkedHashMap<String, Object>>) infoResponse.get("inputs");
92             dmaap.setDmaap_info(infoResponse.get("info"));
93         }
94         else {
95             String infoType = "<<" + counter + ">>";
96             dmaap.setDmaap_info(infoType);
97         }
98         response.put("dmaap", dmaap);
99         response.put("inputs", inputs);
100         return response;
101     }
102
103 }