FINERACT-2169: Batches api refactor;

This commit is contained in:
viktorpavlenko
2025-03-11 18:03:43 +00:00
committed by Adam Saghy
parent 8371e162ba
commit cc0c09df60
@@ -42,10 +42,8 @@ import java.util.Optional;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.domain.BatchRequest; import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse; import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.batch.serialization.BatchRequestJsonHelper;
import org.apache.fineract.batch.service.BatchApiService; import org.apache.fineract.batch.service.BatchApiService;
import org.apache.fineract.infrastructure.core.config.FineractProperties; import org.apache.fineract.infrastructure.core.config.FineractProperties;
import org.apache.fineract.infrastructure.core.serialization.ToApiJsonSerializer;
import org.apache.fineract.infrastructure.security.exception.InvalidInstanceTypeMethodException; import org.apache.fineract.infrastructure.security.exception.InvalidInstanceTypeMethodException;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -76,15 +74,13 @@ import org.springframework.stereotype.Component;
public class BatchApiResource { public class BatchApiResource {
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
private final ToApiJsonSerializer<BatchResponse> toApiJsonSerializer;
private final BatchApiService service; private final BatchApiService service;
private final BatchRequestJsonHelper batchRequestJsonHelper;
private final FineractProperties fineractProperties; private final FineractProperties fineractProperties;
/** /**
* Rest assured POST method to get {@link BatchRequest} and returns back the consolidated {@link BatchResponse} * Rest assured POST method to get {@link BatchRequest} and returns back the consolidated {@link BatchResponse}
* *
* @param jsonRequestString * @param requestList
* @param enclosingTransaction * @param enclosingTransaction
* @param uriInfo * @param uriInfo
* @return serialized JSON * @return serialized JSON
@@ -98,30 +94,16 @@ public class BatchApiResource {
@RequestBody(required = true, content = @Content(array = @ArraySchema(schema = @Schema(implementation = BatchRequest.class, description = "request body")))) @RequestBody(required = true, content = @Content(array = @ArraySchema(schema = @Schema(implementation = BatchRequest.class, description = "request body"))))
@ApiResponses({ @ApiResponses({
@ApiResponse(responseCode = "200", description = "Success", content = @Content(array = @ArraySchema(schema = @Schema(implementation = BatchResponse.class)))) }) @ApiResponse(responseCode = "200", description = "Success", content = @Content(array = @ArraySchema(schema = @Schema(implementation = BatchResponse.class)))) })
public String handleBatchRequests( public List<BatchResponse> handleBatchRequests(
@DefaultValue("false") @QueryParam("enclosingTransaction") @Parameter(description = "enclosingTransaction", required = false) final boolean enclosingTransaction, @DefaultValue("false") @QueryParam("enclosingTransaction") @Parameter(description = "enclosingTransaction", required = false) final boolean enclosingTransaction,
@Parameter(hidden = true) final String jsonRequestString, @Context UriInfo uriInfo) { @Parameter(hidden = true) List<BatchRequest> requestList, @Context UriInfo uriInfo) {
// Handles user authentication
this.context.authenticatedUser(); this.context.authenticatedUser();
// Converts request array into BatchRequest List // Converts request array into BatchRequest List
final List<BatchRequest> requestList = this.batchRequestJsonHelper.extractList(jsonRequestString);
validateRequestMethodsAllowedOnInstanceType(requestList); validateRequestMethodsAllowedOnInstanceType(requestList);
// Gets back the consolidated BatchResponse from BatchApiservice
List<BatchResponse> result;
// If the request is to be handled as a Transaction. All requests will // If the request is to be handled as a Transaction. All requests will
// be rolled back on error // be rolled back on error
if (enclosingTransaction) { return enclosingTransaction ? service.handleBatchRequestsWithEnclosingTransaction(requestList, uriInfo)
result = service.handleBatchRequestsWithEnclosingTransaction(requestList, uriInfo); : service.handleBatchRequestsWithoutEnclosingTransaction(requestList, uriInfo);
} else {
result = service.handleBatchRequestsWithoutEnclosingTransaction(requestList, uriInfo);
}
return this.toApiJsonSerializer.serialize(result);
} }