2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.be.servlets;
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;
33 import javax.servlet.http.HttpServletRequest;
35 import javax.ws.rs.core.Context;
36 import javax.ws.rs.core.MediaType;
37 import javax.ws.rs.core.Response;
39 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
40 public class RequirementsServlet extends BeGenericServlet {
42 private static final Logger log = Logger.getLogger(RequirementsServlet.class);
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) {
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;
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);