--- /dev/null
+/*\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
--- /dev/null
+/*\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