Fix the bug about query VIM.
[aai/esr-server.git] / esr-mgr / src / main / java / org / onap / aai / esr / util / VimManagerUtil.java
index de10ac1..2a390d9 100644 (file)
@@ -18,7 +18,6 @@ package org.onap.aai.esr.util;
 
 import java.util.ArrayList;
 
-import org.onap.aai.esr.common.SystemStatus;
 import org.onap.aai.esr.common.SystemType;
 import org.onap.aai.esr.entity.aai.EsrSystemInfo;
 import org.onap.aai.esr.entity.aai.CloudRegionDetail;
@@ -26,10 +25,10 @@ import org.onap.aai.esr.entity.aai.EsrSystemInfoList;
 import org.onap.aai.esr.entity.rest.VimAuthInfo;
 import org.onap.aai.esr.entity.rest.VimRegisterInfo;
 
-
 public class VimManagerUtil {
+  private static ExtsysUtil extsysUtil = new ExtsysUtil();
   
-  public static CloudRegionDetail vimRegisterInfo2CloudRegion(VimRegisterInfo vimRegisterInfo) {
+  public CloudRegionDetail vimRegisterInfo2CloudRegion(VimRegisterInfo vimRegisterInfo) {
     CloudRegionDetail cloudRegion = new CloudRegionDetail();
     EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList();
     EsrSystemInfo esrSystemInfoObj = new EsrSystemInfo();
@@ -44,12 +43,13 @@ public class VimManagerUtil {
     cloudRegion.setCloudExtraInfo(vimRegisterInfo.getCloudExtraInfo());
     
     esrSystemInfoObj = vimAuthInfo2EsrSystemInfoObj(vimRegisterInfo.getVimAuthInfos());
-    esrSystemInfoList = ExtsysUtil.getEsrSystemInfoListFromAuthInfo(esrSystemInfoObj);
+    esrSystemInfoObj.setSystemStatus(vimRegisterInfo.getStatus());
+    esrSystemInfoList = extsysUtil.getEsrSystemInfoListFromAuthInfo(esrSystemInfoObj);
     cloudRegion.setEsrSystemInfoList(esrSystemInfoList);
     return cloudRegion;
   }
 
-  private static EsrSystemInfo vimAuthInfo2EsrSystemInfoObj(ArrayList<VimAuthInfo> vimAuthInfos) {
+  private EsrSystemInfo vimAuthInfo2EsrSystemInfoObj(ArrayList<VimAuthInfo> vimAuthInfos) {
     EsrSystemInfo esrSystemInfoObj = new EsrSystemInfo();
     VimAuthInfo vimAuthInfo = new VimAuthInfo();
     vimAuthInfo = vimAuthInfos.get(0);
@@ -59,13 +59,13 @@ public class VimManagerUtil {
     esrSystemInfoObj.setServiceUrl(vimAuthInfo.getAuthUrl());
     esrSystemInfoObj.setSslCassert(vimAuthInfo.getSslCacert());
     esrSystemInfoObj.setSslInsecure(vimAuthInfo.getSslInsecure());
-    esrSystemInfoObj.setEsrSystemInfoId(ExtsysUtil.generateId());
+    esrSystemInfoObj.setEsrSystemInfoId(extsysUtil.generateId());
     esrSystemInfoObj.setSystemType(SystemType.VIM.toString());
-    esrSystemInfoObj.setSystemStatus(SystemStatus.normal.toString());
+//    esrSystemInfoObj.setSystemStatus(SystemStatus.normal.toString());
     return esrSystemInfoObj;
   }
   
-  private static VimAuthInfo authInfo2VimAuthInfo(EsrSystemInfo authInfo) {
+  private VimAuthInfo authInfo2VimAuthInfo(EsrSystemInfo authInfo) {
     VimAuthInfo vimAuthInfo = new VimAuthInfo();
     vimAuthInfo.setAuthUrl(authInfo.getServiceUrl());
     vimAuthInfo.setCloudDomain(authInfo.getCloudDomain());
@@ -76,11 +76,14 @@ public class VimManagerUtil {
     return vimAuthInfo;
   }
   
-  public static VimRegisterInfo cloudRegion2VimRegisterInfo(CloudRegionDetail cloudRegion) {
+  public VimRegisterInfo cloudRegion2VimRegisterInfo(CloudRegionDetail cloudRegion) {
     VimRegisterInfo vimRegisterInfo = new VimRegisterInfo();
     VimAuthInfo vimAuthInfo = new VimAuthInfo();
     ArrayList<VimAuthInfo> vimAuthInfos = new ArrayList<VimAuthInfo>();
-    vimAuthInfo = authInfo2VimAuthInfo(cloudRegion.getEsrSystemInfoList().getEsrSystemInfo().get(0));
+    if(cloudRegion.getEsrSystemInfoList()!=null){
+      vimAuthInfo = authInfo2VimAuthInfo(cloudRegion.getEsrSystemInfoList().getEsrSystemInfo().get(0));
+      vimRegisterInfo.setStatus(cloudRegion.getEsrSystemInfoList().getEsrSystemInfo().get(0).getSystemStatus());
+    }
     vimAuthInfos.add(vimAuthInfo);
     vimRegisterInfo.setVimAuthInfos(vimAuthInfos);
     vimRegisterInfo.setCloudExtraInfo(cloudRegion.getCloudExtraInfo());