From 36a8badb472e14b687eeb8d9be99a49dd6e47042 Mon Sep 17 00:00:00 2001 From: elnafateh Date: Tue, 7 Jul 2026 13:36:40 +0100 Subject: [PATCH] FINERACT-2165: migrate AuditHelper to Feign client --- .../commands/api/AuditsApiResource.java | 4 + .../api/AuditsApiResourceSwagger.java | 38 ++++ .../InternalLoanInformationApiResource.java | 12 +- .../AuditIntegrationTest.java | 54 +++--- .../IpTrackingIntegrationTest.java | 8 +- .../integrationtests/MakercheckerTest.java | 3 - .../integrationtests/common/AuditHelper.java | 177 ++++++++++-------- 7 files changed, 173 insertions(+), 123 deletions(-) create mode 100644 fineract-provider/src/main/java/org/apache/fineract/commands/api/AuditsApiResourceSwagger.java diff --git a/fineract-provider/src/main/java/org/apache/fineract/commands/api/AuditsApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/commands/api/AuditsApiResource.java index b2387ba6795..055bd0c9972 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/commands/api/AuditsApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/commands/api/AuditsApiResource.java @@ -20,6 +20,9 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; +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.tags.Tag; import jakarta.ws.rs.BeanParam; import jakarta.ws.rs.GET; @@ -66,6 +69,7 @@ public class AuditsApiResource { + "\n" + "Example Requests:\n" + "\n" + "audits\n" + "\n" + "audits?fields=madeOnDate,maker,processingResult\n" + "\n" + "audits?makerDateTimeFrom=2013-03-25 08:00:00&makerDateTimeTo=2013-04-04 18:00:00\n" + "\n" + "audits?officeId=1\n" + "\n" + "audits?officeId=1&includeJson=true") + @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = AuditsApiResourceSwagger.PageGetAuditsResponse.class))) public String retrieveAuditEntries(@Context final UriInfo uriInfo, @BeanParam AuditRequest auditRequest, @QueryParam("offset") @Parameter(description = "offset") final Integer offset, @QueryParam("limit") @Parameter(description = "limit") final Integer limit, diff --git a/fineract-provider/src/main/java/org/apache/fineract/commands/api/AuditsApiResourceSwagger.java b/fineract-provider/src/main/java/org/apache/fineract/commands/api/AuditsApiResourceSwagger.java new file mode 100644 index 00000000000..d2d00973200 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/commands/api/AuditsApiResourceSwagger.java @@ -0,0 +1,38 @@ +/** + * 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.commands.api; + +import io.swagger.v3.oas.annotations.media.Schema; +import java.util.List; +import org.apache.fineract.commands.data.AuditData; + +final class AuditsApiResourceSwagger { + + private AuditsApiResourceSwagger() {} + + @Schema(description = "PageGetAuditsResponse") + public static final class PageGetAuditsResponse { + + private PageGetAuditsResponse() {} + + @Schema(example = "1") + public Integer totalFilteredRecords; + public List pageItems; + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/InternalLoanInformationApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/InternalLoanInformationApiResource.java index 705936ff2f7..328b19ee9a8 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/InternalLoanInformationApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/api/InternalLoanInformationApiResource.java @@ -72,7 +72,7 @@ public void afterPropertiesSet() { @Path("{loanId}/audit") @Produces({ MediaType.APPLICATION_JSON }) @SuppressFBWarnings("SLF4J_SIGN_ONLY_FORMAT") - public AuditData getLoanAuditFields(@Context final UriInfo uriInfo, @PathParam("loanId") Long loanId) { + public LoanAuditFieldsData getLoanAuditFields(@Context final UriInfo uriInfo, @PathParam("loanId") Long loanId) { log.warn("------------------------------------------------------------"); log.warn(" "); log.warn("Fetching loan with {}", loanId); @@ -80,15 +80,15 @@ public AuditData getLoanAuditFields(@Context final UriInfo uriInfo, @PathParam(" log.warn("------------------------------------------------------------"); final Loan loan = loanRepositoryWrapper.findOneWithNotFoundDetection(loanId); - return new AuditData(loan.getCreatedBy().orElse(null), loan.getCreatedDate().orElse(null), loan.getLastModifiedBy().orElse(null), - loan.getLastModifiedDate().orElse(null)); + return new LoanAuditFieldsData(loan.getCreatedBy().orElse(null), loan.getCreatedDate().orElse(null), + loan.getLastModifiedBy().orElse(null), loan.getLastModifiedDate().orElse(null)); } @GET @Path("{loanId}/transaction/{transactionId}/audit") @Produces({ MediaType.APPLICATION_JSON }) @SuppressFBWarnings("SLF4J_SIGN_ONLY_FORMAT") - public AuditData getLoanTransactionAuditFields(@Context final UriInfo uriInfo, @PathParam("loanId") Long loanId, + public LoanAuditFieldsData getLoanTransactionAuditFields(@Context final UriInfo uriInfo, @PathParam("loanId") Long loanId, @PathParam("transactionId") Long transactionId) { log.warn("------------------------------------------------------------"); log.warn(" "); @@ -97,7 +97,7 @@ public AuditData getLoanTransactionAuditFields(@Context final UriInfo uriInfo, @ log.warn("------------------------------------------------------------"); final LoanTransaction transaction = loanTransactionRepository.findById(transactionId).orElseThrow(); - return new AuditData(transaction.getCreatedBy().orElse(null), transaction.getCreatedDate().orElse(null), + return new LoanAuditFieldsData(transaction.getCreatedBy().orElse(null), transaction.getCreatedDate().orElse(null), transaction.getLastModifiedBy().orElse(null), transaction.getLastModifiedDate().orElse(null)); } @@ -145,6 +145,6 @@ public LocalDate getMaxTransactionDateOfActiveLoans() { return loanRepositoryWrapper.findMaxTransactionDateOfActiveLoans(); } - private record AuditData(Long createdBy, OffsetDateTime createdDate, Long lastModifiedBy, OffsetDateTime lastModifiedDate) { + private record LoanAuditFieldsData(Long createdBy, OffsetDateTime createdDate, Long lastModifiedBy, OffsetDateTime lastModifiedDate) { } } diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/AuditIntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/AuditIntegrationTest.java index 6dfefdbf47e..1ddeef2ae69 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/AuditIntegrationTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/AuditIntegrationTest.java @@ -30,9 +30,9 @@ import io.restassured.specification.ResponseSpecification; import java.security.SecureRandom; import java.util.Arrays; -import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.List; +import org.apache.fineract.client.models.AuditData; +import org.apache.fineract.client.models.AuditSearchData; import org.apache.fineract.integrationtests.common.AuditHelper; import org.apache.fineract.integrationtests.common.ClientHelper; import org.apache.fineract.integrationtests.common.OfficeHelper; @@ -51,7 +51,6 @@ public class AuditIntegrationTest { private ResponseSpecification responseSpec; private RequestSpecification requestSpec; private ClientHelper clientHelper; - private AuditHelper auditHelper; private SchedulerJobHelper schedulerJobHelper; private static final SecureRandom rand = new SecureRandom(); @@ -65,7 +64,6 @@ public void setup() { this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); - this.auditHelper = new AuditHelper(this.requestSpec, this.responseSpec); this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec); this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec); } @@ -74,19 +72,17 @@ public void setup() { public void testAuditSearchTemplate() { // given // when - LinkedHashMap auditSearchTemplate = this.auditHelper.getAuditSearchTemplate(); + AuditSearchData auditSearchTemplate = AuditHelper.getAuditSearchTemplate(); // then assertNotNull(auditSearchTemplate); - assertEquals(4, auditSearchTemplate.size()); // appUsers, actionNames, entityNames, processingResults - assertTrue(((List) auditSearchTemplate.get("actionNames")).size() > 0); + assertTrue(auditSearchTemplate.getActionNames().size() > 0); // verify all command processing status enum values are present and use enum_value (not enum_message_property) - List statuses = (List) auditSearchTemplate.get("statuses"); - assertNotNull(statuses); - assertEquals(6, statuses.size()); + assertNotNull(auditSearchTemplate.getStatuses()); + assertEquals(6, auditSearchTemplate.getStatuses().size()); - List statusValues = statuses.stream().map(r -> (String) r.get("processingResult")) + List statusValues = auditSearchTemplate.getStatuses().stream().map(r -> r.getProcessingResult()) .collect(java.util.stream.Collectors.toList()); assertTrue(statusValues.contains("Invalid")); @@ -101,44 +97,43 @@ public void testAuditSearchTemplate() { * Here we Create/Update different Entities and verify an audit is generated for each action. This can be further * extened with more entities and actions in similiar way. */ - @SuppressWarnings("unchecked") @Test public void auditShouldbeCreated() { // Audits recieved after all actions are performed. - List> auditsRecieved; + List auditsRecieved; // Audits recieved before any action is performed, needed in special // cases eg: reactivate client, close client - List> auditsRecievedInitial; + List auditsRecievedInitial; // When Client is created: Count should be "1" final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientId); - auditsRecieved = auditHelper.getAuditDetails(clientId, "CREATE", "CLIENT"); - auditHelper.verifyOneAuditOnly(auditsRecieved, clientId, "CREATE", "CLIENT"); + auditsRecieved = AuditHelper.getAuditDetails(clientId, "CREATE", "CLIENT"); + AuditHelper.verifyOneAuditOnly(auditsRecieved, clientId, "CREATE", "CLIENT"); // Performs multiple close and reactivate on client for (int i = 0; i < 4; i++) { // Close - auditsRecievedInitial = auditHelper.getAuditDetails(clientId, "CLOSE", "CLIENT"); + auditsRecievedInitial = AuditHelper.getAuditDetails(clientId, "CLOSE", "CLIENT"); this.clientHelper.closeClient(clientId); - auditsRecieved = auditHelper.getAuditDetails(clientId, "CLOSE", "CLIENT"); - auditHelper.verifyMultipleAuditsOnserver(auditsRecievedInitial, auditsRecieved, clientId, "CLOSE", "CLIENT"); + auditsRecieved = AuditHelper.getAuditDetails(clientId, "CLOSE", "CLIENT"); + AuditHelper.verifyMultipleAuditsOnserver(auditsRecievedInitial, auditsRecieved, clientId, "CLOSE", "CLIENT"); // Activate - auditsRecievedInitial = auditHelper.getAuditDetails(clientId, "REACTIVATE", "CLIENT"); + auditsRecievedInitial = AuditHelper.getAuditDetails(clientId, "REACTIVATE", "CLIENT"); this.clientHelper.reactivateClient(clientId); - auditsRecieved = auditHelper.getAuditDetails(clientId, "REACTIVATE", "CLIENT"); - auditHelper.verifyMultipleAuditsOnserver(auditsRecievedInitial, auditsRecieved, clientId, "REACTIVATE", "CLIENT"); + auditsRecieved = AuditHelper.getAuditDetails(clientId, "REACTIVATE", "CLIENT"); + AuditHelper.verifyMultipleAuditsOnserver(auditsRecievedInitial, auditsRecieved, clientId, "REACTIVATE", "CLIENT"); } // When Office is created OfficeHelper officeHelper = new OfficeHelper(); int officeId = officeHelper.createOffice(java.time.LocalDate.of(2020, 6, 22)).getResourceId().intValue(); - auditsRecieved = auditHelper.getAuditDetails(officeId, "CREATE", "OFFICE"); - auditHelper.verifyOneAuditOnly(auditsRecieved, officeId, "CREATE", "OFFICE"); + auditsRecieved = AuditHelper.getAuditDetails(officeId, "CREATE", "OFFICE"); + AuditHelper.verifyOneAuditOnly(auditsRecieved, officeId, "CREATE", "OFFICE"); } @Test @@ -159,7 +154,7 @@ public void checkAuditsWithLimitParam() { for (int i = 0; i < 3; i++) { // limit contains a number between 1-8 int limit = rand.nextInt(7) + 1; - auditHelper.verifyLimitParameterfor(limit); + AuditHelper.verifyLimitParameterfor(limit); } } @@ -170,24 +165,23 @@ public void checkIfOrderBySupported() { "madeOnDate", "id", "loanId", "actionName"); for (int i = 0; i < shouldBeSupportedFor.size(); i++) { - auditHelper.verifyOrderBysupported(shouldBeSupportedFor.get(i)); + AuditHelper.verifyOrderBysupported(shouldBeSupportedFor.get(i)); } } - @SuppressWarnings("unchecked") @Test public void executeSchedulerJobShouldCreateAuditEntry() { // given int jobId = schedulerJobHelper.getSchedulerJobIdByShortName("SA_AANF").intValue(); - List> auditsRecievedInitial = auditHelper.getAuditDetails(jobId, "EXECUTEJOB", "SCHEDULER"); + List auditsRecievedInitial = AuditHelper.getAuditDetails(jobId, "EXECUTEJOB", "SCHEDULER"); // when schedulerJobHelper.runSchedulerJob(jobId); // then - List> auditsRecieved = auditHelper.getAuditDetails(jobId, "EXECUTEJOB", "SCHEDULER"); - auditHelper.verifyMultipleAuditsOnserver(auditsRecievedInitial, auditsRecieved, jobId, "EXECUTEJOB", "SCHEDULER"); + List auditsRecieved = AuditHelper.getAuditDetails(jobId, "EXECUTEJOB", "SCHEDULER"); + AuditHelper.verifyMultipleAuditsOnserver(auditsRecievedInitial, auditsRecieved, jobId, "EXECUTEJOB", "SCHEDULER"); } } diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/IpTrackingIntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/IpTrackingIntegrationTest.java index 99339be4bdc..0e7bff6673f 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/IpTrackingIntegrationTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/IpTrackingIntegrationTest.java @@ -26,8 +26,8 @@ import io.restassured.http.ContentType; import io.restassured.specification.RequestSpecification; import io.restassured.specification.ResponseSpecification; -import java.util.HashMap; import java.util.List; +import org.apache.fineract.client.models.AuditData; import org.apache.fineract.integrationtests.common.AuditHelper; import org.apache.fineract.integrationtests.common.ClientHelper; import org.apache.fineract.integrationtests.common.Utils; @@ -36,7 +36,6 @@ public class IpTrackingIntegrationTest { - private AuditHelper auditHelper; private static final String EXPECTED_LOCAL_IP = "127.0.0.1"; private RequestSpecification requestSpec; private ResponseSpecification responseSpec; @@ -50,7 +49,6 @@ public void setup() { this.requestSpec.auth().basic("mifos", "password"); this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); this.responseSpecForSearch = new ResponseSpecBuilder().expectStatusCode(200).build(); - this.auditHelper = new AuditHelper(this.requestSpec, this.responseSpec); } @Test @@ -61,10 +59,10 @@ public void capturesIpAddressWhenCreatingClient() throws Exception { // given final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientId); - List> auditsRecieved = auditHelper.getAuditDetails(clientId, "CREATE", "CLIENT"); + List auditsRecieved = AuditHelper.getAuditDetails(clientId, "CREATE", "CLIENT"); // when - String ip = auditsRecieved.get(0).get("ip").toString(); + String ip = auditsRecieved.get(0).getIp(); assumeTrue(!ip.isEmpty(), "IP not arrived: skipping capture test when enabled"); // then diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/MakercheckerTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/MakercheckerTest.java index a6a92a64158..879543f5102 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/MakercheckerTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/MakercheckerTest.java @@ -33,7 +33,6 @@ import org.apache.fineract.client.models.PutGlobalConfigurationsRequest; import org.apache.fineract.client.models.PutPermissionsRequest; import org.apache.fineract.infrastructure.configuration.api.GlobalConfigurationConstants; -import org.apache.fineract.integrationtests.common.AuditHelper; import org.apache.fineract.integrationtests.common.ClientHelper; import org.apache.fineract.integrationtests.common.CommonConstants; import org.apache.fineract.integrationtests.common.FineractClientHelper; @@ -58,7 +57,6 @@ public class MakercheckerTest { private RequestSpecification requestSpec; private MakercheckersHelper makercheckersHelper; private RolesHelper rolesHelper; - private AuditHelper auditHelper; private SavingsProductHelper savingsProductHelper; private SavingsAccountHelper savingsAccountHelper; private static final String START_DATE_STRING = "03 June 2023"; @@ -73,7 +71,6 @@ public void setup() { this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); this.makercheckersHelper = new MakercheckersHelper(this.requestSpec, this.responseSpec); this.rolesHelper = new RolesHelper(); - this.auditHelper = new AuditHelper(requestSpec, responseSpec); this.savingsProductHelper = new SavingsProductHelper(); this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); this.globalConfigurationHelper = new GlobalConfigurationHelper(); diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/AuditHelper.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/AuditHelper.java index fdeaba6c7b1..7fba415ead8 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/AuditHelper.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/AuditHelper.java @@ -18,17 +18,14 @@ */ package org.apache.fineract.integrationtests.common; +import static org.apache.fineract.client.feign.util.FeignCalls.ok; import static org.junit.jupiter.api.Assertions.assertEquals; -import com.google.gson.Gson; -import io.restassured.specification.RequestSpecification; -import io.restassured.specification.ResponseSpecification; import java.util.Collections; import java.util.Comparator; -import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.List; -import org.apache.fineract.client.util.JSON; +import org.apache.fineract.client.models.AuditData; +import org.apache.fineract.client.models.AuditSearchData; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,110 +34,132 @@ * @author Manthan Surkar * */ +public final class AuditHelper { -public class AuditHelper { + private AuditHelper() { - private static final Logger LOG = LoggerFactory.getLogger(AuditHelper.class); - private static final String AUDIT_BASE_URL = "/fineract-provider/api/v1/audits?" + Utils.TENANT_IDENTIFIER; - private static final String AUDITSEARCH_BASE_URL = "/fineract-provider/api/v1/audits/searchtemplate?" + Utils.TENANT_IDENTIFIER; - - private static final Gson GSON = new JSON().getGson(); - - private ResponseSpecification responseSpec; - private RequestSpecification requestSpec; - - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public AuditHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { - this.requestSpec = requestSpec; - this.responseSpec = responseSpec; } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public List getAuditDetails(final Integer resourceId, final String actionName, final String entityName) { - final String AUDIT_URL = AUDIT_BASE_URL + "&entityName=" + entityName + "&resourceId=" + resourceId + "&actionName=" + actionName - + "&orderBy=id&sortBy=DSC"; - List> responseAudits = Utils.performServerGet(requestSpec, responseSpec, AUDIT_URL, ""); - return responseAudits; + private static final Logger LOG = LoggerFactory.getLogger(AuditHelper.class); + + public static List getAuditDetails(final Integer resourceId, final String actionName, final String entityName) { + return ok(() -> FineractFeignClientHelper.getFineractFeignClient().audits().retrieveAuditEntries(actionName, // actionName + entityName, // entityName + resourceId == null ? null : resourceId.longValue(), // resourceId + null, // makerId + null, // makerDateTimeFrom + null, // makerDateTimeTo + null, // checkerId + null, // checkerDateTimeFrom + null, // checkerDateTimeTo + null, // status + null, // clientId + null, // loanId + null, // officeId + null, // groupId + null, // savingsAccountId + null, // processingResult + null, // dateFormat + null, // locale + null, // offset + null, // limit + "id", // orderBy + "DESC", // sortOrder + true // paged + )).getPageItems(); } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public List getAuditDetails(final int limit) { - final String AUDIT_URL = AUDIT_BASE_URL + "&paged=true&limit=" + Integer.toString(limit); - LinkedHashMap responseAudits = Utils.performServerGet(requestSpec, responseSpec, AUDIT_URL, ""); - return (List) responseAudits.get("pageItems"); + public static List getAuditDetails(final int limit) { + return ok(() -> FineractFeignClientHelper.getFineractFeignClient().audits().retrieveAuditEntries(null, // actionName + null, // entityName + null, // resourceId + null, // makerId + null, // makerDateTimeFrom + null, // makerDateTimeTo + null, // checkerId + null, // checkerDateTimeFrom + null, // checkerDateTimeTo + null, // status + null, // clientId + null, // loanId + null, // officeId + null, // groupId + null, // savingsAccountId + null, // processingResult + null, // dateFormat + null, // locale + null, // offset + limit, // limit + null, // orderBy + null, // sortOrder + true // paged + )).getPageItems(); } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public LinkedHashMap getAuditSearchTemplate() { - return Utils.performServerGet(requestSpec, responseSpec, AUDITSEARCH_BASE_URL, "$"); + public static AuditSearchData getAuditSearchTemplate() { + return ok(() -> FineractFeignClientHelper.getFineractFeignClient().audits().retrieveAuditSearchTemplate()); } /** * Some audit actions can only be done once Eg: Creation of a client with id 123, hence we verify number of audits * For such operations is "equal" to 1 always */ - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public void verifyOneAuditOnly(List> auditsToCheck, Integer id, String actionName, String entityType) { + public static void verifyOneAuditOnly(final List auditsToCheck, final Integer id, final String actionName, + final String entityType) { LOG.info("------------------------------CHECK IF AUDIT CREATED------------------------------------\n"); assertEquals(1, auditsToCheck.size(), "More than one audit created"); - HashMap auditToCheck = auditsToCheck.get(0); - String actual = auditToCheck.get("actionName").toString() + " is done on " + auditToCheck.get("entityName").toString() + " with id " - + auditToCheck.get("resourceId").toString(); - String expected = actionName + " is done on " + entityType + " with id " + id; + final AuditData auditToCheck = auditsToCheck.get(0); + final String actual = auditToCheck.getActionName() + " is done on " + auditToCheck.getEntityName() + " with id " + + auditToCheck.getResourceId(); + final String expected = actionName + " is done on " + entityType + " with id " + id; assertEquals(expected, actual, "Error in creating audit!"); } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public void verifyMultipleAuditsOnserver(List> auditsRecievedInitial, - List> auditsRecieved, Integer id, String actionName, String entityType) { + public static void verifyMultipleAuditsOnserver(final List auditsRecievedInitial, final List auditsRecieved, + final Integer id, final String actionName, final String entityType) { LOG.info("------------------------------CHECK IF AUDIT CREATED------------------------------------\n"); assertEquals(auditsRecievedInitial.size() + 1, auditsRecieved.size(), "Audit is not Created"); - Comparator> compareById = (HashMap a, HashMap b) -> a.get("id").toString() - .compareTo(b.get("id").toString()); + final Comparator compareById = Comparator.comparing(AuditData::getId); Collections.sort(auditsRecieved, compareById.reversed()); // First element is new audit created(Sorted DESC by Id) - HashMap auditToCheck = auditsRecieved.get(0); - String actual = auditToCheck.get("actionName").toString() + " is done on " + auditToCheck.get("entityName").toString() + " with id " - + auditToCheck.get("resourceId").toString(); - String expected = actionName + " is done on " + entityType + " with id " + id; + final AuditData auditToCheck = auditsRecieved.get(0); + final String actual = auditToCheck.getActionName() + " is done on " + auditToCheck.getEntityName() + " with id " + + auditToCheck.getResourceId(); + final String expected = actionName + " is done on " + entityType + " with id " + id; assertEquals(expected, actual, "Error in creating audit!"); } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public void verifyLimitParameterfor(final int limit) { + public static void verifyLimitParameterfor(final int limit) { assertEquals(limit, getAuditDetails(limit).size(), "Incorrect number of audits recieved for limit: " + Integer.toString(limit)); } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public void verifyOrderBysupported(final String orderByValue) { - final String AUDIT_URL = AUDIT_BASE_URL + "&paged=true&orderBy=" + orderByValue; - Utils.performServerGet(requestSpec, responseSpec, AUDIT_URL, ""); + public static void verifyOrderBysupported(final String orderByValue) { + ok(() -> FineractFeignClientHelper.getFineractFeignClient().audits().retrieveAuditEntries(null, // actionName + null, // entityName + null, // resourceId + null, // makerId + null, // makerDateTimeFrom + null, // makerDateTimeTo + null, // checkerId + null, // checkerDateTimeFrom + null, // checkerDateTimeTo + null, // status + null, // clientId + null, // loanId + null, // officeId + null, // groupId + null, // savingsAccountId + null, // processingResult + null, // dateFormat + null, // locale + null, // offset + null, // limit + orderByValue, // orderBy + null, // sortOrder + true // paged + )); } }