Distributing Blueprint to DCAE Dashboard Issue-ID: DCAEGEN2-2385>
[dcaegen2/platform.git] / mod2 / catalog-service / src / main / java / org / onap / dcaegen2 / platform / mod / util / BlueprintDistributionUtils.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  org.onap.dcae
4  *  ================================================================================
5  *  Copyright (c) 2021 AT&T Intellectual Property. 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 package org.onap.dcaegen2.platform.mod.util;
22
23 import java.util.HashMap;
24 import java.util.Map;
25 import javax.annotation.PostConstruct;
26 import org.onap.dcaegen2.platform.mod.model.exceptions.policymodel.PolicyModelDistributionEnvNotFoundException;
27 import org.onap.dcaegen2.platform.mod.model.policymodel.EnvInfo;
28 import org.onap.dcaegen2.platform.mod.model.policymodel.PolicyModelDistributionEnv;
29 import org.springframework.beans.factory.annotation.Value;
30 import org.springframework.stereotype.Component;
31
32 /**
33  * Policy Model Service Utils to get URL, Username, Password, Webclient
34  */
35
36 @Component
37 public class BlueprintDistributionUtils {
38
39     @Value("${dcae.platform.url.path}")
40     private String urlpath;
41
42     @Value("${dcae.platform.dev.server}")
43     private String devServer;
44
45     @Value("${dcae.platform.dev.port}")
46     private String devServerPort;
47
48     @Value("${dcae.platform.dev.user}")
49     private String devServerUser;
50
51     @Value("${dcae.platform.dev.password}")
52     private String devServerUserPassword;
53
54     @Value("${dcae.platform.pst.server}")
55     private String pstServer;
56
57     @Value("${dcae.platform.pst.port}")
58     private String pstServerPort;
59
60     @Value("${dcae.platform.pst.user}")
61     private String pstServerUser;
62
63     @Value("${dcae.platform.pst.password}")
64     private String pstServerUserPassword;
65
66     @Value("${dcae.platform.ete.server}")
67     private String eteServer;
68
69     @Value("${dcae.platform.ete.port}")
70     private String eteServerPort;
71
72     @Value("${dcae.platform.ete.user}")
73     private String eteServerUser;
74
75     @Value("${dcae.platform.ete.password}")
76     private String eteServerUserPassword;
77
78     @Value("${dcae.platform.prod.server}")
79     private String prodServer;
80
81     @Value("${dcae.platform.prod.port}")
82     private String prodServerPort;
83
84     @Value("${dcae.platform.prod.user}")
85     private String prodServerUser;
86
87     @Value("${dcae.platform.prod.password}")
88     private String prodServerUserPassword;
89
90     Map<String, EnvInfo> envMap;
91
92     /**
93      * Creates a Blueprint Distribution Dashboard URL for the Environment requested
94      */
95     @PostConstruct
96     public void init() {
97         envMap = new HashMap<>();
98         envMap.put(PolicyModelDistributionEnv.DEV.name(), EnvInfo.builder().url("https://"+ devServer + ":" + devServerPort + urlpath).username(devServerUser).password(devServerUserPassword).build());
99         envMap.put(PolicyModelDistributionEnv.PST.name(), EnvInfo.builder().url("https://"+ pstServer + ":" + pstServerPort + urlpath).username(pstServerUser).password(pstServerUserPassword).build());
100         envMap.put(PolicyModelDistributionEnv.ETE.name(), EnvInfo.builder().url("https://"+ eteServer + ":" + eteServerPort + urlpath).username(eteServerUser).password(eteServerUserPassword).build());
101         envMap.put(PolicyModelDistributionEnv.PROD.name(), EnvInfo.builder().url("https://"+ prodServer + ":" + prodServerPort + urlpath).username(prodServerUser).password(prodServerUserPassword).build());
102     }
103
104     /**
105      * Generates a Blueprint Distribution Dashboard URL for the Environment
106      *
107      * @param env
108      * @return
109      */
110     public String getBlueprintDashboardURL(String env) {
111         if(!envMap.containsKey(env)) throw new PolicyModelDistributionEnvNotFoundException(String.format("Blueprint Dashboard Environment with env %s invalid", env));
112         return envMap.get(env).getUrl();
113     }
114
115     /**
116      * Generates a Blueprint Distribution Dashboard UserName for the Environment
117      *
118      * @param env
119      * @return
120      */
121
122     public String getBlueprintDashboardUserName(String env) {
123         if(!envMap.containsKey(env)) throw new PolicyModelDistributionEnvNotFoundException(String.format("Blueprint Dashboard Environment with env %s invalid", env));
124         return envMap.get(env).getUsername();
125     }
126
127
128     /**
129      * Generates a Blueprint Distribution Dashboard Password for the Environment
130      *
131      * @param env
132      * @return
133      */
134
135     public String getBlueprintDashboardPassword(String env) {
136         if(!envMap.containsKey(env)) throw new PolicyModelDistributionEnvNotFoundException(String.format("Blueprint Dashboard Environment with env %s invalid", env));
137         return envMap.get(env).getPassword();
138     }
139
140 }