FINERACT-2169: Refactor loan COB catch up api controller;
This commit is contained in:
committed by
Adam Saghy
parent
20195464c9
commit
b646ba6ca7
+2
-2
@@ -26,9 +26,9 @@ import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.fineract.client.models.GetOldestCOBProcessedLoanResponse;
|
||||
import org.apache.fineract.client.models.LoanAccountLock;
|
||||
import org.apache.fineract.client.models.LoanAccountLockResponseDTO;
|
||||
import org.apache.fineract.client.models.OldestCOBProcessedLoanDTO;
|
||||
import org.apache.fineract.client.models.PostLoansResponse;
|
||||
import org.apache.fineract.client.services.DefaultApi;
|
||||
import org.apache.fineract.client.services.LoanAccountLockApi;
|
||||
@@ -54,7 +54,7 @@ public class LoanCOBStepDef extends AbstractStepDef {
|
||||
|
||||
@Then("The cobProcessedDate of the oldest loan processed by COB is more than 1 day earlier than cobBusinessDate")
|
||||
public void checkOldestCOBProcessed() throws IOException {
|
||||
Response<GetOldestCOBProcessedLoanResponse> response = loanCobCatchUpApi.getOldestCOBProcessedLoan().execute();
|
||||
Response<OldestCOBProcessedLoanDTO> response = loanCobCatchUpApi.getOldestCOBProcessedLoan().execute();
|
||||
ErrorHelper.checkSuccessfulApiCall(response);
|
||||
|
||||
LocalDate cobDate = response.body().getCobBusinessDate();
|
||||
|
||||
+7
-7
@@ -79,7 +79,7 @@ import org.apache.fineract.client.models.GetLoansLoanIdTransactions;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdTransactionsResponse;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdTransactionsTransactionIdResponse;
|
||||
import org.apache.fineract.client.models.InterestPauseRequestDto;
|
||||
import org.apache.fineract.client.models.IsCatchUpRunningResponse;
|
||||
import org.apache.fineract.client.models.IsCatchUpRunningDTO;
|
||||
import org.apache.fineract.client.models.PaymentAllocationOrder;
|
||||
import org.apache.fineract.client.models.PostClientsResponse;
|
||||
import org.apache.fineract.client.models.PostLoansLoanIdRequest;
|
||||
@@ -2293,19 +2293,19 @@ public class LoanStepDef extends AbstractStepDef {
|
||||
.pollInterval(Duration.ofSeconds(5)) //
|
||||
.pollDelay(Duration.ofSeconds(5)) //
|
||||
.until(() -> {
|
||||
Response<IsCatchUpRunningResponse> isCatchUpRunningResponse = loanCobCatchUpApi.isCatchUpRunning().execute();
|
||||
Response<IsCatchUpRunningDTO> isCatchUpRunningResponse = loanCobCatchUpApi.isCatchUpRunning().execute();
|
||||
ErrorHelper.checkSuccessfulApiCall(isCatchUpRunningResponse);
|
||||
IsCatchUpRunningResponse isCatchUpRunning = isCatchUpRunningResponse.body();
|
||||
return isCatchUpRunning.getIsCatchUpRunning();
|
||||
IsCatchUpRunningDTO isCatchUpRunning = isCatchUpRunningResponse.body();
|
||||
return isCatchUpRunning.getCatchUpRunning();
|
||||
});
|
||||
await().atMost(Duration.ofMinutes(4)) //
|
||||
.pollInterval(Duration.ofSeconds(5)) //
|
||||
.pollDelay(Duration.ofSeconds(5)) //
|
||||
.until(() -> {
|
||||
Response<IsCatchUpRunningResponse> isCatchUpRunningResponse = loanCobCatchUpApi.isCatchUpRunning().execute();
|
||||
Response<IsCatchUpRunningDTO> isCatchUpRunningResponse = loanCobCatchUpApi.isCatchUpRunning().execute();
|
||||
ErrorHelper.checkSuccessfulApiCall(isCatchUpRunningResponse);
|
||||
IsCatchUpRunningResponse isCatchUpRunning = isCatchUpRunningResponse.body();
|
||||
return !isCatchUpRunning.getIsCatchUpRunning();
|
||||
IsCatchUpRunningDTO isCatchUpRunning = isCatchUpRunningResponse.body();
|
||||
return !isCatchUpRunning.getCatchUpRunning();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+22
-41
@@ -19,8 +19,6 @@
|
||||
package org.apache.fineract.cob.api;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -31,41 +29,31 @@ import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.cob.data.IsCatchUpRunningDTO;
|
||||
import org.apache.fineract.cob.data.OldestCOBProcessedLoanDTO;
|
||||
import org.apache.fineract.cob.service.LoanCOBCatchUpService;
|
||||
import org.apache.fineract.infrastructure.core.exception.JobIsNotFoundOrNotEnabledException;
|
||||
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||
import org.apache.fineract.infrastructure.jobs.service.JobName;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Path("/v1/loans")
|
||||
@Component
|
||||
@Tag(name = "Loan COB Catch Up", description = "")
|
||||
@RequiredArgsConstructor
|
||||
public class LoanCOBCatchUpApiResource {
|
||||
|
||||
@Autowired
|
||||
private DefaultToApiJsonSerializer<OldestCOBProcessedLoanDTO> oldestCOBProcessedLoanSerializeService;
|
||||
@Autowired
|
||||
private DefaultToApiJsonSerializer<IsCatchUpRunningDTO> isCatchUpRunningSerializer;
|
||||
@Autowired(required = false)
|
||||
private LoanCOBCatchUpService loanCOBCatchUpService;
|
||||
private final Optional<LoanCOBCatchUpService> loanCOBCatchUpServiceOp;
|
||||
|
||||
@GET
|
||||
@Path("oldest-cob-closed")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Operation(summary = "Retrieves the oldest COB processed loan", description = "Retrieves the COB business date and the oldest COB processed loan")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = LoanCOBCatchUpApiResourceSwagger.GetOldestCOBProcessedLoanResponse.class))) })
|
||||
public String getOldestCOBProcessedLoan() {
|
||||
if (Objects.isNull(loanCOBCatchUpService)) {
|
||||
throw new JobIsNotFoundOrNotEnabledException(JobName.LOAN_COB.name());
|
||||
}
|
||||
OldestCOBProcessedLoanDTO response = loanCOBCatchUpService.getOldestCOBProcessedLoan();
|
||||
return oldestCOBProcessedLoanSerializeService.serialize(response);
|
||||
public OldestCOBProcessedLoanDTO getOldestCOBProcessedLoan() {
|
||||
return loanCOBCatchUpServiceOp.map(LoanCOBCatchUpService::getOldestCOBProcessedLoan)
|
||||
.orElseThrow(() -> new JobIsNotFoundOrNotEnabledException(JobName.LOAN_COB.name()));
|
||||
}
|
||||
|
||||
@POST
|
||||
@@ -77,20 +65,19 @@ public class LoanCOBCatchUpApiResource {
|
||||
@ApiResponse(responseCode = "202", description = "Catch Up has been started"),
|
||||
@ApiResponse(responseCode = "400", description = "Catch Up is already running") })
|
||||
public Response executeLoanCOBCatchUp() {
|
||||
if (Objects.isNull(loanCOBCatchUpService)) {
|
||||
throw new JobIsNotFoundOrNotEnabledException(JobName.LOAN_COB.name());
|
||||
}
|
||||
if (loanCOBCatchUpService.isCatchUpRunning().isCatchUpRunning()) {
|
||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||
}
|
||||
loanCOBCatchUpService.unlockHardLockedLoans();
|
||||
OldestCOBProcessedLoanDTO oldestCOBProcessedLoan = loanCOBCatchUpService.getOldestCOBProcessedLoan();
|
||||
if (oldestCOBProcessedLoan.getCobProcessedDate().equals(oldestCOBProcessedLoan.getCobBusinessDate())) {
|
||||
return Response.status(Response.Status.OK).build();
|
||||
}
|
||||
loanCOBCatchUpService.executeLoanCOBCatchUp();
|
||||
return loanCOBCatchUpServiceOp.map(loanCOBCatchUpService -> {
|
||||
if (loanCOBCatchUpService.isCatchUpRunning().isCatchUpRunning()) {
|
||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||
}
|
||||
loanCOBCatchUpService.unlockHardLockedLoans();
|
||||
OldestCOBProcessedLoanDTO oldestCOBProcessedLoan = loanCOBCatchUpService.getOldestCOBProcessedLoan();
|
||||
|
||||
return Response.status(Response.Status.ACCEPTED).build();
|
||||
if (oldestCOBProcessedLoan.getCobProcessedDate().equals(oldestCOBProcessedLoan.getCobBusinessDate())) {
|
||||
return Response.status(Response.Status.OK).build();
|
||||
}
|
||||
loanCOBCatchUpService.executeLoanCOBCatchUp();
|
||||
return Response.status(Response.Status.ACCEPTED).build();
|
||||
}).orElseThrow(() -> new JobIsNotFoundOrNotEnabledException(JobName.LOAN_COB.name()));
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -98,14 +85,8 @@ public class LoanCOBCatchUpApiResource {
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Operation(summary = "Retrieves whether Loan COB catch up is running", description = "Retrieves whether Loan COB catch up is running, and the current execution date if it is running.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = LoanCOBCatchUpApiResourceSwagger.IsCatchUpRunningResponse.class))) })
|
||||
public String isCatchUpRunning() {
|
||||
if (Objects.isNull(loanCOBCatchUpService)) {
|
||||
throw new JobIsNotFoundOrNotEnabledException(JobName.LOAN_COB.name());
|
||||
}
|
||||
IsCatchUpRunningDTO response = loanCOBCatchUpService.isCatchUpRunning();
|
||||
|
||||
return isCatchUpRunningSerializer.serialize(response);
|
||||
public IsCatchUpRunningDTO isCatchUpRunning() {
|
||||
return loanCOBCatchUpServiceOp.map(LoanCOBCatchUpService::isCatchUpRunning)
|
||||
.orElseThrow(() -> new JobIsNotFoundOrNotEnabledException(JobName.LOAN_COB.name()));
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -21,8 +21,8 @@ package org.apache.fineract.integrationtests.common.loans;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Objects;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.fineract.client.models.GetOldestCOBProcessedLoanResponse;
|
||||
import org.apache.fineract.client.models.IsCatchUpRunningResponse;
|
||||
import org.apache.fineract.client.models.IsCatchUpRunningDTO;
|
||||
import org.apache.fineract.client.models.OldestCOBProcessedLoanDTO;
|
||||
import org.apache.fineract.client.util.Calls;
|
||||
import org.apache.fineract.integrationtests.common.FineractClientHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -34,16 +34,16 @@ public class LoanCOBCatchUpHelper {
|
||||
public LoanCOBCatchUpHelper() {}
|
||||
|
||||
public boolean isLoanCOBCatchUpRunning() {
|
||||
Response<IsCatchUpRunningResponse> response = executeGetLoanCatchUpStatus();
|
||||
return Boolean.TRUE.equals(Objects.requireNonNull(response.body()).getIsCatchUpRunning());
|
||||
Response<IsCatchUpRunningDTO> response = executeGetLoanCatchUpStatus();
|
||||
return Boolean.TRUE.equals(Objects.requireNonNull(response.body()).getCatchUpRunning());
|
||||
}
|
||||
|
||||
public boolean isLoanCOBCatchUpFinishedFor(@NotNull LocalDate cobBusinessDate) {
|
||||
Response<IsCatchUpRunningResponse> response = executeGetLoanCatchUpStatus();
|
||||
IsCatchUpRunningResponse isCatchUpRunningResponse = Objects.requireNonNull(response.body());
|
||||
GetOldestCOBProcessedLoanResponse getOldestCOBProcessedLoanResponse = executeRetrieveOldestCOBProcessedLoan();
|
||||
Response<IsCatchUpRunningDTO> response = executeGetLoanCatchUpStatus();
|
||||
IsCatchUpRunningDTO isCatchUpRunningResponse = Objects.requireNonNull(response.body());
|
||||
OldestCOBProcessedLoanDTO getOldestCOBProcessedLoanResponse = executeRetrieveOldestCOBProcessedLoan();
|
||||
|
||||
return !Boolean.TRUE.equals(isCatchUpRunningResponse.getIsCatchUpRunning())
|
||||
return !Boolean.TRUE.equals(isCatchUpRunningResponse.getCatchUpRunning())
|
||||
&& cobBusinessDate.equals(getOldestCOBProcessedLoanResponse.getCobProcessedDate());
|
||||
}
|
||||
|
||||
@@ -51,11 +51,11 @@ public class LoanCOBCatchUpHelper {
|
||||
return Calls.okR(FineractClientHelper.getFineractClient().loanCobCatchUpApi.executeLoanCOBCatchUp());
|
||||
}
|
||||
|
||||
public GetOldestCOBProcessedLoanResponse executeRetrieveOldestCOBProcessedLoan() {
|
||||
public OldestCOBProcessedLoanDTO executeRetrieveOldestCOBProcessedLoan() {
|
||||
return Calls.ok(FineractClientHelper.getFineractClient().loanCobCatchUpApi.getOldestCOBProcessedLoan());
|
||||
}
|
||||
|
||||
public Response<IsCatchUpRunningResponse> executeGetLoanCatchUpStatus() {
|
||||
public Response<IsCatchUpRunningDTO> executeGetLoanCatchUpStatus() {
|
||||
return Calls.okR(FineractClientHelper.getFineractClient().loanCobCatchUpApi.isCatchUpRunning());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user