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 javax.inject.Inject;
29 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
30 import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
31 import org.openecomp.sdc.be.dao.api.ActionStatus;
32 import org.openecomp.sdc.be.impl.ComponentsUtils;
33 import org.openecomp.sdc.be.user.UserBusinessLogic;
34 import org.openecomp.sdc.common.api.Constants;
35 import org.openecomp.sdc.common.log.wrappers.Logger;
36 import org.openecomp.sdc.exception.ResponseFormat;
38 import javax.servlet.http.HttpServletRequest;
40 import javax.ws.rs.core.Context;
41 import javax.ws.rs.core.MediaType;
42 import javax.ws.rs.core.Response;
44 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
45 public class RequirementsServlet extends BeGenericServlet {
47 private static final Logger log = Logger.getLogger(RequirementsServlet.class);
50 public RequirementsServlet(UserBusinessLogic userBusinessLogic,
51 ComponentsUtils componentsUtils) {
52 super(userBusinessLogic, componentsUtils);
56 @Path("resources/{resourceId}/requirements/{requirementId}")
57 @Consumes(MediaType.APPLICATION_JSON)
58 @Produces(MediaType.APPLICATION_JSON)
59 @ApiOperation(value = "Update Resource Requirement", httpMethod = "PUT", notes = "Returns updated requirement", response = Response.class)
60 @ApiResponses(value = { @ApiResponse(code = 200, message = "Resource requirement updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content") })
61 public Response updateRequirement(@ApiParam(value = "resource id to update with new requirement", required = true) @PathParam("resourceId") final String resourceId,
62 @ApiParam(value = "requirement id to update", required = true) @PathParam("requirementId") final String requirementId, @ApiParam(value = "Resource property to update", required = true) String requirementData,
63 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
65 // Convert RequirementDefinition from JSON
66 // TODO: it's going to be another object, probably. This is placeholder
67 // for sake of JSON validation
68 // RequirementDefinition requirementDefinition;
69 ResponseFormat responseFormat;
71 // TODO pass real entity
72 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), null);
73 } catch (Exception e) {
74 log.debug("Unexpected error: ", e);
75 responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
76 return buildErrorResponse(responseFormat);