2 * Copyright 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.group.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.util.restclient.ServiceException;
27 import org.onap.vfc.nfvo.resmanagement.service.dao.inf.NsDao;
28 import org.onap.vfc.nfvo.resmanagement.service.entity.NsEntity;
29 import org.onap.vfc.nfvo.resmanagement.service.group.inf.NsService;
31 import net.sf.json.JSONObject;
39 * @version VFC 1.0 Sep 4, 2017
41 public class NsServiceImpl implements NsService {
43 private static final Logger LOGGER = LogManager.getLogger(NsServiceImpl.class);
48 public JSONObject addNs(JSONObject object) {
49 NsEntity nsEntity = NsEntity.toEntity(object);
50 JSONObject restJson = new JSONObject();
52 if(!checkId(nsEntity.getId())) {
53 LOGGER.error("function=addNs; msg=add error, because id is already exist.");
54 restJson.put("message", "Ns id is already exist.");
58 if(StringUtils.isEmpty(nsEntity.getId())) {
59 nsEntity.setId(UUID.randomUUID().toString());
61 int result = nsDao.addNs(nsEntity);
64 restJson.put("ns", nsEntity);
66 LOGGER.error("function=addNs; msg=add ns into DB error.");
67 restJson.put("message", "Add ns into DB error.");
72 private boolean checkId(String id) {
73 NsEntity nsEntity = nsDao.getNs(id);
74 if(nsEntity.getId() == null) {
80 public void setNsDao(NsDao nsDao) {
85 public List<NsEntity> getList(Map<String, Object> map) throws ServiceException {
86 return nsDao.getAllNs(map);
90 public int delete(String id) throws ServiceException {
91 return nsDao.deleteNsById(id);