Add ns rest interface 81/10181/1
authorluxin <luxin7@huawei.com>
Mon, 4 Sep 2017 09:09:56 +0000 (17:09 +0800)
committerluxin <luxin7@huawei.com>
Mon, 4 Sep 2017 09:09:56 +0000 (17:09 +0800)
Change-Id: Ibdbe802df10ba7e0cab62fa99a9a59dd05340d0f
Issue-Id:VFC-216
Signed-off-by: luxin <luxin7@huawei.com>
ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/NsRoa.java [new file with mode: 0644]

diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/NsRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/NsRoa.java
new file mode 100644 (file)
index 0000000..63905ea
--- /dev/null
@@ -0,0 +1,132 @@
+\r
+package org.onap.vfc.nfvo.resmanagement.service.rest;\r
+\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import javax.servlet.http.HttpServletRequest;\r
+import javax.servlet.http.HttpServletResponse;\r
+import javax.ws.rs.Consumes;\r
+import javax.ws.rs.DELETE;\r
+import javax.ws.rs.GET;\r
+import javax.ws.rs.POST;\r
+import javax.ws.rs.Path;\r
+import javax.ws.rs.PathParam;\r
+import javax.ws.rs.Produces;\r
+import javax.ws.rs.core.Context;\r
+import javax.ws.rs.core.MediaType;\r
+\r
+import org.onap.vfc.nfvo.resmanagement.common.constant.HttpConstant;\r
+import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant;\r
+import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant;\r
+import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil;\r
+import org.onap.vfc.nfvo.resmanagement.common.util.response.ResponseUtil;\r
+import org.onap.vfc.nfvo.resmanagement.common.util.response.RoaResponseUtil;\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
+@Path(UrlConstant.NS_URL)\r
+@Produces(MediaType.APPLICATION_JSON)\r
+@Consumes(MediaType.APPLICATION_JSON)\r
+public class NsRoa {\r
+\r
+    private static final Logger LOGGER = LoggerFactory.getLogger(VirtualLinkRoa.class);\r
+\r
+    private NsService nsService;\r
+\r
+    /**\r
+     * <br>\r
+     * \r
+     * @param context\r
+     * @param resp\r
+     * @return\r
+     * @throws ServiceException\r
+     * @since VFC 1.0\r
+     */\r
+    @POST\r
+    public JSONObject addNs(@Context HttpServletRequest context, @Context HttpServletResponse resp)\r
+            throws ServiceException {\r
+        JSONObject object = RequestUtil.getJsonRequestBody(context);\r
+        JSONObject restJson = new JSONObject();\r
+        if(null == object) {\r
+            LOGGER.error("function=addNs; msg=add error, because ns is null.");\r
+            restJson.put("message", "ns is null");\r
+            resp.setStatus(HttpConstant.HTTP_BAD_REQUEST);\r
+            return restJson;\r
+        }\r
+\r
+        LOGGER.info("VnfRoa::addVnf:{}", object.toString());\r
+        return nsService.addNs(object);\r
+    }\r
+\r
+    /**\r
+     * <br>\r
+     * \r
+     * @param context\r
+     * @return\r
+     * @throws ServiceException\r
+     * @since VFC 1.0\r
+     */\r
+    @GET\r
+    public JSONObject getAllNs(@Context HttpServletRequest context) throws ServiceException {\r
+        Map<String, Object> map = new HashMap<>(10);\r
+        List<NsEntity> allNs = nsService.getList(map);\r
+        LOGGER.info("NsRoa::getAllNs:{}", allNs.toString());\r
+        JSONObject result = new JSONObject();\r
+        result.put("ns", allNs);\r
+        return result;\r
+    }\r
+\r
+    /**\r
+     * <br>\r
+     * \r
+     * @param context\r
+     * @param id\r
+     * @return\r
+     * @throws ServiceException\r
+     * @since VFC 1.0\r
+     */\r
+    @GET\r
+    @Path("/{nsId}")\r
+    public JSONObject getNs(@Context HttpServletRequest context, @PathParam("nsId") String id) throws ServiceException {\r
+        LOGGER.info("NsRoa::getNs id:{}", id);\r
+        Map<String, Object> map = new HashMap<>(10);\r
+        map.put(ParamConstant.PARAM_ID, id);\r
+        List<NsEntity> ns = nsService.getList(map);\r
+        LOGGER.info("NsRoa::getNs:{}", ns.toString());\r
+        JSONObject result = new JSONObject();\r
+        result.put("ns", ns.get(0));\r
+        return result;\r
+    }\r
+\r
+    @DELETE\r
+    @Path("/{id}")\r
+    public JSONObject deleteNs(@Context HttpServletRequest context, @Context HttpServletResponse resp,\r
+            @PathParam(ParamConstant.PARAM_ID) String id) throws ServiceException {\r
+        JSONObject restJson = new JSONObject();\r
+        if(id == null) {\r
+            LOGGER.error("function=deleteNs; msg=delete error, because id is null.");\r
+            restJson.put("message", "ns id is null");\r
+            resp.setStatus(HttpConstant.HTTP_BAD_REQUEST);\r
+            return restJson;\r
+        }\r
+        LOGGER.info("NsRoa::deleteNs id:{}", id);\r
+        try {\r
+            int result = nsService.delete(id);\r
+            return RoaResponseUtil.delete(result);\r
+        } catch(ServiceException se) {\r
+            LOGGER.error("NsRoa::deleteNs error:{}" + se);\r
+            return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage());\r
+        }\r
+    }\r
+\r
+    public void setNsService(NsService nsService) {\r
+        this.nsService = nsService;\r
+    }\r
+}\r