23190a75ff1e3fb96e041fa8fdef70e9d3ade955
[vfc/nfvo/resmanagement.git] /
1 /*
2  * Copyright 2016 Huawei Technologies Co., Ltd.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.vfc.nfvo.resmanagement.service.rest;
18
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;
26
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;
36
37 import net.sf.json.JSONObject;
38
39 /**
40  * <br>
41  * <p>
42  * </p>
43  * 
44  * @author
45  * @version NFVO 0.5 Oct 29, 2016
46  */
47 @Path(UrlConstant.GRANTRES_URL)
48 @Produces(MediaType.APPLICATION_JSON)
49 @Consumes(MediaType.APPLICATION_JSON)
50 public class GrantResourseRoa {
51
52     private static final Logger LOGGER = LoggerFactory.getLogger(GrantResourseRoa.class);
53
54     private GrantResService grantResService;
55
56     @PUT
57     @Path("/stub")
58     public JSONObject grantResource(@Context HttpServletRequest context) throws ServiceException {
59         JSONObject object = RequestUtil.getJsonRequestBody(context);
60         if(null == object) {
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"));
63         }
64
65         LOGGER.info("GrantResourseRoa::grantResource:{}", object.toString());
66         try {
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());
71         }
72     }
73
74     @PUT
75     public JSONObject grantResourceReal(@Context HttpServletRequest context) throws ServiceException {
76         JSONObject object = RequestUtil.getJsonRequestBody(context);
77         if(null == object) {
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"));
80         }
81
82         LOGGER.info("GrantResourseRoa::grantResource:{}", object.toString());
83         try {
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());
88         }
89     }
90
91     public void setGrantResService(GrantResService grantResService) {
92         this.grantResService = grantResService;
93     }
94 }