255f20ab9d58e3ec5c88969dd7c4122dee189f8d
[vfc/nfvo/resmanagement.git] /
1 /*
2  * Copyright 2016-2017 Huawei Technologies Co., Ltd.
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
17 package org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl;
18
19 import java.util.List;
20 import java.util.Map;
21
22 import org.apache.logging.log4j.LogManager;
23 import org.apache.logging.log4j.Logger;
24 import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil;
25 import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Network;
26 import org.onap.vfc.nfvo.resmanagement.service.business.inf.NetworkBusiness;
27 import org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity;
28 import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
29
30 import net.sf.json.JSONObject;
31
32 /**
33  * Network implementation class.<br>
34  * <p>
35  * </p>
36  *
37  * @author
38  * @version VFC 1.0 Sep 10, 2016
39  */
40 public class NetworkImpl implements Network {
41
42     private static final Logger LOGGER = LogManager.getLogger(NetworkImpl.class);
43
44     private NetworkBusiness networkBusiness;
45
46     @Override
47     public int add(JSONObject jsonObject) throws ServiceException {
48         LOGGER.warn("function=addPort; jsonObject={}", jsonObject);
49         JSONObject networkObj = dataParse(jsonObject);
50         return networkBusiness.addNetwork(NetworkEntity.toEntity(networkObj));
51     }
52
53     private JSONObject dataParse(JSONObject jsonObject) {
54         JSONObject portObj = new JSONObject();
55         portObj.put("id", JsonUtil.getJsonFieldStr(jsonObject, "id"));
56         portObj.put("name", JsonUtil.getJsonFieldStr(jsonObject, "name"));
57         portObj.put("status", JsonUtil.getJsonFieldStr(jsonObject, "status"));
58         portObj.put("tenantId", JsonUtil.getJsonFieldStr(jsonObject, "tenant_id"));
59         portObj.put("vimId", JsonUtil.getJsonFieldStr(jsonObject, "vimId"));
60         portObj.put("vimName", JsonUtil.getJsonFieldStr(jsonObject, "vimName"));
61         portObj.put("physicalNetwork", JsonUtil.getJsonFieldStr(jsonObject, "physicalNetwork"));
62         portObj.put("networkType", JsonUtil.getJsonFieldStr(jsonObject, "networkType"));
63         portObj.put("segmentationId", JsonUtil.getJsonFieldStr(jsonObject, "segmentationId"));
64         return portObj;
65     }
66
67     @Override
68     public int add(NetworkEntity entity) throws ServiceException {
69         return networkBusiness.addNetwork(entity);
70     }
71
72     @Override
73     public int update(JSONObject jsonObject) throws ServiceException {
74         return networkBusiness.updateNetworkSelective(NetworkEntity.toEntity(jsonObject));
75     }
76
77     @Override
78     public int delete(String id) throws ServiceException {
79         return networkBusiness.deleteNetwork(id);
80     }
81
82     @Override
83     public int updateStatusByVimId(JSONObject jsonObject) throws ServiceException {
84         return networkBusiness.updateNetworkByVimId(NetworkEntity.toEntity(jsonObject));
85     }
86
87     @Override
88     public List<NetworkEntity> getList(Map<String, Object> condition) throws ServiceException {
89         return networkBusiness.getNetworks(condition);
90     }
91
92     @Override
93     public int deleteResByVimId(String vimId) throws ServiceException {
94         return networkBusiness.deleteNetworkByVimId(vimId);
95     }
96
97     public void setNetworkBusiness(NetworkBusiness networkBusiness) {
98         this.networkBusiness = networkBusiness;
99     }
100
101 }