Realize the query EMS list API. 71/13071/1
authorlizi00164331 <li.zi30@zte.com.cn>
Mon, 18 Sep 2017 09:38:07 +0000 (17:38 +0800)
committerlizi00164331 <li.zi30@zte.com.cn>
Mon, 18 Sep 2017 09:38:07 +0000 (17:38 +0800)
Change-Id: I151c71919245d6af21b9ad63a153ef2331860b98
Issue-ID: AAI-322
Signed-off-by: lizi00164331 <li.zi30@zte.com.cn>
esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/EsrEms.java [new file with mode: 0644]
esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/EsrEmsList.java [new file with mode: 0644]
esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/EsrVnfm.java
esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/ExternalSystemProxy.java
esr-mgr/src/main/java/org/onap/aai/esr/wrapper/EmsManagerWrapper.java
esr-mgr/src/main/java/org/onap/aai/esr/wrapper/VnfmManagerWrapper.java

diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/EsrEms.java b/esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/EsrEms.java
new file mode 100644 (file)
index 0000000..d50af6b
--- /dev/null
@@ -0,0 +1,47 @@
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.aai.esr.entity.aai;
+
+import java.io.Serializable;
+
+import com.google.gson.annotations.SerializedName;
+
+public class EsrEms implements Serializable {
+  
+public static final long serialVersionUID = 1L;
+  
+  @SerializedName("ems-id")
+  private String emsId;
+  
+  @SerializedName("resource-version")
+  private String resourceVersion;
+
+  public String getEmsId() {
+    return emsId;
+  }
+
+  public void setEmsId(String emsId) {
+    this.emsId = emsId;
+  }
+
+  public String getResourceVersion() {
+    return resourceVersion;
+  }
+
+  public void setResourceVersion(String resourceVersion) {
+    this.resourceVersion = resourceVersion;
+  }
+}
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/EsrEmsList.java b/esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/EsrEmsList.java
new file mode 100644 (file)
index 0000000..e14da46
--- /dev/null
@@ -0,0 +1,37 @@
+/**
+ * Copyright 2017 ZTE Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.aai.esr.entity.aai;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+
+import com.google.gson.annotations.SerializedName;
+
+public class EsrEmsList implements Serializable {
+
+  public static final long serialVersionUID = 1L;
+  
+  @SerializedName("esr-ems")
+  private ArrayList<EsrEms> esrEms;
+
+  public ArrayList<EsrEms> getEsrEms() {
+    return esrEms;
+  }
+
+  public void setEsrEms(ArrayList<EsrEms> esrEms) {
+    this.esrEms = esrEms;
+  }
+}
index f0b8bb8..73fbc8c 100644 (file)
@@ -19,7 +19,7 @@ import java.io.Serializable;
 
 import com.google.gson.annotations.SerializedName;
 
-public class EsrVnfm  implements Serializable {
+public class EsrVnfm implements Serializable {
 
   public static final long serialVersionUID = 1L;
   
index bc7b58e..e2ebfef 100644 (file)
@@ -86,4 +86,8 @@ public class ExternalSystemProxy {
   public static String queryEmsDetail(String emsId) throws Exception {
     return externalSystemproxy.queryEMSDetail(transactionId, fromAppId, authorization, emsId);
   }
+  
+  public static String queryEmsList() throws Exception {
+    return externalSystemproxy.queryEMSList(transactionId, fromAppId, authorization);
+  }
 }
index ac85b0a..9d13165 100644 (file)
@@ -23,6 +23,7 @@ import org.onap.aai.esr.entity.rest.EmsRegisterInfo;
 import org.onap.aai.esr.externalservice.aai.ExternalSystemProxy;
 import org.onap.aai.esr.util.EmsManagerUtil;
 import org.onap.aai.esr.entity.aai.EsrEmsDetail;
+import org.onap.aai.esr.entity.aai.EsrEmsList;
 import org.onap.aai.esr.entity.rest.CommonRegisterResponse;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -66,9 +67,19 @@ public class EmsManagerWrapper {
   }
   
   public Response queryEmsList() {
-    //TODO
     ArrayList<EmsRegisterInfo> emsList = new ArrayList<EmsRegisterInfo>();
-    return Response.ok(emsList).build();
+    EsrEmsList esrEms = new EsrEmsList();
+    try {
+      String esrEmsStr = ExternalSystemProxy.queryEmsList();
+      esrEms = new Gson().fromJson(esrEmsStr, EsrEmsList.class);
+      LOG.info("Response from AAI by query EMS list: " + esrEms);
+      emsList = getEmsDetailList(esrEms);
+      return Response.ok(emsList).build();
+    } catch (Exception e) {
+      e.printStackTrace();
+      LOG.error("Query EMS list failed !");
+      return Response.serverError().build();
+    }
   }
   
   public Response queryEmsById(String emsId) {
@@ -97,8 +108,21 @@ public class EmsManagerWrapper {
       return emsRegisterInfo;
     } catch (Exception e) {
       e.printStackTrace();
-      LOG.error("Query VNFM detail failed! EMS ID: " + emsId, e.getMessage());
+      LOG.error("Query EMS detail failed! EMS ID: " + emsId, e.getMessage());
       return null;
     }
   }
+  
+  private ArrayList<EmsRegisterInfo> getEmsDetailList(EsrEmsList esrEms) {
+    ArrayList<EmsRegisterInfo> emsInfoList = new ArrayList<EmsRegisterInfo>();
+    EmsRegisterInfo emsInfo = new EmsRegisterInfo();
+    for (int i = 0; i < esrEms.getEsrEms().size(); i++) {
+      String emsId = esrEms.getEsrEms().get(i).getEmsId();
+      emsInfo = queryEmsDetail(emsId);
+      if (emsInfo != null) {
+        emsInfoList.add(emsInfo);
+      }
+    }
+    return emsInfoList;
+  }
 }
index d75760c..d1b3b77 100644 (file)
@@ -103,7 +103,6 @@ public class VnfmManagerWrapper {
       LOG.error("Query VNFM list failed !");
       return Response.serverError().build();
     }
-
   }
 
   public Response queryVnfmById(String vnfmId) {