2 * Copyright 2017 ZTE Corporation.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.aai.esr.wrapper;
18 import java.util.ArrayList;
20 import javax.ws.rs.core.Response;
22 import org.onap.aai.esr.entity.aai.EsrThirdpartySdncDetail;
23 import org.onap.aai.esr.entity.aai.EsrThirdpartySdncList;
24 import org.onap.aai.esr.entity.rest.CommonRegisterResponse;
25 import org.onap.aai.esr.entity.rest.ThirdpartySdncRegisterInfo;
26 import org.onap.aai.esr.externalservice.aai.ExternalSystemProxy;
27 import org.onap.aai.esr.util.ThirdpartySdncManagerUtil;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 import com.google.gson.Gson;
33 public class ThirdpatySdncWrapper {
35 private static ThirdpatySdncWrapper thirdpatySdncWrapper;
36 private static final Logger LOG = LoggerFactory.getLogger(ThirdpatySdncWrapper.class);
39 * get ThirdpatySdncWrapper instance.
40 * @return ThirdpatySdnc manager wrapper instance
42 public static ThirdpatySdncWrapper getInstance() {
43 if (thirdpatySdncWrapper == null) {
44 thirdpatySdncWrapper = new ThirdpatySdncWrapper();
46 return thirdpatySdncWrapper;
49 public Response registerThirdpartySdnc(ThirdpartySdncRegisterInfo thirdpartySdnc) {
50 CommonRegisterResponse result = new CommonRegisterResponse();
51 EsrThirdpartySdncDetail esrSdncDetail = new EsrThirdpartySdncDetail();
52 esrSdncDetail = ThirdpartySdncManagerUtil.sdncRegisterInfo2EsrSdnc(thirdpartySdnc);
53 String sdncId = esrSdncDetail.getThirdpartySdncId();
55 ExternalSystemProxy.registerSdnc(sdncId, esrSdncDetail);
57 return Response.ok(result).build();
58 } catch (Exception e) {
60 LOG.error("Register thirdParty SDNC failed !" + e.getMessage());
61 return Response.serverError().build();
66 public Response updateThirdpartySdnc(ThirdpartySdncRegisterInfo thirdpartySdnc) {
68 return Response.ok().build();
71 public Response queryThirdpartySdncList() {
72 ArrayList<ThirdpartySdncRegisterInfo> sdncList = new ArrayList<ThirdpartySdncRegisterInfo>();
73 EsrThirdpartySdncList esrSdnc = new EsrThirdpartySdncList();
75 String esrSdncStr = ExternalSystemProxy.querySdncList();
76 esrSdnc = new Gson().fromJson(esrSdncStr, EsrThirdpartySdncList.class);
77 LOG.info("Response from AAI by query thirdparty SDNC list: " + esrSdnc);
78 sdncList = getSdncDetailList(esrSdnc);
79 return Response.ok(sdncList).build();
80 } catch (Exception e) {
82 LOG.error("Query thirdparty SDNC list failed !");
83 return Response.serverError().build();
87 public Response queryThirdpartySdncById(String thirdpartySdncId) {
88 ThirdpartySdncRegisterInfo thirdpartySdnc = new ThirdpartySdncRegisterInfo();
89 thirdpartySdnc = querySdncDetail(thirdpartySdncId);
90 if(thirdpartySdnc != null) {
91 return Response.ok(thirdpartySdnc).build();
93 return Response.serverError().build();
97 public Response delThirdpartySdnc(String thirdpartySdncId) {
99 return Response.noContent().build();
102 private ThirdpartySdncRegisterInfo querySdncDetail(String sdncId) {
103 ThirdpartySdncRegisterInfo sdncRegisterInfo = new ThirdpartySdncRegisterInfo();
104 EsrThirdpartySdncDetail esrSdncDetail = new EsrThirdpartySdncDetail();
106 String esrSdncStr = ExternalSystemProxy.queryThirdpartySdncDetail(sdncId);
107 LOG.info("Response from AAI by query thirdparty SDNC: " + esrSdncStr);
108 esrSdncDetail = new Gson().fromJson(esrSdncStr, EsrThirdpartySdncDetail.class);
109 sdncRegisterInfo = ThirdpartySdncManagerUtil.esrSdnc2SdncRegisterInfo(esrSdncDetail);
110 return sdncRegisterInfo;
111 } catch (Exception e) {
113 LOG.error("Query VNFM detail failed! thirdpaty SDNC ID: " + sdncId, e.getMessage());
118 private ArrayList<ThirdpartySdncRegisterInfo> getSdncDetailList(EsrThirdpartySdncList esrThirdPartySdnc) {
119 ArrayList<ThirdpartySdncRegisterInfo> sdncInfoList = new ArrayList<ThirdpartySdncRegisterInfo>();
120 ThirdpartySdncRegisterInfo sdncInfo = new ThirdpartySdncRegisterInfo();
121 for (int i = 0; i < esrThirdPartySdnc.getEsrThirdpartySdnc().size(); i++) {
122 String sdncId = esrThirdPartySdnc.getEsrThirdpartySdnc().get(i).getThirdpartySdncId();
123 sdncInfo = querySdncDetail(sdncId);
124 if (sdncInfo != null) {
125 sdncInfoList.add(sdncInfo);