Rename variable,fix sonar issue.
[aai/esr-server.git] / esr-mgr / src / main / java / org / onap / aai / esr / externalservice / aai / ExternalSystemProxy.java
1 /**
2  * Copyright 2017 ZTE Corporation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.aai.esr.externalservice.aai;
17
18 import org.glassfish.jersey.client.ClientConfig;
19 import org.onap.aai.esr.common.MsbConfig;
20 import org.onap.aai.esr.entity.aai.EsrEmsDetail;
21 import org.onap.aai.esr.entity.aai.EsrThirdpartySdncDetail;
22 import org.onap.aai.esr.entity.aai.EsrVnfmDetail;
23 import org.onap.aai.esr.exception.ExtsysException;
24 import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
25
26 public class ExternalSystemProxy {
27
28     private static IExternalSystem externalSystem;
29     private static String transactionId = "9999";
30     private static String fromAppId = "esr-server";
31     private static String authorization = AaiCommon.getAuthenticationCredentials();
32     static {
33         ClientConfig config = new ClientConfig();
34         externalSystem =
35                 ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
36     }
37     
38     public void registerVnfm(String vnfmId, EsrVnfmDetail esrVnfmDetail) throws ExtsysException {
39         ClientConfig config = new ClientConfig(new VnfmRegisterProvider());
40         IExternalSystem registerVnfmServiceproxy =
41                 ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
42         try {
43             registerVnfmServiceproxy.registerVNFM(transactionId, fromAppId, authorization, vnfmId, esrVnfmDetail);
44         } catch (Exception e) {
45             throw new ExtsysException("PUT VNFM to A&AI failed.", e);
46         }
47     }
48
49     public String queryVnfmDetail(String vnfmId) throws ExtsysException {
50         try {
51             return externalSystem.queryVNFMDetail(transactionId, fromAppId, authorization, vnfmId);
52         } catch (Exception e) {
53             throw new ExtsysException("Query VNFM detail from A&AI failed.", e);
54         }
55     }
56
57     public String queryVnfmList() throws ExtsysException {
58         try {
59             return externalSystem.queryVNFMList(transactionId, fromAppId, authorization);
60         } catch (Exception e) {
61             throw new ExtsysException("Query VNFM list from A&AI failed.", e);
62         }
63     }
64
65     public void deleteVnfm(String vnfmId, String resourceVersion) throws ExtsysException {
66         try {
67             externalSystem.deleteVNFM(transactionId, fromAppId, authorization, vnfmId, resourceVersion);
68         } catch (Exception e) {
69             throw new ExtsysException("Delete VNFM from A&AI failed.", e);
70         }
71     }
72
73     public void registerSdnc(String thirdpartySdncId, EsrThirdpartySdncDetail esrSdncDetail) throws ExtsysException {
74         ClientConfig config = new ClientConfig(new ThirdpartySdncRegisterProvider());
75         IExternalSystem registerSdncServiceproxy =
76                 ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
77         try {
78             registerSdncServiceproxy.registerThirdpartySdnc(transactionId, fromAppId, authorization, thirdpartySdncId,
79                     esrSdncDetail);
80         } catch (Exception e) {
81             throw new ExtsysException("PUT thirdparty SDNC to A&AI failed.", e);
82         }
83     }
84
85     public String queryThirdpartySdncDetail(String thirdpartySdncId) throws ExtsysException {
86         try {
87             return externalSystem.queryThirdpartySdncDetail(transactionId, fromAppId, authorization,
88                     thirdpartySdncId);
89         } catch (Exception e) {
90             throw new ExtsysException("Query thirdparty SDNC detail from A&AI failed.", e);
91         }
92     }
93
94     public String querySdncList() throws ExtsysException {
95         try {
96             return externalSystem.queryThirdpartySdncList(transactionId, fromAppId, authorization);
97         } catch (Exception e) {
98             throw new ExtsysException("Query thirdparty SDNC list from A&AI failed.", e);
99         }
100     }
101
102     public void deleteThirdpartySdnc(String sdncId, String resourceVersion) throws ExtsysException {
103         try {
104             externalSystem.deleteThirdpartySdnc(transactionId, fromAppId, authorization, sdncId, resourceVersion);
105         } catch (Exception e) {
106             throw new ExtsysException("Delete thirdparty SDNC from A&AI failed.", e);
107         }
108     }
109
110     public void registerEms(String emsId, EsrEmsDetail emsDetail) throws ExtsysException {
111         ClientConfig config = new ClientConfig(new EmsRegisterProvider());
112         IExternalSystem registerEmsServiceproxy =
113                 ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
114         try {
115             registerEmsServiceproxy.registerEMS(transactionId, fromAppId, authorization, emsId, emsDetail);
116         } catch (Exception e) {
117             throw new ExtsysException("PUT EMS to A&AI failed.", e);
118         }
119     }
120
121     public String queryEmsDetail(String emsId) throws ExtsysException {
122         try {
123             return externalSystem.queryEMSDetail(transactionId, fromAppId, authorization, emsId);
124         } catch (Exception e) {
125             throw new ExtsysException("Query EMS detail from A&AI failed.", e);
126         }
127     }
128
129     public String queryEmsList() throws ExtsysException {
130         try {
131             return externalSystem.queryEMSList(transactionId, fromAppId, authorization);
132         } catch (Exception e) {
133             throw new ExtsysException("Query EMS list from A&AI failed.", e);
134         }
135     }
136
137     public void deleteEms(String emsId, String resourceVersion) throws ExtsysException {
138         try {
139             externalSystem.deleteEMS(transactionId, fromAppId, authorization, emsId, resourceVersion);
140         } catch (Exception e) {
141             throw new ExtsysException("Delete EMS from A&AI failed.", e);
142         }
143     }
144 }