Change the static method in util.
[aai/esr-server.git] / esr-mgr / src / main / java / org / onap / aai / esr / wrapper / ThirdpatySdncWrapper.java
index e5f9966..0dfd45a 100644 (file)
@@ -37,6 +37,7 @@ public class ThirdpatySdncWrapper {
 
   private static ThirdpatySdncWrapper thirdpatySdncWrapper;
   private static final Logger LOG = LoggerFactory.getLogger(ThirdpatySdncWrapper.class);
+  private static ThirdpartySdncManagerUtil thirdpartySdncManagerUtil = new ThirdpartySdncManagerUtil();
 
   /**
    * get ThirdpatySdncWrapper instance.
@@ -52,7 +53,7 @@ public class ThirdpatySdncWrapper {
   public Response registerThirdpartySdnc(ThirdpartySdncRegisterInfo thirdpartySdnc) {
     CommonRegisterResponse result = new CommonRegisterResponse();
     EsrThirdpartySdncDetail esrSdncDetail = new EsrThirdpartySdncDetail();
-    esrSdncDetail = ThirdpartySdncManagerUtil.sdncRegisterInfo2EsrSdnc(thirdpartySdnc);
+    esrSdncDetail = thirdpartySdncManagerUtil.sdncRegisterInfo2EsrSdnc(thirdpartySdnc);
     String sdncId = esrSdncDetail.getThirdpartySdncId();
     try {
       ExternalSystemProxy.registerSdnc(sdncId, esrSdncDetail);
@@ -72,7 +73,7 @@ public class ThirdpatySdncWrapper {
     EsrThirdpartySdncDetail originalEsrSdncDetail = new EsrThirdpartySdncDetail();
     EsrSystemInfo originalEsrSystemInfo = new EsrSystemInfo();
     originalEsrSdncDetail = queryEsrThirdpartySdncDetail(sdncId);
-    esrSdncDetail = ThirdpartySdncManagerUtil.sdncRegisterInfo2EsrSdnc(thirdpartySdnc);
+    esrSdncDetail = thirdpartySdncManagerUtil.sdncRegisterInfo2EsrSdnc(thirdpartySdnc);
     String resourceVersion = originalEsrSdncDetail.getResourceVersion();
     esrSdncDetail.setResourceVersion(resourceVersion);
     esrSdncDetail.setThirdpartySdncId(sdncId);
@@ -119,8 +120,23 @@ public class ThirdpatySdncWrapper {
   }
   
   public Response delThirdpartySdnc(String thirdpartySdncId) {
-    //TODO
-    return Response.noContent().build();
+    EsrThirdpartySdncDetail thirdpartySdncDetail = new EsrThirdpartySdncDetail();
+    thirdpartySdncDetail = queryEsrThirdpartySdncDetail(thirdpartySdncId);
+    String resourceVersion = thirdpartySdncDetail.getResourceVersion();
+    if (resourceVersion != null) {
+      try {
+        ExternalSystemProxy.deleteThirdpartySdnc(thirdpartySdncId, resourceVersion);
+        return Response.ok().build();
+      } catch (Exception e) {
+        e.printStackTrace();
+        LOG.error("Delete VNFM from A&AI failed! thirdparty SDNC ID: " + thirdpartySdncId + "resouce-version:"
+            + resourceVersion, e.getMessage());
+        return Response.noContent().build();
+      }
+    } else {
+      LOG.error("resouce-version is null ! Can not delete resouce from A&AI. ");
+      return Response.serverError().build();
+    }
   }
   
   private ThirdpartySdncRegisterInfo querySdncDetail(String sdncId) {
@@ -130,7 +146,7 @@ public class ThirdpatySdncWrapper {
       String esrSdncStr = ExternalSystemProxy.queryThirdpartySdncDetail(sdncId);
       LOG.info("Response from AAI by query thirdparty SDNC: " + esrSdncStr);
       esrSdncDetail = new Gson().fromJson(esrSdncStr, EsrThirdpartySdncDetail.class);
-      sdncRegisterInfo = ThirdpartySdncManagerUtil.esrSdnc2SdncRegisterInfo(esrSdncDetail);
+      sdncRegisterInfo = thirdpartySdncManagerUtil.esrSdnc2SdncRegisterInfo(esrSdncDetail);
       return sdncRegisterInfo;
     } catch (Exception e) {
       e.printStackTrace();