36b6cd1b4debe3349bc94caf763254591485edba
[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.res.service.base.openstack.impl;
18
19 import java.util.List;
20 import java.util.Map;
21
22 import org.onap.vfc.nfvo.res.common.util.JsonUtil;
23 import org.onap.vfc.nfvo.res.service.base.openstack.inf.Port;
24 import org.onap.vfc.nfvo.res.service.business.inf.PortBusiness;
25 import org.onap.vfc.nfvo.res.service.entity.PortEntity;
26 import org.openo.baseservice.remoteservice.exception.ServiceException;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 import net.sf.json.JSONObject;
31
32 /**
33  * Port implementation class.<br>
34  * <p>
35  * </p>
36  *
37  * @author
38  * @version NFVO 0.5 Sep 10, 2016
39  */
40 public class PortImpl implements Port {
41
42     private static final Logger LOGGER = LoggerFactory.getLogger(PortImpl.class);
43
44     private PortBusiness portBusiness;
45
46     @Override
47     public int add(JSONObject jsonObject) throws ServiceException {
48         LOGGER.warn("function=addPort; jsonObject={}", jsonObject);
49         JSONObject portObj = dataParse(jsonObject);
50         return portBusiness.addPort(PortEntity.toEntity(portObj));
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("networkId", JsonUtil.getJsonFieldStr(jsonObject, "networkId"));
58         portObj.put("status", JsonUtil.getJsonFieldStr(jsonObject, "status"));
59         portObj.put("tenantId", JsonUtil.getJsonFieldStr(jsonObject, "tenant_id"));
60         portObj.put("vimId", JsonUtil.getJsonFieldStr(jsonObject, "vimId"));
61         portObj.put("vimName", JsonUtil.getJsonFieldStr(jsonObject, "vimName"));
62         return portObj;
63     }
64
65     @Override
66     public int add(PortEntity portEntity) throws ServiceException {
67         return portBusiness.addPort(portEntity);
68     }
69
70     @Override
71     public int update(JSONObject jsonObject) throws ServiceException {
72         return portBusiness.updatePortSelective(PortEntity.toEntity(jsonObject));
73     }
74
75     @Override
76     public int update(PortEntity portEntity) throws ServiceException {
77         return portBusiness.updatePortSelective(portEntity);
78     }
79
80     @Override
81     public int delete(String id) throws ServiceException {
82         return portBusiness.deletePort(id);
83     }
84
85     @Override
86     public int updateStatusByVimId(JSONObject jsonObject) throws ServiceException {
87         return portBusiness.updatePortByVimId(PortEntity.toEntity(jsonObject));
88     }
89
90     @Override
91     public int deleteResByVimId(String vimId) throws ServiceException {
92         return portBusiness.deletePortByVimId(vimId);
93     }
94
95     @Override
96     public List<PortEntity> getList(Map<String, Object> condition) throws ServiceException {
97         return portBusiness.getPorts(condition);
98     }
99
100     public void setPortBusiness(PortBusiness portBusiness) {
101         this.portBusiness = portBusiness;
102     }
103 }