FINERACT-2169: Refactor loan account api controller;
This commit is contained in:
committed by
Adam Saghy
parent
993393b519
commit
3aa011b32e
+3
-3
@@ -28,8 +28,8 @@ import java.util.stream.Collectors;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.fineract.client.models.BatchResponse;
|
||||
import org.apache.fineract.client.models.GetJournalEntriesTransactionIdResponse;
|
||||
import org.apache.fineract.client.models.GetLoanAccountLockResponse;
|
||||
import org.apache.fineract.client.models.Header;
|
||||
import org.apache.fineract.client.models.LoanAccountLockResponseDTO;
|
||||
import retrofit2.Response;
|
||||
|
||||
public final class ErrorMessageHelper {
|
||||
@@ -680,12 +680,12 @@ public final class ErrorMessageHelper {
|
||||
expectedStr);
|
||||
}
|
||||
|
||||
public static String listOfLockedLoansNotEmpty(Response<GetLoanAccountLockResponse> response) {
|
||||
public static String listOfLockedLoansNotEmpty(Response<LoanAccountLockResponseDTO> response) {
|
||||
String bodyStr = response.body().toString();
|
||||
return String.format("List of locked loan accounts is not empty. Actual response is: %n%s", bodyStr);
|
||||
}
|
||||
|
||||
public static String listOfLockedLoansContainsLoan(Long loanId, Response<GetLoanAccountLockResponse> response) {
|
||||
public static String listOfLockedLoansContainsLoan(Long loanId, Response<LoanAccountLockResponseDTO> response) {
|
||||
String bodyStr = response.body().toString();
|
||||
return String.format("List of locked loan accounts contains the loan with loanId %s. List of locked loans: %n%s", loanId, bodyStr);
|
||||
}
|
||||
|
||||
+3
-3
@@ -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.GetLoanAccountLockResponse;
|
||||
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.PostLoansResponse;
|
||||
import org.apache.fineract.client.services.DefaultApi;
|
||||
import org.apache.fineract.client.services.LoanAccountLockApi;
|
||||
@@ -69,7 +69,7 @@ public class LoanCOBStepDef extends AbstractStepDef {
|
||||
|
||||
@Then("There are no locked loan accounts")
|
||||
public void listOfLockedLoansEmpty() throws IOException {
|
||||
Response<GetLoanAccountLockResponse> response = loanAccountLockApi.retrieveLockedAccounts(0, 1000).execute();
|
||||
Response<LoanAccountLockResponseDTO> response = loanAccountLockApi.retrieveLockedAccounts(0, 1000).execute();
|
||||
ErrorHelper.checkSuccessfulApiCall(response);
|
||||
|
||||
int size = response.body().getContent().size();
|
||||
@@ -82,7 +82,7 @@ public class LoanCOBStepDef extends AbstractStepDef {
|
||||
Response<PostLoansResponse> loanResponse = testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
|
||||
Long targetLoanId = loanResponse.body().getLoanId();
|
||||
|
||||
Response<GetLoanAccountLockResponse> response = loanAccountLockApi.retrieveLockedAccounts(0, 1000).execute();
|
||||
Response<LoanAccountLockResponseDTO> response = loanAccountLockApi.retrieveLockedAccounts(0, 1000).execute();
|
||||
ErrorHelper.checkSuccessfulApiCall(response);
|
||||
|
||||
List<LoanAccountLock> content = response.body().getContent();
|
||||
|
||||
+2
-30
@@ -19,31 +19,17 @@
|
||||
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;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.QueryParam;
|
||||
import jakarta.ws.rs.core.Context;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.UriInfo;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.cob.data.LoanAccountLockResponseDTO;
|
||||
import org.apache.fineract.cob.domain.LoanAccountLock;
|
||||
import org.apache.fineract.cob.service.LoanAccountLockService;
|
||||
import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper;
|
||||
import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Path("/v1/loans")
|
||||
@@ -52,32 +38,18 @@ import org.springframework.stereotype.Component;
|
||||
@RequiredArgsConstructor
|
||||
public class LoanAccountLockApiResource {
|
||||
|
||||
private static final Set<String> LOAN_ACCOUNT_LOCK_RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList("page", "limit", "content"));
|
||||
|
||||
private final LoanAccountLockService loanAccountLockService;
|
||||
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||
private final DefaultToApiJsonSerializer<LoanAccountLockResponseDTO> businessStepConfigSerializeService;
|
||||
|
||||
@GET
|
||||
@Path("locked")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Operation(summary = "List locked loan accounts", description = "Returns the locked loan IDs")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = LoanAccountLockApiResourceSwagger.GetLoanAccountLockResponse.class))) })
|
||||
public String retrieveLockedAccounts(@Context final UriInfo uriInfo, @QueryParam("page") Integer pageParam,
|
||||
public LoanAccountLockResponseDTO retrieveLockedAccounts(@QueryParam("page") Integer pageParam,
|
||||
@QueryParam("limit") Integer limitParam) {
|
||||
int page = Objects.requireNonNullElse(pageParam, 0);
|
||||
int limit = Objects.requireNonNullElse(limitParam, 50);
|
||||
|
||||
List<LoanAccountLock> lockedLoanAccounts = loanAccountLockService.getLockedLoanAccountByPage(page, limit);
|
||||
LoanAccountLockResponseDTO response = new LoanAccountLockResponseDTO();
|
||||
response.setPage(page);
|
||||
response.setLimit(limit);
|
||||
response.setContent(lockedLoanAccounts);
|
||||
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
|
||||
return businessStepConfigSerializeService.serialize(settings, response, LOAN_ACCOUNT_LOCK_RESPONSE_DATA_PARAMETERS);
|
||||
return new LoanAccountLockResponseDTO(page, limit, loanAccountLockService.getLockedLoanAccountByPage(page, limit));
|
||||
}
|
||||
}
|
||||
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
/**
|
||||
* 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.cob.api;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.util.List;
|
||||
import org.apache.fineract.cob.domain.LoanAccountLock;
|
||||
|
||||
final class LoanAccountLockApiResourceSwagger {
|
||||
|
||||
private LoanAccountLockApiResourceSwagger() {
|
||||
|
||||
}
|
||||
|
||||
@Schema(description = "GetLoanAccountLockResponse")
|
||||
public static final class GetLoanAccountLockResponse {
|
||||
|
||||
private GetLoanAccountLockResponse() {}
|
||||
|
||||
public int page;
|
||||
public int limit;
|
||||
public List<LoanAccountLock> content;
|
||||
|
||||
}
|
||||
}
|
||||
+10
-1
@@ -18,12 +18,21 @@
|
||||
*/
|
||||
package org.apache.fineract.cob.data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.fineract.cob.domain.LoanAccountLock;
|
||||
|
||||
@Data
|
||||
public class LoanAccountLockResponseDTO {
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class LoanAccountLockResponseDTO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private int page;
|
||||
private int limit;
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@ import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import org.apache.fineract.client.models.GetLoanAccountLockResponse;
|
||||
import org.apache.fineract.client.models.LoanAccountLockResponseDTO;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.accounting.Account;
|
||||
@@ -86,7 +86,7 @@ public class ClientLoanAccountLockIntegrationTest {
|
||||
|
||||
loanAccountLockHelper.placeSoftLockOnLoanAccount(loanID, "LOAN_INLINE_COB_PROCESSING", "Sample error");
|
||||
|
||||
GetLoanAccountLockResponse getLoanAccountLockResponse = clientHelper.retrieveLockedAccounts(0, 1000);
|
||||
LoanAccountLockResponseDTO getLoanAccountLockResponse = clientHelper.retrieveLockedAccounts(0, 1000);
|
||||
Assertions.assertTrue(getLoanAccountLockResponse.getContent().size() > 0);
|
||||
Assertions.assertTrue(getLoanAccountLockResponse.getContent().stream()
|
||||
.anyMatch(loanAccountLock -> loanAccountLock.getLoanId().equals(Long.valueOf(loanID))));
|
||||
|
||||
+2
-2
@@ -46,8 +46,8 @@ import org.apache.fineract.client.models.GetClientsClientIdAccountsResponse;
|
||||
import org.apache.fineract.client.models.GetClientsClientIdResponse;
|
||||
import org.apache.fineract.client.models.GetClientsClientIdTransactionsResponse;
|
||||
import org.apache.fineract.client.models.GetClientsClientIdTransactionsTransactionIdResponse;
|
||||
import org.apache.fineract.client.models.GetLoanAccountLockResponse;
|
||||
import org.apache.fineract.client.models.GetObligeeData;
|
||||
import org.apache.fineract.client.models.LoanAccountLockResponseDTO;
|
||||
import org.apache.fineract.client.models.PageClientSearchData;
|
||||
import org.apache.fineract.client.models.PagedRequestClientTextSearch;
|
||||
import org.apache.fineract.client.models.PostClientClientIdAddressesRequest;
|
||||
@@ -1215,7 +1215,7 @@ public class ClientHelper {
|
||||
.activationDate(DEFAULT_DATE);
|
||||
}
|
||||
|
||||
public GetLoanAccountLockResponse retrieveLockedAccounts(int page, int limit) {
|
||||
public LoanAccountLockResponseDTO retrieveLockedAccounts(int page, int limit) {
|
||||
return Calls.ok(FineractClientHelper.getFineractClient().loanAccountLockApi.retrieveLockedAccounts(page, limit));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user