From 8577817c782b27b83e377effff16d6bd70a1ccfb Mon Sep 17 00:00:00 2001 From: luxin Date: Mon, 4 Sep 2017 16:53:23 +0800 Subject: Add ns service interface Change-Id: Idcf48249cd76d6852fc37b297466e14f235a6eb5 Issue-Id:VFC-216 Signed-off-by: luxin --- .../service/group/impl/NsServiceImpl.java | 95 ++++++++++++++++++++++ .../resmanagement/service/group/inf/NsService.java | 66 +++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/NsServiceImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/NsService.java diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/NsServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/NsServiceImpl.java new file mode 100644 index 0000000..81e79c8 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/NsServiceImpl.java @@ -0,0 +1,95 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.group.impl; + +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.NsDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.NsEntity; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.NsService; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version VFC 1.0 Sep 4, 2017 + */ +public class NsServiceImpl implements NsService { + + private static final Logger LOGGER = LoggerFactory.getLogger(NsServiceImpl.class); + + private NsDao nsDao; + + @Override + public JSONObject addNs(JSONObject object) { + NsEntity nsEntity = NsEntity.toEntity(object); + JSONObject restJson = new JSONObject(); + + if(!checkId(nsEntity.getId())) { + LOGGER.error("function=addVnf; msg=add error, because id is already exist."); + restJson.put("message", "Ns id is already exist."); + return restJson; + } + + if(StringUtils.isEmpty(nsEntity.getId())) { + nsEntity.setId(UUID.randomUUID().toString()); + } + int result = nsDao.addNs(nsEntity); + + if(result > 0) { + restJson.put("id", nsEntity.getId()); + restJson.put("name", nsEntity.getName()); + } else { + LOGGER.error("function=addNs; msg=add ns into DB error."); + restJson.put("message", "Add ns into DB error."); + } + return restJson; + } + + private boolean checkId(String id) { + NsEntity nsEntity = nsDao.getNs(id); + if(null == nsEntity) { + return true; + } + return false; + } + + public void setNsDao(NsDao nsDao) { + this.nsDao = nsDao; + } + + @Override + public List getList(Map map) throws ServiceException { + return nsDao.getAllNs(map); + } + + @Override + public int delete(String id) throws ServiceException { + return nsDao.deleteNsById(id); + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/NsService.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/NsService.java new file mode 100644 index 0000000..add9f47 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/NsService.java @@ -0,0 +1,66 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.group.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.NsEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version VFC 1.0 Sep 4, 2017 + */ +public interface NsService { + + /** + *
+ * + * @param object + * @return + * @since VFC 1.0 + */ + JSONObject addNs(JSONObject object); + + /** + *
+ * + * @param map + * @return + * @throws ServiceException + * @since VFC 1.0 + */ + List getList(Map map) throws ServiceException; + + /** + *
+ * + * @param id + * @return + * @throws ServiceException + * @since VFC 1.0 + */ + int delete(String id) throws ServiceException; + +} -- cgit 1.2.3-korg