diff options
author | 2017-09-04 16:53:23 +0800 | |
---|---|---|
committer | 2017-09-04 16:53:23 +0800 | |
commit | 8577817c782b27b83e377effff16d6bd70a1ccfb (patch) | |
tree | 66a9f15529c7b13f1c95ae09c5b6728764b346a7 /ResmanagementService/service/src/main | |
parent | dfaa80a79250067391a2fcc5e1d571fcc50460f1 (diff) |
Add ns service interface
Change-Id: Idcf48249cd76d6852fc37b297466e14f235a6eb5
Issue-Id:VFC-216
Signed-off-by: luxin <luxin7@huawei.com>
Diffstat (limited to 'ResmanagementService/service/src/main')
2 files changed, 161 insertions, 0 deletions
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;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @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<NsEntity> getList(Map<String, Object> 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;
+
+/**
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version VFC 1.0 Sep 4, 2017
+ */
+public interface NsService {
+
+ /**
+ * <br>
+ *
+ * @param object
+ * @return
+ * @since VFC 1.0
+ */
+ JSONObject addNs(JSONObject object);
+
+ /**
+ * <br>
+ *
+ * @param map
+ * @return
+ * @throws ServiceException
+ * @since VFC 1.0
+ */
+ List<NsEntity> getList(Map<String, Object> map) throws ServiceException;
+
+ /**
+ * <br>
+ *
+ * @param id
+ * @return
+ * @throws ServiceException
+ * @since VFC 1.0
+ */
+ int delete(String id) throws ServiceException;
+
+}
|