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.NetworkBusiness;
28 import org.onap.vfc.nfvo.resmanagement.service.dao.inf.NetworkDao;
29 import org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity;
30 import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
33 * Network business implementation class.<br>
38 * @version VFC 1.0 Sep 10, 2016
40 public class NetworkBusinessImpl implements NetworkBusiness {
42 private static final Logger LOGGER = LogManager.getLogger(NetworkBusinessImpl.class);
44 private NetworkDao networkDao;
47 public NetworkEntity getNetwork(String id) {
48 if(StringUtils.isEmpty(id)) {
49 LOGGER.error("function=getNetwork; msg=get error, because id is empty.");
52 return networkDao.getNetwork(id);
56 public List<NetworkEntity> getNetworks(Map<String, Object> condition) {
57 return networkDao.getNetworks(condition);
61 public int deleteNetwork(String id) throws ServiceException {
62 if(StringUtils.isEmpty(id)) {
63 LOGGER.error("function=deleteNetwork; msg=delete error, because id is empty.");
64 throw new ServiceException(
65 ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.network.delete.id.null"));
67 return networkDao.deleteNetwork(id);
71 public int addNetwork(NetworkEntity networkEntity) throws ServiceException {
72 if(null == networkEntity) {
73 LOGGER.error("function=addNetwork; msg=add error, because networkEntity is null.");
74 throw new ServiceException(
75 ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.network.add.entity.null"));
77 if(!checkId(networkEntity.getId())) {
78 return networkDao.updateNetworkSelective(networkEntity);
80 if(StringUtils.isEmpty(networkEntity.getId())) {
81 networkEntity.setId(UUID.randomUUID().toString());
83 return networkDao.addNetwork(networkEntity);
87 public int addNetworkSelective(NetworkEntity networkEntity) throws ServiceException {
88 if(null == networkEntity) {
89 LOGGER.error("function=addNetworkSelective; msg=add error, because networkEntity is null.");
90 throw new ServiceException(
91 ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.network.add.entity.null"));
93 if(!checkId(networkEntity.getId())) {
94 return networkDao.updateNetworkSelective(networkEntity);
96 if(StringUtils.isEmpty(networkEntity.getId())) {
97 networkEntity.setId(UUID.randomUUID().toString());
99 return networkDao.addNetworkSelective(networkEntity);
102 private boolean checkId(String id) {
103 NetworkEntity network = networkDao.getNetwork(id);
104 if(null == network) {
111 public int updateNetworkSelective(NetworkEntity networkEntity) throws ServiceException {
112 if(null == networkEntity) {
113 LOGGER.error("function=updateNetworkSelective; msg=update error, because networkEntity is null.");
114 throw new ServiceException(
115 ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.network.update.entity.null"));
117 return networkDao.updateNetworkSelective(networkEntity);
121 public int updateNetwork(NetworkEntity networkEntity) throws ServiceException {
122 if(null == networkEntity) {
123 LOGGER.error("function=updateNetwork; msg=update error, because networkEntity is null.");
124 throw new ServiceException(
125 ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.network.update.entity.null"));
127 return networkDao.updateNetwork(networkEntity);
131 public int updateNetworkByVimId(NetworkEntity networkEntity) throws ServiceException {
132 if(null == networkEntity) {
133 LOGGER.error("function=updateNetworkByVimId; msg=update error, because networkEntity is null.");
134 throw new ServiceException(
135 ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.network.update.entity.null"));
137 return networkDao.updateNetworkByVimId(networkEntity);
141 public int deleteNetworkByVimId(String vimId) throws ServiceException {
142 if(StringUtils.isEmpty(vimId)) {
143 LOGGER.error("function=deleteNetworkByVimId; msg=delete error, because VimId is empty.");
144 throw new ServiceException(ResourceUtil.getMessage(""));
146 return networkDao.deleteNetworkByVimId(vimId);
149 public void setNetworkDao(NetworkDao networkDao) {
150 this.networkDao = networkDao;