Add ns service interface 79/10179/1
authorluxin <luxin7@huawei.com>
Mon, 4 Sep 2017 08:53:23 +0000 (16:53 +0800)
committerluxin <luxin7@huawei.com>
Mon, 4 Sep 2017 08:53:23 +0000 (16:53 +0800)
Change-Id: Idcf48249cd76d6852fc37b297466e14f235a6eb5
Issue-Id:VFC-216
Signed-off-by: luxin <luxin7@huawei.com>
ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/NsServiceImpl.java [new file with mode: 0644]
ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/NsService.java [new file with mode: 0644]

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