josehernandezfintecheandomx commented on code in PR #2442:
URL: https://github.com/apache/fineract/pull/2442#discussion_r938800697


##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/delinquency/api/DelinquencyApiResource.java:
##########
@@ -0,0 +1,217 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.portfolio.delinquency.api;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.parameters.RequestBody;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import java.util.Collection;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriInfo;
+import lombok.RequiredArgsConstructor;
+import org.apache.fineract.commands.domain.CommandWrapper;
+import org.apache.fineract.commands.service.CommandWrapperBuilder;
+import 
org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
+import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper;
+import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
+import 
org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
+import 
org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
+import 
org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
+import org.apache.fineract.portfolio.delinquency.data.DelinquencyBucketData;
+import org.apache.fineract.portfolio.delinquency.data.DelinquencyRangeData;
+import 
org.apache.fineract.portfolio.delinquency.service.DelinquencyReadPlatformService;
+import org.springframework.stereotype.Component;
+
+@RequiredArgsConstructor
+@Path("delinquency")
+@Component
+@Tag(name = "Delinquency Range and Buckets Management", description = 
"Delinquency Range and Buckets management enables you to set up, fetch and 
adjust Delinquency overdue ranges")
+public class DelinquencyApiResource {
+
+    private final ApiRequestParameterHelper parameterHelper;
+    private final PlatformSecurityContext securityContext;
+    private final DefaultToApiJsonSerializer<DelinquencyBucketData> 
jsonSerializerBucket;
+    private final DefaultToApiJsonSerializer<DelinquencyRangeData> 
jsonSerializerRange;
+    private final DelinquencyReadPlatformService readPlatformService;
+    private final PortfolioCommandSourceWritePlatformService 
commandWritePlatformService;
+
+    @GET
+    @Path("ranges")
+    @Consumes({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON })
+    @Produces(MediaType.APPLICATION_JSON)
+    @Operation(summary = "List all Delinquency Ranges", description = "")
+    @ApiResponses({
+            @ApiResponse(responseCode = "200", description = "OK", content = 
@Content(array = @ArraySchema(schema = @Schema(implementation = 
DelinquencyApiResourceSwagger.GetDelinquencyRangesResponse.class)))) })
+    public String getDelinquencyRanges(@Context final UriInfo uriInfo) {
+        
securityContext.authenticatedUser().validateHasReadPermission("DELINQUENCY_BUCKET");
+        final Collection<DelinquencyRangeData> delinquencyRangeData = 
this.readPlatformService.retrieveAllDelinquencyRanges();
+        ApiRequestJsonSerializationSettings settings = 
parameterHelper.process(uriInfo.getQueryParameters());
+        return this.jsonSerializerRange.serialize(settings, 
delinquencyRangeData);
+    }
+
+    @GET
+    @Path("ranges/{delinquencyRangeId}")
+    @Consumes({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON })
+    @Produces(MediaType.APPLICATION_JSON)
+    @Operation(summary = "Retrieve a specific Delinquency Range based on the 
Id", description = "")
+    @ApiResponses({
+            @ApiResponse(responseCode = "200", description = "OK", content = 
@Content(schema = @Schema(implementation = 
DelinquencyApiResourceSwagger.GetDelinquencyRangesResponse.class))) })
+    public String getDelinquencyRange(
+            @PathParam("delinquencyRangeId") @Parameter(description = 
"delinquencyRangeId") final Long delinquencyRangeId,
+            @Context final UriInfo uriInfo) {
+        
securityContext.authenticatedUser().validateHasReadPermission("DELINQUENCY_BUCKET");
+        final DelinquencyRangeData delinquencyRangeData = 
this.readPlatformService.retrieveDelinquencyRange(delinquencyRangeId);
+        ApiRequestJsonSerializationSettings settings = 
parameterHelper.process(uriInfo.getQueryParameters());
+        return this.jsonSerializerRange.serialize(settings, 
delinquencyRangeData);
+    }
+
+    @POST
+    @Path("ranges")
+    @Consumes({ MediaType.APPLICATION_JSON })
+    @Produces({ MediaType.APPLICATION_JSON })
+    @Operation(summary = "Create Delinquency Range", description = "")
+    @RequestBody(required = true, content = @Content(schema = 
@Schema(implementation = 
DelinquencyApiResourceSwagger.PostDelinquencyRangeRequest.class)))
+    @ApiResponses({
+            @ApiResponse(responseCode = "200", description = "OK", content = 
@Content(schema = @Schema(implementation = 
DelinquencyApiResourceSwagger.PostDelinquencyRangeResponse.class))) })
+    public String createDelinquencyRange(final String jsonRequestBody, 
@Context UriInfo uriInfo) {
+        
securityContext.authenticatedUser().validateHasCreatePermission("DELINQUENCY_BUCKET");
+        final CommandWrapper commandRequest = new 
CommandWrapperBuilder().createDelinquencyRange().withJson(jsonRequestBody).build();
+
+        CommandProcessingResult result = 
commandWritePlatformService.logCommandSource(commandRequest);
+        return jsonSerializerRange.serialize(result);
+    }
+
+    @PUT
+    @Path("ranges/{delinquencyRangeId}")
+    @Consumes({ MediaType.APPLICATION_JSON })
+    @Produces({ MediaType.APPLICATION_JSON })
+    @Operation(summary = "Update Delinquency Range based on the Id", 
description = "")
+    @RequestBody(required = true, content = @Content(schema = 
@Schema(implementation = 
DelinquencyApiResourceSwagger.PostDelinquencyRangeRequest.class)))
+    @ApiResponses({
+            @ApiResponse(responseCode = "200", description = "OK", content = 
@Content(schema = @Schema(implementation = 
DelinquencyApiResourceSwagger.PutDelinquencyRangeResponse.class))) })
+    public String updateDelinquencyRange(
+            @PathParam("delinquencyRangeId") @Parameter(description = 
"delinquencyRangeId") final Long delinquencyRangeId,
+            final String jsonRequestBody, @Context UriInfo uriInfo) {
+        
securityContext.authenticatedUser().validateHasCreatePermission("DELINQUENCY_BUCKET");
+        final CommandWrapper commandRequest = new 
CommandWrapperBuilder().updateDelinquencyRange(delinquencyRangeId)
+                .withJson(jsonRequestBody).build();
+
+        CommandProcessingResult result = 
commandWritePlatformService.logCommandSource(commandRequest);
+        return jsonSerializerRange.serialize(result);
+    }
+
+    @DELETE
+    @Path("ranges/{delinquencyRangeId}")
+    @Consumes({ MediaType.APPLICATION_JSON })
+    @Produces({ MediaType.APPLICATION_JSON })
+    @Operation(summary = "Update Delinquency Range based on the Id", 
description = "")
+    @RequestBody(required = true, content = @Content(schema = 
@Schema(implementation = 
DelinquencyApiResourceSwagger.PostDelinquencyRangeRequest.class)))
+    @ApiResponses({
+            @ApiResponse(responseCode = "200", description = "OK", content = 
@Content(schema = @Schema(implementation = 
DelinquencyApiResourceSwagger.PutDelinquencyRangeResponse.class))) })
+    public String deleteDelinquencyRange(
+            @PathParam("delinquencyRangeId") @Parameter(description = 
"delinquencyRangeId") final Long delinquencyRangeId,
+            @Context UriInfo uriInfo) {
+        
securityContext.authenticatedUser().validateHasCreatePermission("DELINQUENCY_BUCKET");

Review Comment:
   Done! validateHasDeletePermission implemented



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to