17a9bf67bac6b0b791fedec6172ce3030e60073f
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / servlets / RequirementsServlet.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.be.servlets;
22
23 import com.jcabi.aspects.Loggable;
24 import io.swagger.annotations.ApiOperation;
25 import io.swagger.annotations.ApiParam;
26 import io.swagger.annotations.ApiResponse;
27 import io.swagger.annotations.ApiResponses;
28 import org.openecomp.sdc.be.dao.api.ActionStatus;
29 import org.openecomp.sdc.common.api.Constants;
30 import org.openecomp.sdc.common.log.wrappers.Logger;
31 import org.openecomp.sdc.exception.ResponseFormat;
32
33 import javax.servlet.http.HttpServletRequest;
34 import javax.ws.rs.*;
35 import javax.ws.rs.core.Context;
36 import javax.ws.rs.core.MediaType;
37 import javax.ws.rs.core.Response;
38
39 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
40 public class RequirementsServlet extends BeGenericServlet {
41
42     private static final Logger log = Logger.getLogger(RequirementsServlet.class);
43
44     @PUT
45     @Path("resources/{resourceId}/requirements/{requirementId}")
46     @Consumes(MediaType.APPLICATION_JSON)
47     @Produces(MediaType.APPLICATION_JSON)
48     @ApiOperation(value = "Update Resource Requirement", httpMethod = "PUT", notes = "Returns updated requirement", response = Response.class)
49     @ApiResponses(value = { @ApiResponse(code = 200, message = "Resource requirement updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
50     public Response updateRequirement(@ApiParam(value = "resource id to update with new requirement", required = true) @PathParam("resourceId") final String resourceId,
51                                       @ApiParam(value = "requirement id to update", required = true) @PathParam("requirementId") final String requirementId, @ApiParam(value = "Resource property to update", required = true) String requirementData,
52                                       @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
53
54         // Convert RequirementDefinition from JSON
55         // TODO: it's going to be another object, probably. This is placeholder
56         // for sake of JSON validation
57         // RequirementDefinition requirementDefinition;
58         ResponseFormat responseFormat;
59         try {
60             // TODO pass real entity
61             return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), null);
62         }  catch (Exception e) {
63             log.debug("Unexpected error: ", e);
64             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
65             return buildErrorResponse(responseFormat);
66         }
67     }
68 }