2 * Copyright 2017 Huawei Technologies Co., Ltd.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.onap.vfc.nfvo.resmanagement.service.group.impl;
\r
19 import java.util.List;
\r
20 import java.util.Map;
\r
21 import java.util.UUID;
\r
23 import org.apache.commons.lang3.StringUtils;
\r
24 import org.onap.vfc.nfvo.resmanagement.service.dao.inf.NsDao;
\r
25 import org.onap.vfc.nfvo.resmanagement.service.entity.NsEntity;
\r
26 import org.onap.vfc.nfvo.resmanagement.service.group.inf.NsService;
\r
27 import org.openo.baseservice.remoteservice.exception.ServiceException;
\r
28 import org.slf4j.Logger;
\r
29 import org.slf4j.LoggerFactory;
\r
31 import net.sf.json.JSONObject;
\r
39 * @version VFC 1.0 Sep 4, 2017
\r
41 public class NsServiceImpl implements NsService {
\r
43 private static final Logger LOGGER = LoggerFactory.getLogger(NsServiceImpl.class);
\r
45 private NsDao nsDao;
\r
48 public JSONObject addNs(JSONObject object) {
\r
49 NsEntity nsEntity = NsEntity.toEntity(object);
\r
50 JSONObject restJson = new JSONObject();
\r
52 if(!checkId(nsEntity.getId())) {
\r
53 LOGGER.error("function=addVnf; msg=add error, because id is already exist.");
\r
54 restJson.put("message", "Ns id is already exist.");
\r
58 if(StringUtils.isEmpty(nsEntity.getId())) {
\r
59 nsEntity.setId(UUID.randomUUID().toString());
\r
61 int result = nsDao.addNs(nsEntity);
\r
64 restJson.put("id", nsEntity.getId());
\r
65 restJson.put("name", nsEntity.getName());
\r
67 LOGGER.error("function=addNs; msg=add ns into DB error.");
\r
68 restJson.put("message", "Add ns into DB error.");
\r
73 private boolean checkId(String id) {
\r
74 NsEntity nsEntity = nsDao.getNs(id);
\r
75 if(null == nsEntity) {
\r
81 public void setNsDao(NsDao nsDao) {
\r
86 public List<NsEntity> getList(Map<String, Object> map) throws ServiceException {
\r
87 return nsDao.getAllNs(map);
\r
91 public int delete(String id) throws ServiceException {
\r
92 return nsDao.deleteNsById(id);
\r