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.rest.CommonRegisterResponse;
24 import org.onap.aai.esr.entity.rest.ThirdpartySdncRegisterInfo;
25 import org.onap.aai.esr.externalservice.aai.ExternalSystemProxy;
26 import org.onap.aai.esr.util.ThirdpartySdncManagerUtil;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 import com.google.gson.Gson;
32 public class ThirdpatySdncWrapper {
34 private static ThirdpatySdncWrapper thirdpatySdncWrapper;
35 private static final Logger LOG = LoggerFactory.getLogger(ThirdpatySdncWrapper.class);
38 * get ThirdpatySdncWrapper instance.
39 * @return ThirdpatySdnc manager wrapper instance
41 public static ThirdpatySdncWrapper getInstance() {
42 if (thirdpatySdncWrapper == null) {
43 thirdpatySdncWrapper = new ThirdpatySdncWrapper();
45 return thirdpatySdncWrapper;
48 public Response registerThirdpartySdnc(ThirdpartySdncRegisterInfo thirdpartySdnc) {
49 CommonRegisterResponse result = new CommonRegisterResponse();
50 EsrThirdpartySdncDetail esrSdncDetail = new EsrThirdpartySdncDetail();
51 esrSdncDetail = ThirdpartySdncManagerUtil.sdncRegisterInfo2EsrSdnc(thirdpartySdnc);
52 String sdncId = esrSdncDetail.getThirdpartySdncId();
54 ExternalSystemProxy.registerSdnc(sdncId, esrSdncDetail);
56 return Response.ok(result).build();
57 } catch (Exception e) {
59 LOG.error("Register thirdParty SDNC failed !" + e.getMessage());
60 return Response.serverError().build();
65 public Response updateThirdpartySdnc(ThirdpartySdncRegisterInfo thirdpartySdnc) {
67 return Response.ok().build();
70 public Response queryThirdpartySdncList() {
72 ArrayList<ThirdpartySdncRegisterInfo> thirdpartySdncList = new ArrayList<ThirdpartySdncRegisterInfo>();
73 return Response.ok(thirdpartySdncList).build();
76 public Response queryThirdpartySdncById(String thirdpartySdncId) {
77 ThirdpartySdncRegisterInfo thirdpartySdnc = new ThirdpartySdncRegisterInfo();
78 thirdpartySdnc = querySdncDetail(thirdpartySdncId);
79 if(thirdpartySdnc != null) {
80 return Response.ok(thirdpartySdnc).build();
82 return Response.serverError().build();
86 public Response delThirdpartySdnc(String thirdpartySdncId) {
88 return Response.noContent().build();
91 private ThirdpartySdncRegisterInfo querySdncDetail(String sdncId) {
92 ThirdpartySdncRegisterInfo sdncRegisterInfo = new ThirdpartySdncRegisterInfo();
93 EsrThirdpartySdncDetail esrSdncDetail = new EsrThirdpartySdncDetail();
95 String esrSdncStr = ExternalSystemProxy.queryThirdpartySdncDetail(sdncId);
96 LOG.info("Response from AAI by query thirdparty SDNC: " + esrSdncStr);
97 esrSdncDetail = new Gson().fromJson(esrSdncStr, EsrThirdpartySdncDetail.class);
98 sdncRegisterInfo = ThirdpartySdncManagerUtil.esrSdnc2SdncRegisterInfo(esrSdncDetail);
99 return sdncRegisterInfo;
100 } catch (Exception e) {
102 LOG.error("Query VNFM detail failed! thirdpaty SDNC ID: " + sdncId, e.getMessage());