2 * Copyright 2016 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.res.service.group.impl;
19 import java.util.List;
21 import java.util.UUID;
23 import org.apache.commons.lang3.StringUtils;
24 import org.onap.vfc.nfvo.res.common.ResourceUtil;
25 import org.onap.vfc.nfvo.res.service.dao.inf.VirtualLinkDao;
26 import org.onap.vfc.nfvo.res.service.entity.VirtualLinkEntity;
27 import org.onap.vfc.nfvo.res.service.group.inf.VirtualLinkService;
28 import org.openo.baseservice.remoteservice.exception.ServiceException;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 import net.sf.json.JSONObject;
40 * @version NFVO 0.5 Oct 27, 2016
42 public class VirtualLinkServiceImpl implements VirtualLinkService {
44 private static final Logger LOGGER = LoggerFactory.getLogger(VirtualLinkServiceImpl.class);
46 private VirtualLinkDao virtualLinkDao;
51 * @param virtualLinkEntity
53 * @throws ServiceException
57 public JSONObject addVl(VirtualLinkEntity virtualLinkEntity) throws ServiceException {
58 if(!checkId(virtualLinkEntity.getId())) {
59 LOGGER.error("function=addVl; msg=add error, because id is already exist.");
60 throw new ServiceException(ResourceUtil
61 .getMessage("org.onap.vfc.nfvo.res.service.group.impl.VirtualLinkServiceImpl.add.id.check"));
63 if(StringUtils.isEmpty(virtualLinkEntity.getId())) {
64 virtualLinkEntity.setId(UUID.randomUUID().toString());
66 int result = virtualLinkDao.addVl(virtualLinkEntity);
67 JSONObject restJson = new JSONObject();
69 restJson.put("id", virtualLinkEntity.getId());
70 restJson.put("name", virtualLinkEntity.getName());
72 LOGGER.error("function=addVl; msg=add vl into DB error.");
73 restJson.put("message", "Add Vl into DB error.");
86 private boolean checkId(String id) {
87 VirtualLinkEntity vl = virtualLinkDao.getVl(id);
99 * @throws ServiceException
103 public List<VirtualLinkEntity> getList(Map<String, Object> map) throws ServiceException {
104 return virtualLinkDao.getVls(map);
112 * @throws ServiceException
116 public int delete(String id) throws ServiceException {
117 return virtualLinkDao.deleteVlById(id);
120 public void setVirtualLinkDao(VirtualLinkDao virtualLinkDao) {
121 this.virtualLinkDao = virtualLinkDao;