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.business.impl;
19 import java.util.List;
21 import java.util.UUID;
23 import org.apache.commons.lang.StringUtils;
24 import org.apache.logging.log4j.LogManager;
25 import org.apache.logging.log4j.Logger;
26 import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil;
27 import org.onap.vfc.nfvo.resmanagement.service.business.inf.PortBusiness;
28 import org.onap.vfc.nfvo.resmanagement.service.dao.inf.PortDao;
29 import org.onap.vfc.nfvo.resmanagement.service.entity.PortEntity;
30 import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
33 * Port business implementation class.<br>
38 * @version VFC 1.0 Sep 10, 2016
40 public class PortBusinessImpl implements PortBusiness {
42 private static final Logger LOGGER = LogManager.getLogger(PortBusinessImpl.class);
44 private PortDao portDao;
47 public PortEntity getPort(String id) {
48 if(StringUtils.isEmpty(id)) {
49 LOGGER.error("function=getPort; msg=get error, because id is empty.");
52 return portDao.getPort(id);
56 public List<PortEntity> getPorts(Map<String, Object> condition) {
57 return portDao.getPorts(condition);
61 public int deletePort(String id) throws ServiceException {
62 if(StringUtils.isEmpty(id)) {
63 LOGGER.error("function=deletePort; msg=delete error, because id is empty.");
64 throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.port.delete.id.null"));
66 PortEntity rp = portDao.getPort(id);
68 return portDao.deletePort(id);
71 return portDao.deletePort(id);
75 public int addPort(PortEntity portEntity) throws ServiceException {
76 if(null == portEntity) {
77 LOGGER.error("function=addPort; msg=add error, because portEntity is null.");
78 throw new ServiceException(
79 ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.port.add.entity.null"));
82 if(!checkId(portEntity.getId())) {
83 return portDao.updatePortSelective(portEntity);
85 if(StringUtils.isEmpty(portEntity.getId())) {
86 portEntity.setId(UUID.randomUUID().toString());
88 return portDao.addPort(portEntity);
92 public int addPortSelective(PortEntity portEntity) throws ServiceException {
93 if(null == portEntity) {
94 LOGGER.error("function=addPortSelective; msg=add error, because portEntity is null.");
95 throw new ServiceException(
96 ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.port.add.entity.null"));
98 if(!checkId(portEntity.getId())) {
99 return portDao.updatePortSelective(portEntity);
102 if(StringUtils.isEmpty(portEntity.getId())) {
103 portEntity.setId(UUID.randomUUID().toString());
105 return portDao.addPortSelective(portEntity);
108 private boolean checkId(String id) {
109 PortEntity respool = portDao.getPort(id);
110 if(null == respool) {
117 public int updatePortSelective(PortEntity portEntity) throws ServiceException {
118 if(null == portEntity) {
119 LOGGER.error("function=updatePortSelective; msg=update error, because portEntity is null.");
120 throw new ServiceException(
121 ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.port.update.entity.null"));
124 return portDao.updatePortSelective(portEntity);
128 public int updatePort(PortEntity portEntity) throws ServiceException {
129 if(null == portEntity) {
130 LOGGER.error("function=updatePort; msg=update error, because portEntity is null.");
131 throw new ServiceException("update error, because portEntity is null.");
134 return portDao.updatePort(portEntity);
138 public int updatePortByVimId(PortEntity portEntity) throws ServiceException {
139 if(null == portEntity) {
140 LOGGER.error("function=updatePortByVimId; msg=update error, because portEntity is null.");
141 throw new ServiceException(
142 ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.port.update.entity.null"));
144 return portDao.updatePortByVimId(portEntity);
148 public int deletePortByVimId(String vimId) throws ServiceException {
149 if(StringUtils.isEmpty(vimId)) {
150 LOGGER.error("function=deletePortByVimId; msg=delete error, because VimId is empty.");
151 throw new ServiceException(
152 ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.port.delete.vimid.check"));
154 return portDao.deletePortByVimId(vimId);
157 public void setPortDao(PortDao portDao) {
158 this.portDao = portDao;