Add unit test for app Configuration.
[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
19 import java.util.ArrayList;
20
21 import org.onap.aai.esr.common.SystemType;
22 import org.onap.aai.esr.entity.aai.EsrSystemInfo;
23 import org.onap.aai.esr.entity.aai.CloudRegionDetail;
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   private static ExtsysUtil extsysUtil = new ExtsysUtil();
31   
32   public CloudRegionDetail vimRegisterInfo2CloudRegion(VimRegisterInfo vimRegisterInfo) {
33     CloudRegionDetail cloudRegion = new CloudRegionDetail();
34     EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList();
35     EsrSystemInfo esrSystemInfoObj = new EsrSystemInfo();
36     
37     cloudRegion.setCloudOwner(vimRegisterInfo.getCloudOwner());
38     cloudRegion.setCloudRegionId(vimRegisterInfo.getCloudRegionId());
39     cloudRegion.setCloudType(vimRegisterInfo.getCloudType());
40     cloudRegion.setCloudRegionVersion(vimRegisterInfo.getCloudRegionVersion());
41     cloudRegion.setCloudZone(vimRegisterInfo.getCloudZone());
42     cloudRegion.setComplexName(vimRegisterInfo.getComplexName());
43     cloudRegion.setOwnerDefinedType(vimRegisterInfo.getOwnerDefinedType());
44     cloudRegion.setCloudExtraInfo(vimRegisterInfo.getCloudExtraInfo());
45     
46     esrSystemInfoObj = vimAuthInfo2EsrSystemInfoObj(vimRegisterInfo.getVimAuthInfos());
47     esrSystemInfoObj.setSystemStatus(vimRegisterInfo.getStatus());
48     esrSystemInfoList = extsysUtil.getEsrSystemInfoListFromAuthInfo(esrSystemInfoObj);
49     cloudRegion.setEsrSystemInfoList(esrSystemInfoList);
50     return cloudRegion;
51   }
52
53   private EsrSystemInfo vimAuthInfo2EsrSystemInfoObj(ArrayList<VimAuthInfo> vimAuthInfos) {
54     EsrSystemInfo esrSystemInfoObj = new EsrSystemInfo();
55     VimAuthInfo vimAuthInfo = new VimAuthInfo();
56     vimAuthInfo = vimAuthInfos.get(0);
57     esrSystemInfoObj.setCloudDomain(vimAuthInfo.getCloudDomain());
58     esrSystemInfoObj.setUserName(vimAuthInfo.getUserName());
59     esrSystemInfoObj.setPassword(vimAuthInfo.getPassword());
60     esrSystemInfoObj.setServiceUrl(vimAuthInfo.getAuthUrl());
61     esrSystemInfoObj.setSslCassert(vimAuthInfo.getSslCacert());
62     esrSystemInfoObj.setSslInsecure(vimAuthInfo.getSslInsecure());
63     esrSystemInfoObj.setEsrSystemInfoId(ExtsysUtil.generateId());
64     esrSystemInfoObj.setSystemType(SystemType.VIM.toString());
65 //    esrSystemInfoObj.setSystemStatus(SystemStatus.normal.toString());
66     return esrSystemInfoObj;
67   }
68   
69   private VimAuthInfo authInfo2VimAuthInfo(EsrSystemInfo authInfo) {
70     VimAuthInfo vimAuthInfo = new VimAuthInfo();
71     vimAuthInfo.setAuthUrl(authInfo.getServiceUrl());
72     vimAuthInfo.setCloudDomain(authInfo.getCloudDomain());
73     vimAuthInfo.setPassword(authInfo.getPassword());
74     vimAuthInfo.setSslCacert(authInfo.getSslCassert());
75     vimAuthInfo.setSslInsecure(authInfo.getSslInsecure());
76     vimAuthInfo.setUserName(authInfo.getUserName());
77     return vimAuthInfo;
78   }
79   
80   public VimRegisterInfo cloudRegion2VimRegisterInfo(CloudRegionDetail cloudRegion) {
81     VimRegisterInfo vimRegisterInfo = new VimRegisterInfo();
82     VimAuthInfo vimAuthInfo = new VimAuthInfo();
83     ArrayList<VimAuthInfo> vimAuthInfos = new ArrayList<VimAuthInfo>();
84     vimAuthInfo = authInfo2VimAuthInfo(cloudRegion.getEsrSystemInfoList().getEsrSystemInfo().get(0));
85     vimAuthInfos.add(vimAuthInfo);
86     vimRegisterInfo.setVimAuthInfos(vimAuthInfos);
87     vimRegisterInfo.setCloudExtraInfo(cloudRegion.getCloudExtraInfo());
88     vimRegisterInfo.setCloudOwner(cloudRegion.getCloudOwner());
89     vimRegisterInfo.setCloudRegionId(cloudRegion.getCloudRegionId());
90     vimRegisterInfo.setCloudType(cloudRegion.getCloudType());
91     vimRegisterInfo.setCloudZone(cloudRegion.getCloudZone());
92     vimRegisterInfo.setComplexName(cloudRegion.getComplexName());
93     vimRegisterInfo.setCloudRegionVersion(cloudRegion.getCloudRegionVersion());
94     vimRegisterInfo.setOwnerDefinedType(cloudRegion.getOwnerDefinedType());
95     vimRegisterInfo.setStatus(cloudRegion.getEsrSystemInfoList().getEsrSystemInfo().get(0).getSystemStatus());
96     return vimRegisterInfo;
97   }
98 }