2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.sdc.be.servlets;
\r
23 import javax.inject.Inject;
\r
24 import javax.servlet.http.HttpServletRequest;
\r
25 import javax.ws.rs.Consumes;
\r
26 import javax.ws.rs.HeaderParam;
\r
27 import javax.ws.rs.PUT;
\r
28 import javax.ws.rs.Path;
\r
29 import javax.ws.rs.PathParam;
\r
30 import javax.ws.rs.Produces;
\r
31 import javax.ws.rs.core.Context;
\r
32 import javax.ws.rs.core.MediaType;
\r
33 import javax.ws.rs.core.Response;
\r
34 import org.openecomp.sdc.be.dao.api.ActionStatus;
\r
35 import org.openecomp.sdc.be.impl.ComponentsUtils;
\r
36 import org.openecomp.sdc.be.user.UserBusinessLogic;
\r
37 import org.openecomp.sdc.common.api.Constants;
\r
38 import org.openecomp.sdc.common.log.wrappers.Logger;
\r
39 import org.openecomp.sdc.exception.ResponseFormat;
\r
40 import com.jcabi.aspects.Loggable;
\r
41 import io.swagger.v3.oas.annotations.Operation;
\r
42 import io.swagger.v3.oas.annotations.Parameter;
\r
43 import io.swagger.v3.oas.annotations.media.ArraySchema;
\r
44 import io.swagger.v3.oas.annotations.media.Content;
\r
45 import io.swagger.v3.oas.annotations.media.Schema;
\r
46 import io.swagger.v3.oas.annotations.responses.ApiResponse;
\r
47 import io.swagger.v3.oas.annotations.responses.ApiResponses;
\r
49 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
\r
50 public class RequirementsServlet extends BeGenericServlet {
\r
52 private static final Logger log = Logger.getLogger(RequirementsServlet.class);
\r
55 public RequirementsServlet(UserBusinessLogic userBusinessLogic,
\r
56 ComponentsUtils componentsUtils) {
\r
57 super(userBusinessLogic, componentsUtils);
\r
61 @Path("resources/{resourceId}/requirements/{requirementId}")
\r
62 @Consumes(MediaType.APPLICATION_JSON)
\r
63 @Produces(MediaType.APPLICATION_JSON)
\r
64 @Operation(description = "Update Resource Requirement", method = "PUT", summary = "Returns updated requirement", responses = @ApiResponse(
\r
65 content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
\r
66 @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Resource requirement updated"),
\r
67 @ApiResponse(responseCode = "403", description = "Restricted operation"),
\r
68 @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
\r
69 public Response updateRequirement(
\r
70 @Parameter(description = "resource id to update with new requirement",
\r
71 required = true) @PathParam("resourceId") final String resourceId,
\r
72 @Parameter(description = "requirement id to update",
\r
73 required = true) @PathParam("requirementId") final String requirementId,
\r
74 @Parameter(description = "Resource property to update", required = true) String requirementData,
\r
75 @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
\r
77 // Convert RequirementDefinition from JSON
\r
78 // TODO: it's going to be another object, probably. This is placeholder
\r
79 // for sake of JSON validation
\r
80 // RequirementDefinition requirementDefinition;
\r
81 ResponseFormat responseFormat;
\r
83 // TODO pass real entity
\r
84 return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), null);
\r
85 } catch (Exception e) {
\r
86 log.debug("Unexpected error: ", e);
\r
87 responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
\r
88 return buildErrorResponse(responseFormat);
\r