2 * Copyright 2016 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openo.nfvo.resmanagement.service.rest;
19 import java.util.HashMap;
20 import java.util.List;
23 import javax.servlet.http.HttpServletRequest;
24 import javax.ws.rs.Consumes;
25 import javax.ws.rs.DELETE;
26 import javax.ws.rs.GET;
27 import javax.ws.rs.POST;
28 import javax.ws.rs.Path;
29 import javax.ws.rs.PathParam;
30 import javax.ws.rs.Produces;
31 import javax.ws.rs.core.Context;
32 import javax.ws.rs.core.MediaType;
34 import org.openo.baseservice.remoteservice.exception.ServiceException;
35 import org.openo.nfvo.resmanagement.common.ResourceUtil;
36 import org.openo.nfvo.resmanagement.common.constant.HttpConstant;
37 import org.openo.nfvo.resmanagement.common.constant.ParamConstant;
38 import org.openo.nfvo.resmanagement.common.constant.UrlConstant;
39 import org.openo.nfvo.resmanagement.common.util.request.RequestUtil;
40 import org.openo.nfvo.resmanagement.common.util.response.ResponseUtil;
41 import org.openo.nfvo.resmanagement.common.util.response.RoaResponseUtil;
42 import org.openo.nfvo.resmanagement.service.entity.VnfInfoEntity;
43 import org.openo.nfvo.resmanagement.service.group.inf.VnfInfoService;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
47 import net.sf.json.JSONObject;
55 * @version NFVO 0.5 Oct 28, 2016
57 @Path(UrlConstant.VNFINFO_URL)
58 @Produces(MediaType.APPLICATION_JSON)
59 @Consumes(MediaType.APPLICATION_JSON)
60 public class VnfInfoRoa {
62 private static final Logger LOGGER = LoggerFactory.getLogger(VnfInfoRoa.class);
64 private VnfInfoService vnfInfoService;
67 public JSONObject getVnfInfos(@Context HttpServletRequest context) throws ServiceException {
68 Map<String, Object> map = new HashMap<>(10);
69 List<VnfInfoEntity> vnfInfos = vnfInfoService.getList(map);
70 LOGGER.info("VnfInfoRoa::getVnfInfos:{}", vnfInfos.toString());
71 JSONObject result = new JSONObject();
72 result.put("vnfInfos", vnfInfos);
78 public JSONObject getVnfInfo(@Context HttpServletRequest context, @PathParam("id") String id)
79 throws ServiceException {
80 LOGGER.info("VnfInfoRoa::getVnfInfo id:{}", id);
81 Map<String, Object> map = new HashMap<>(10);
82 map.put(ParamConstant.PARAM_ID, id);
83 List<VnfInfoEntity> vnfInfos = vnfInfoService.getList(map);
84 LOGGER.info("VnfInfoRoa::getVnfInfo:{}", vnfInfos.toString());
85 JSONObject result = new JSONObject();
86 result.put("vnfInfos", vnfInfos);
91 public JSONObject addVnfInfo(@Context HttpServletRequest context) throws ServiceException {
92 JSONObject object = RequestUtil.getJsonRequestBody(context);
94 LOGGER.error("function=addVnfInfo; msg=add error, because vnfInfo is null.");
95 throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.vnfInfo.add.null"));
98 LOGGER.info("VnfInfoRoa::addVnfInfo:{}", object.toString());
100 return vnfInfoService.addVnfInfo(object);
101 } catch(ServiceException se) {
102 LOGGER.error("VnfInfoRoa::addVnfInfo error:{}" + se);
103 return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage());
109 public JSONObject deleteVnfInfo(@Context HttpServletRequest context, @PathParam(ParamConstant.PARAM_ID) String id)
110 throws ServiceException {
112 LOGGER.error("function=deleteVnfInfo; msg=delete error, because id is null.");
113 throw new ServiceException(
114 ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.vnfInfo.delete.id.null"));
116 LOGGER.info("VnfInfoRoa::deleteVnfInfo id:{}", id);
118 int result = vnfInfoService.delete(id);
119 return RoaResponseUtil.delete(result);
120 } catch(ServiceException se) {
121 LOGGER.error("VnfInfoRoa::deleteVnfInfo error:{}" + se);
122 return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage());
126 public void setVnfInfoService(VnfInfoService vnfInfoService) {
127 this.vnfInfoService = vnfInfoService;