- @POST
- @Path("/{containerComponentType}/{componentId}/policies/{policyId}/targets")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- @ApiOperation(value = "update policy targets", httpMethod = "POST", notes = "Returns updated Policy", response = Response.class)
- @ApiResponses(value = {@ApiResponse(code = 201, message = "Policy target updated"), @ApiResponse(code = 403, message = "Restricted operation"), @ApiResponse(code = 400, message = "Invalid content / Missing content")})
- public Response updatePolicyTargets(@PathParam("componentId") final String containerComponentId,
- @ApiParam(value = "valid values: resources / services", allowableValues = ComponentTypeEnum.RESOURCE_PARAM_NAME + "," + ComponentTypeEnum.SERVICE_PARAM_NAME) @PathParam("containerComponentType") final String containerComponentType,
- @PathParam("policyId") final String policyId,
- @HeaderParam(value = Constants.USER_ID_HEADER) @ApiParam(value = "USER_ID of modifier user", required = true) String userId,
- @Context final HttpServletRequest request,
- List<PolicyTargetDTO> requestJson) {
- try {
-
- return updatePolicyTargetsFromDTO(requestJson)
- .left()
- .bind(policyTarget -> updatePolicyTargetsFromMap(policyTarget, containerComponentType, containerComponentId, policyId, userId))
- .either(this::buildOkResponse, this::buildErrorResponse);
-
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create Policy");
- log.debug("Policy target update has been failed with the exception{}. ", e);
- return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
- }
+ @POST
+ @Path("/{containerComponentType}/{componentId}/policies/{policyId}/targets")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "update policy targets", method = "POST", summary = "Returns updated Policy", responses = {
+ @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
+ @ApiResponse(responseCode = "201", description = "Policy target updated"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content")})
+ public Response updatePolicyTargets(@PathParam("componentId") final String containerComponentId,
+ @Parameter(description = "valid values: resources / services", schema = @Schema(allowableValues = {
+ ComponentTypeEnum.RESOURCE_PARAM_NAME,
+ ComponentTypeEnum.SERVICE_PARAM_NAME})) @PathParam("containerComponentType") final String containerComponentType,
+ @PathParam("policyId") final String policyId,
+ @HeaderParam(value = Constants.USER_ID_HEADER) @Parameter(description = "USER_ID of modifier user", required = true) String userId,
+ @Context final HttpServletRequest request, List<PolicyTargetDTO> requestJson) {
+ Map<PolicyTargetType, List<String>> policyTargetTypeListMap = updatePolicyTargetsFromDTO(requestJson);
+ PolicyDefinition policyDefinition = updatePolicyTargetsFromMap(policyTargetTypeListMap, containerComponentType, containerComponentId,
+ policyId, userId);
+ return buildOkResponse(policyDefinition);