Change the usage of Exception in external system.
[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
25 import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
26
27 public class ExternalSystemProxy {
28
29   private static IExternalSystem externalSystemproxy;
30
31   private static String transactionId = "9999";
32   private static String fromAppId = "esr-server";
33   private static String authorization = AaiCommon.getAuthenticationCredentials();
34   static {
35     ClientConfig config = new ClientConfig();
36     externalSystemproxy = ConsumerFactory.createConsumer(MsbConfig.getExternalSystemAddr(),
37         config, IExternalSystem.class);
38   }
39
40   public static void registerVnfm(String vnfmId, EsrVnfmDetail esrVnfmDetail) throws ExtsysException {
41     ClientConfig config = new ClientConfig(new VnfmRegisterProvider());
42     IExternalSystem registerVnfmServiceproxy = ConsumerFactory
43         .createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
44     try {
45       registerVnfmServiceproxy.registerVNFM(transactionId, fromAppId, authorization, vnfmId,
46           esrVnfmDetail);
47     } catch (Exception e) {
48       throw new ExtsysException("PUT VNFM to A&AI failed.", e);
49     }
50   }
51   
52   public static String queryVnfmDetail(String vnfmId) throws ExtsysException {
53     try {
54       return externalSystemproxy.queryVNFMDetail(transactionId, fromAppId, authorization, vnfmId);
55     } catch (Exception e) {
56       throw new ExtsysException("Query VNFM detail from A&AI failed.", e);
57     }
58   }
59   
60   public static String queryVnfmList() throws ExtsysException {
61     try {
62       return externalSystemproxy.queryVNFMList(transactionId, fromAppId, authorization);
63     } catch (Exception e) {
64       throw new ExtsysException("Query VNFM list from A&AI failed.", e);
65     }
66   }
67   
68   public static void deleteVnfm(String vnfmId, String resourceVersion) throws ExtsysException {
69     try {
70       externalSystemproxy.deleteVNFM(transactionId, fromAppId, authorization, vnfmId, resourceVersion);
71     } catch (Exception e) {
72       throw new ExtsysException("Delete VNFM from A&AI failed.", e);
73     }
74   }
75   
76   public static void registerSdnc(String thirdpartySdncId, EsrThirdpartySdncDetail esrSdncDetail) throws ExtsysException {
77     ClientConfig config = new ClientConfig(new ThirdpartySdncRegisterProvider());
78     IExternalSystem registerSdncServiceproxy = ConsumerFactory
79         .createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
80     try {
81       registerSdncServiceproxy.registerThirdpartySdnc(transactionId, fromAppId, authorization, thirdpartySdncId,
82           esrSdncDetail);
83     } catch (Exception e) {
84       throw new ExtsysException("PUT thirdparty SDNC to A&AI failed.", e);
85     }
86   }
87   
88   public static String queryThirdpartySdncDetail(String thirdpartySdncId) throws ExtsysException {
89     try {
90       return externalSystemproxy.queryThirdpartySdncDetail(transactionId, fromAppId, authorization, thirdpartySdncId);
91     } catch (Exception e) {
92       throw new ExtsysException("Query thirdparty SDNC detail from A&AI failed.", e);
93     }
94   }
95   
96   public static String querySdncList() throws ExtsysException {
97     try {
98       return externalSystemproxy.queryThirdpartySdncList(transactionId, fromAppId, authorization);
99     } catch (Exception e) {
100       throw new ExtsysException("Query thirdparty SDNC list from A&AI failed.", e);
101     }
102   }
103   
104   public static void deleteThirdpartySdnc(String sdncId, String resourceVersion) throws ExtsysException {
105     try {
106       externalSystemproxy.deleteThirdpartySdnc(transactionId, fromAppId, authorization, sdncId, resourceVersion);
107     } catch (Exception e) {
108       throw new ExtsysException("Delete thirdparty SDNC from A&AI failed.", e);
109     }
110   }
111   
112   public static void registerEms(String emsId, EsrEmsDetail emsDetail) throws ExtsysException {
113     ClientConfig config = new ClientConfig(new EmsRegisterProvider());
114     IExternalSystem registerEmsServiceproxy = ConsumerFactory
115         .createConsumer(MsbConfig.getExternalSystemAddr(), config, IExternalSystem.class);
116     try {
117       registerEmsServiceproxy.registerEMS(transactionId, fromAppId, authorization, emsId,
118           emsDetail);
119     } catch (Exception e) {
120       throw new ExtsysException("PUT EMS to A&AI failed.", e);
121     }
122   }
123   
124   public static String queryEmsDetail(String emsId) throws ExtsysException {
125     try {
126       return externalSystemproxy.queryEMSDetail(transactionId, fromAppId, authorization, emsId);
127     } catch (Exception e) {
128       throw new ExtsysException("Query EMS detail from A&AI failed.", e);
129     }
130   }
131   
132   public static String queryEmsList() throws ExtsysException {
133     try {
134       return externalSystemproxy.queryEMSList(transactionId, fromAppId, authorization);
135     } catch (Exception e) {
136       throw new ExtsysException("Query EMS list from A&AI failed.", e);
137     }
138   }
139   
140   public static void deleteEms(String emsId, String resourceVersion) throws ExtsysException {
141     try {
142       externalSystemproxy.deleteEMS(transactionId, fromAppId, authorization, emsId, resourceVersion);
143     } catch (Exception e) {
144       throw new ExtsysException("Delete EMS from A&AI failed.", e);
145     }
146   }
147 }