Realize the data transformation of VNFM.
[aai/esr-server.git] / esr-mgr / src / main / java / org / onap / aai / esr / util / VimManagerUtil.java
1 /**
2  * Copyright 2017 ZTE Corporation.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.aai.esr.util;
17
18 import java.util.ArrayList;
19
20 import org.onap.aai.esr.common.SystemStatus;
21 import org.onap.aai.esr.common.SystemType;
22 import org.onap.aai.esr.entity.aai.AuthInfo;
23 import org.onap.aai.esr.entity.aai.CloudRegion;
24 import org.onap.aai.esr.entity.aai.EsrSystemInfoList;
25 import org.onap.aai.esr.entity.rest.VimAuthInfo;
26 import org.onap.aai.esr.entity.rest.VimRegisterInfo;
27
28
29 public class VimManagerUtil {
30   
31   public static CloudRegion vimRegisterInfo2CloudRegion(VimRegisterInfo vimRegisterInfo) {
32     CloudRegion cloudRegion = new CloudRegion();
33     EsrSystemInfoList esrSystemInfo = new EsrSystemInfoList();
34     AuthInfo authInfo = new AuthInfo();
35     
36     cloudRegion.setCloudOwner(vimRegisterInfo.getCloudOwner());
37     cloudRegion.setCloudRegionId(vimRegisterInfo.getCloudRegionId());
38     cloudRegion.setCloudType(vimRegisterInfo.getCloudType());
39     cloudRegion.setCloudRegionVersion(vimRegisterInfo.getCloudRegionVersion());
40     cloudRegion.setCloudZone(vimRegisterInfo.getCloudZone());
41     cloudRegion.setComplexName(vimRegisterInfo.getComplexName());
42     cloudRegion.setOwnerDefinedType(vimRegisterInfo.getOwnerDefinedType());
43     cloudRegion.setCloudExtraInfo(vimRegisterInfo.getCloudExtraInfo());
44     
45     authInfo = vimAuthInfo2AuthInfo(vimRegisterInfo.getVimAuthInfo());
46     esrSystemInfo = ExtsysUtil.getEsrSystemInfoListFromAuthInfo(authInfo);
47     cloudRegion.setEsrSystemInfoList(esrSystemInfo);
48     return cloudRegion;
49   }
50
51   private static AuthInfo vimAuthInfo2AuthInfo(VimAuthInfo vimAuthInfo) {
52     AuthInfo authInfo = new AuthInfo();
53     authInfo.setCloudDomain(vimAuthInfo.getCloudDomain());
54     authInfo.setUserName(vimAuthInfo.getUserName());
55     authInfo.setPassword(vimAuthInfo.getPassword());
56     authInfo.setServiceUrl(vimAuthInfo.getAuthUrl());
57     authInfo.setSslCassert(vimAuthInfo.getSslCacert());
58     authInfo.setSslInsecure(vimAuthInfo.getSslInsecure());
59     authInfo.setEsrSystemInfoId(ExtsysUtil.generateId());
60     authInfo.setSystemType(SystemType.VIM.toString());
61     authInfo.setSystemStatus(SystemStatus.normal.toString());
62     return authInfo;
63   }
64   
65   private static VimAuthInfo authInfo2VimAuthInfo(AuthInfo authInfo) {
66     VimAuthInfo vimAuthInfo = new VimAuthInfo();
67     vimAuthInfo.setAuthUrl(authInfo.getServiceUrl());
68     vimAuthInfo.setCloudDomain(authInfo.getCloudDomain());
69     vimAuthInfo.setPassword(authInfo.getPassword());
70     vimAuthInfo.setSslCacert(authInfo.getSslCassert());
71     vimAuthInfo.setSslInsecure(authInfo.getSslInsecure());
72     vimAuthInfo.setUserName(authInfo.getUserName());
73     return vimAuthInfo;
74   }
75   
76   public static VimRegisterInfo cloudRegion2VimRegisterInfo(CloudRegion cloudRegion) {
77     VimRegisterInfo vimRegisterInfo = new VimRegisterInfo();
78     VimAuthInfo vimAuthInfo = new VimAuthInfo();
79     vimAuthInfo = authInfo2VimAuthInfo(cloudRegion.getEsrSystemInfoList().getEsrSystemInfo().getEsrSystemInfo().get(0));
80     vimRegisterInfo.setVimAuthInfo(vimAuthInfo);
81     vimRegisterInfo.setCloudExtraInfo(cloudRegion.getCloudExtraInfo());
82     vimRegisterInfo.setCloudOwner(cloudRegion.getCloudOwner());
83     vimRegisterInfo.setCloudRegionId(cloudRegion.getCloudRegionId());
84     vimRegisterInfo.setCloudType(cloudRegion.getCloudType());
85     vimRegisterInfo.setCloudZone(cloudRegion.getCloudZone());
86     vimRegisterInfo.setComplexName(cloudRegion.getComplexName());
87     vimRegisterInfo.setOwnerDefinedType(cloudRegion.getOwnerDefinedType());
88     return vimRegisterInfo;
89   }
90 }