From: lizi00164331 
Date: Tue, 12 Sep 2017 08:30:44 +0000 (+0800)
Subject: Add the EMS data transformation function.
X-Git-Tag: v1.0.0~77
X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=bb02e67db383ee68af8179c350e07a6c1ddffca9;p=aai%2Fesr-server.git
Add the EMS data transformation function.
Change-Id: I2d48645da9eaf5aeff4142e56d61ccc70bcce04c
Issue-ID: AAI-287
Signed-off-by: lizi00164331 
---
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/AuthInfo.java b/esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/AuthInfo.java
index 56d76cb..1fbca12 100644
--- a/esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/AuthInfo.java
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/AuthInfo.java
@@ -49,6 +49,10 @@ public class AuthInfo {
   
   private String defaultTenant;
   
+  private Boolean passive;
+  
+  private String remotePath;
+  
   private String systemStatus;
   
   private String resouceVersion;
@@ -197,4 +201,20 @@ public class AuthInfo {
     this.resouceVersion = resouceVersion;
   }
 
+  public Boolean getPassive() {
+    return passive;
+  }
+
+  public void setPassive(Boolean passive) {
+    this.passive = passive;
+  }
+
+  public String getRemotePath() {
+    return remotePath;
+  }
+
+  public void setRemotePath(String remotePath) {
+    this.remotePath = remotePath;
+  }
+  
 }
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
index 3bff6a0..e8c402e 100644
--- 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
@@ -20,10 +20,6 @@ public class EsrEms {
 
   private String emsId;
   
-  private Boolean passive;
-  
-  private String remotePath;
-  
   private String resouceVersion;
   
   private EsrSystemInfoList esrSystemInfoList;
@@ -36,22 +32,6 @@ public class EsrEms {
     this.emsId = emsId;
   }
 
-  public Boolean getPassive() {
-    return passive;
-  }
-
-  public void setPassive(Boolean passive) {
-    this.passive = passive;
-  }
-
-  public String getRemotePath() {
-    return remotePath;
-  }
-
-  public void setRemotePath(String remotePath) {
-    this.remotePath = remotePath;
-  }
-
   public EsrSystemInfoList getEsrSystemInfoList() {
     return esrSystemInfoList;
   }
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/entity/rest/FtpAddr.java b/esr-mgr/src/main/java/org/onap/aai/esr/entity/rest/FtpAddr.java
index fe60469..598d6ed 100644
--- a/esr-mgr/src/main/java/org/onap/aai/esr/entity/rest/FtpAddr.java
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/entity/rest/FtpAddr.java
@@ -29,7 +29,7 @@ public class FtpAddr {
   
   private String remotepath;
   
-  private String passive;
+  private Boolean passive;
 
   public String getFtptype() {
     return ftptype;
@@ -79,11 +79,11 @@ public class FtpAddr {
     this.remotepath = remotepath;
   }
 
-  public String getPassive() {
+  public Boolean getPassive() {
     return passive;
   }
 
-  public void setPassive(String passive) {
+  public void setPassive(Boolean passive) {
     this.passive = passive;
   }
 }
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/util/EmsManagerUtil.java b/esr-mgr/src/main/java/org/onap/aai/esr/util/EmsManagerUtil.java
new file mode 100644
index 0000000..decd2da
--- /dev/null
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/util/EmsManagerUtil.java
@@ -0,0 +1,139 @@
+/**
+ * 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.util;
+
+import java.util.ArrayList;
+
+import org.onap.aai.esr.common.SystemType;
+import org.onap.aai.esr.entity.aai.AuthInfo;
+import org.onap.aai.esr.entity.aai.EsrEms;
+import org.onap.aai.esr.entity.rest.AlarmAddr;
+import org.onap.aai.esr.entity.rest.EmsRegisterInfo;
+import org.onap.aai.esr.entity.rest.FtpAddr;
+
+public class EmsManagerUtil {
+  
+  public static EsrEms emsRegisterInfo2EsrEms(EmsRegisterInfo emsRegisterInfo) {
+    EsrEms esrEms = new EsrEms();
+    esrEms.setEmsId(ExtsysUtil.generateId());
+    ArrayList authInfos = new ArrayList();
+    authInfos = getAuthInfosFromRegisterData(emsRegisterInfo);
+    esrEms.setEsrSystemInfoList(ExtsysUtil.getEsrSystemInfoListFromAuthInfoList(authInfos));
+    return esrEms;
+  }
+
+  private static ArrayList getAuthInfosFromRegisterData(EmsRegisterInfo emsRegisterInfo) {
+    ArrayList authInfos = new ArrayList();
+    AuthInfo resouceAuthInfo = new AuthInfo();
+    AuthInfo performanceAuthInfo = new AuthInfo();
+    AuthInfo alarmAuthInfo = new AuthInfo();
+    resouceAuthInfo = getAuthInfoFromFtpAddr(emsRegisterInfo, SystemType.EMS_RESOUCE.toString());
+    performanceAuthInfo = getAuthInfoFromFtpAddr(emsRegisterInfo, SystemType.EMS_PERFORMANCE.toString());
+    alarmAuthInfo = getAuthInfoFromAlarmAddr(emsRegisterInfo);
+    authInfos.add(resouceAuthInfo);
+    authInfos.add(performanceAuthInfo);
+    authInfos.add(alarmAuthInfo);
+    return authInfos;
+  }
+  
+  private static AuthInfo getAuthInfoFromFtpAddr(EmsRegisterInfo emsRegisterInfo, String systemType) {
+    AuthInfo authInfo = new AuthInfo();
+    FtpAddr ftpAddr = new FtpAddr();
+    if(systemType.equals(SystemType.EMS_RESOUCE.toString())) {
+      ftpAddr = emsRegisterInfo.getResourceAddr();
+    } else if(systemType.equals(SystemType.EMS_PERFORMANCE.toString())) {
+      ftpAddr = emsRegisterInfo.getPerformanceAddr();
+    }
+    authInfo.setType(ftpAddr.getFtptype());
+    authInfo.setIpAddress(ftpAddr.getIp());
+    authInfo.setPort(ftpAddr.getPort());
+    authInfo.setUserName(ftpAddr.getUser());
+    authInfo.setPassword(ftpAddr.getPassword());
+    authInfo.setRemotePath(ftpAddr.getRemotepath());
+    authInfo.setPassive(ftpAddr.getPassive());
+    authInfo.setEsrSystemInfoId(ExtsysUtil.generateId());
+    authInfo.setSystemType(systemType);
+    authInfo.setSystemName(emsRegisterInfo.getName());
+    authInfo.setVendor(emsRegisterInfo.getVendor());
+    authInfo.setVersion(emsRegisterInfo.getVersion());
+    return authInfo;
+  }
+  
+  private static AuthInfo getAuthInfoFromAlarmAddr(EmsRegisterInfo emsRegisterInfo) {
+    AuthInfo authInfo = new AuthInfo();
+    AlarmAddr alarmAddr = new AlarmAddr();
+    alarmAddr = emsRegisterInfo.getAlarmAddr();
+    authInfo.setIpAddress(alarmAddr.getIp());
+    authInfo.setPort(alarmAddr.getPort());
+    authInfo.setUserName(alarmAddr.getUser());
+    authInfo.setPassword(alarmAddr.getPassword());
+    authInfo.setSystemType(SystemType.EMS_ALARM.toString());
+    authInfo.setSystemName(emsRegisterInfo.getName());
+    authInfo.setVendor(emsRegisterInfo.getVendor());
+    authInfo.setVersion(emsRegisterInfo.getVersion());
+    return authInfo;
+  }
+  
+  public static EmsRegisterInfo EsrEms2EmsRegisterInfo(EsrEms esrEms) {
+    EmsRegisterInfo emsRegisterInfo = new EmsRegisterInfo();
+    ArrayList authInfos = new ArrayList();
+    AuthInfo authInfo = new AuthInfo();
+    authInfos = esrEms.getEsrSystemInfoList().getEsrSystemInfo().getEsrSystemInfo();
+    emsRegisterInfo.setEmsId(esrEms.getEmsId());
+    
+    for(int i=0; i authInfos = new ArrayList();
@@ -66,4 +66,12 @@ public class ExtsysUtil {
     esrSystemInfoList.setEsrSystemInfo(esrSystemInfo);
     return esrSystemInfoList;
   }
+  
+  public static EsrSystemInfoList getEsrSystemInfoListFromAuthInfoList(ArrayList authInfos) {
+    EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList();
+    EsrSystemInfo esrSystemInfo = new EsrSystemInfo();
+    esrSystemInfo.setEsrSystemInfo(authInfos);
+    esrSystemInfoList.setEsrSystemInfo(esrSystemInfo);
+    return esrSystemInfoList;
+  }
 }
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/util/VimManagerUtil.java b/esr-mgr/src/main/java/org/onap/aai/esr/util/VimManagerUtil.java
index caad565..54720ce 100644
--- a/esr-mgr/src/main/java/org/onap/aai/esr/util/VimManagerUtil.java
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/util/VimManagerUtil.java
@@ -44,7 +44,7 @@ public class VimManagerUtil {
     cloudRegion.setCloudExtraInfo(vimRegisterInfo.getCloudExtraInfo());
     
     authInfo = vimAuthInfo2AuthInfo(vimRegisterInfo.getVimAuthInfo());
-    esrSystemInfo = ExtsysUtil.getEsrSystemInfoList(authInfo);
+    esrSystemInfo = ExtsysUtil.getEsrSystemInfoListFromAuthInfo(authInfo);
     cloudRegion.setEsrSystemInfoList(esrSystemInfo);
     return cloudRegion;
   }