2 * Copyright 2016-2017 Huawei Technologies Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl;
19 import java.util.List;
22 import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil;
23 import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Port;
24 import org.onap.vfc.nfvo.resmanagement.service.business.inf.PortBusiness;
25 import org.onap.vfc.nfvo.resmanagement.service.entity.PortEntity;
26 import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 import net.sf.json.JSONObject;
33 * Port implementation class.<br>
38 * @version NFVO 0.5 Sep 10, 2016
40 public class PortImpl implements Port {
42 private static final Logger LOGGER = LoggerFactory.getLogger(PortImpl.class);
44 private PortBusiness portBusiness;
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));
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"));
66 public int add(PortEntity portEntity) throws ServiceException {
67 return portBusiness.addPort(portEntity);
71 public int update(JSONObject jsonObject) throws ServiceException {
72 return portBusiness.updatePortSelective(PortEntity.toEntity(jsonObject));
76 public int update(PortEntity portEntity) throws ServiceException {
77 return portBusiness.updatePortSelective(portEntity);
81 public int delete(String id) throws ServiceException {
82 return portBusiness.deletePort(id);
86 public int updateStatusByVimId(JSONObject jsonObject) throws ServiceException {
87 return portBusiness.updatePortByVimId(PortEntity.toEntity(jsonObject));
91 public int deleteResByVimId(String vimId) throws ServiceException {
92 return portBusiness.deletePortByVimId(vimId);
96 public List<PortEntity> getList(Map<String, Object> condition) throws ServiceException {
97 return portBusiness.getPorts(condition);
100 public void setPortBusiness(PortBusiness portBusiness) {
101 this.portBusiness = portBusiness;