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.onap.vfc.nfvo.resmanagement.service.rest;
19 import javax.servlet.http.HttpServletRequest;
20 import javax.ws.rs.Consumes;
21 import javax.ws.rs.PUT;
22 import javax.ws.rs.Path;
23 import javax.ws.rs.Produces;
24 import javax.ws.rs.core.Context;
25 import javax.ws.rs.core.MediaType;
27 import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil;
28 import org.onap.vfc.nfvo.resmanagement.common.constant.HttpConstant;
29 import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant;
30 import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil;
31 import org.onap.vfc.nfvo.resmanagement.common.util.response.ResponseUtil;
32 import org.onap.vfc.nfvo.resmanagement.service.group.inf.GrantResService;
33 import org.openo.baseservice.remoteservice.exception.ServiceException;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 import net.sf.json.JSONObject;
45 * @version NFVO 0.5 Oct 29, 2016
47 @Path(UrlConstant.GRANTRES_URL)
48 @Produces(MediaType.APPLICATION_JSON)
49 @Consumes(MediaType.APPLICATION_JSON)
50 public class GrantResourseRoa {
52 private static final Logger LOGGER = LoggerFactory.getLogger(GrantResourseRoa.class);
54 private GrantResService grantResService;
58 public JSONObject grantResource(@Context HttpServletRequest context) throws ServiceException {
59 JSONObject object = RequestUtil.getJsonRequestBody(context);
61 LOGGER.error("function=grantResource; msg=grantResource error, because body is null.");
62 throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.grantResource.null"));
65 LOGGER.info("GrantResourseRoa::grantResource:{}", object.toString());
67 return grantResService.grantResource(object);
68 } catch(ServiceException se) {
69 LOGGER.error("GrantResourseRoa::grantResource error:{}" + se);
70 return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage());
75 public JSONObject grantResourceReal(@Context HttpServletRequest context) throws ServiceException {
76 JSONObject object = RequestUtil.getJsonRequestBody(context);
78 LOGGER.error("function=grantResource; msg=grantResource error, because body is null.");
79 throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.grantResource.null"));
82 LOGGER.info("GrantResourseRoa::grantResource:{}", object.toString());
84 return grantResService.grantResourceReal(object);
85 } catch(ServiceException se) {
86 LOGGER.error("GrantResourseRoa::grantResource error:{}" + se);
87 return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage());
91 public void setGrantResService(GrantResService grantResService) {
92 this.grantResService = grantResService;