You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by ad...@apache.org on 2025/03/25 11:10:32 UTC
(fineract) branch develop updated: FINERACT-2169: Refactor macker checkers api controller;
This is an automated email from the ASF dual-hosted git repository.
adamsaghy pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git
The following commit(s) were added to refs/heads/develop by this push:
new 20195464c9 FINERACT-2169: Refactor macker checkers api controller;
20195464c9 is described below
commit 20195464c95f806b8f96eb04371020f5a99cad96
Author: viktorpavlenko <vi...@gmail.com>
AuthorDate: Thu Mar 20 14:59:04 2025 +0200
FINERACT-2169: Refactor macker checkers api controller;
---
.../commands/api/MakercheckersApiResource.java | 103 +++++++--------------
.../api/MakercheckersApiResourceSwagger.java | 48 ----------
.../commands/data/request/MakerCheckerRequest.java | 59 ++++++++++++
3 files changed, 92 insertions(+), 118 deletions(-)
diff --git a/fineract-provider/src/main/java/org/apache/fineract/commands/api/MakercheckersApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/commands/api/MakercheckersApiResource.java
index 06e05268e0..5acafefbc2 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/commands/api/MakercheckersApiResource.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/commands/api/MakercheckersApiResource.java
@@ -20,12 +20,12 @@ package org.apache.fineract.commands.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.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.ws.rs.BeanParam;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
@@ -37,21 +37,18 @@ 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.Collection;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.commands.data.AuditData;
import org.apache.fineract.commands.data.AuditSearchData;
+import org.apache.fineract.commands.data.request.MakerCheckerRequest;
import org.apache.fineract.commands.service.AuditReadPlatformService;
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.exception.UnrecognizedQueryParamException;
import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
-import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.apache.fineract.infrastructure.security.utils.SQLBuilder;
import org.springframework.stereotype.Component;
@@ -61,13 +58,10 @@ import org.springframework.stereotype.Component;
@RequiredArgsConstructor
public class MakercheckersApiResource {
- private static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList("id", "actionName", "entityName", "resourceId",
- "subresourceId", "maker", "madeOnDate", "checker", "checkedOnDate", "processingResult", "commandAsJson", "officeName",
- "groupLevelName", "groupName", "clientName", "loanAccountNo", "savingsAccountNo", "clientId", "loanId"));
+ private static final String COMMAND_APPROVE = "approve";
+ private static final String COMMAND_REJECT = "reject";
private final AuditReadPlatformService readPlatformService;
- private final DefaultToApiJsonSerializer<AuditData> toApiJsonSerializerAudit;
- private final DefaultToApiJsonSerializer<AuditSearchData> toApiJsonSerializerSearchTemplate;
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final PortfolioCommandSourceWritePlatformService writePlatformService;
@@ -78,30 +72,12 @@ public class MakercheckersApiResource {
+ "\n" + "Example Requests:\n" + "\n" + "makercheckers\n" + "\n" + "makercheckers?fields=madeOnDate,maker,processingResult\n"
+ "\n" + "makercheckers?makerDateTimeFrom=2013-03-25 08:00:00&makerDateTimeTo=2013-04-04 18:00:00\n" + "\n"
+ "makercheckers?officeId=1\n" + "\n" + "makercheckers?officeId=1&includeJson=true")
- @ApiResponses({
- @ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = MakercheckersApiResourceSwagger.GetMakerCheckerResponse.class)))) })
- public String retrieveCommands(@Context final UriInfo uriInfo,
- @QueryParam("actionName") @Parameter(description = "actionName") final String actionName,
- @QueryParam("entityName") @Parameter(description = "entityName") final String entityName,
- @QueryParam("resourceId") @Parameter(description = "resourceId") final Long resourceId,
- @QueryParam("makerId") @Parameter(description = "makerId") final Long makerId,
- @QueryParam("makerDateTimeFrom") @Parameter(description = "makerDateTimeFrom") final String makerDateTimeFrom,
- @QueryParam("makerDateTimeTo") @Parameter(description = "makerDateTimeTo") final String makerDateTimeTo,
- @QueryParam("officeId") @Parameter(description = "officeId") final Integer officeId,
- @QueryParam("groupId") @Parameter(description = "groupId") final Integer groupId,
- @QueryParam("clientId") @Parameter(description = "clientId") final Integer clientId,
- @QueryParam("loanid") @Parameter(description = "loanid") final Integer loanId,
- @QueryParam("savingsAccountId") @Parameter(description = "savingsAccountId") final Integer savingsAccountId) {
-
- final SQLBuilder extraCriteria = getExtraCriteria(actionName, entityName, resourceId, makerId, makerDateTimeFrom, makerDateTimeTo,
- officeId, groupId, clientId, loanId, savingsAccountId);
-
- final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
+ public List<AuditData> retrieveCommands(@Context final UriInfo uriInfo, @BeanParam MakerCheckerRequest makerCheckerRequest) {
+ final SQLBuilder extraCriteria = getExtraCriteria(makerCheckerRequest);
- final Collection<AuditData> entries = this.readPlatformService.retrieveAllEntriesToBeChecked(extraCriteria,
- settings.isIncludeJson());
+ final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
+ return readPlatformService.retrieveAllEntriesToBeChecked(extraCriteria, settings.isIncludeJson());
- return this.toApiJsonSerializerAudit.serialize(settings, entries, RESPONSE_DATA_PARAMETERS);
}
@GET
@@ -110,17 +86,8 @@ public class MakercheckersApiResource {
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Maker Checker Search Template", description = "This is a convenience resource. It can be useful when building a Checker Inbox UI. \"appUsers\" are data scoped to the office/branch the requestor is associated with. \"actionNames\" and \"entityNames\" returned are those that the requestor has Checker approval permissions for.\n"
+ "\n" + "Example Requests:\n" + "\n" + "makercheckers/searchtemplate\n" + "makercheckers/searchtemplate?fields=entityNames")
- @ApiResponses({
- @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = MakercheckersApiResourceSwagger.GetMakerCheckersSearchTemplateResponse.class))) })
- public String retrieveAuditSearchTemplate(@Context final UriInfo uriInfo) {
-
- final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
-
- final AuditSearchData auditSearchData = this.readPlatformService.retrieveSearchTemplate("makerchecker");
-
- final Set<String> RESPONSE_DATA_PARAMETERS_SEARCH_TEMPLATE = new HashSet<>(Arrays.asList("appUsers", "actionNames", "entityNames"));
-
- return this.toApiJsonSerializerSearchTemplate.serialize(settings, auditSearchData, RESPONSE_DATA_PARAMETERS_SEARCH_TEMPLATE);
+ public AuditSearchData retrieveAuditSearchTemplate() {
+ return readPlatformService.retrieveSearchTemplate("makerchecker");
}
@POST
@@ -130,19 +97,19 @@ public class MakercheckersApiResource {
@Operation(summary = "Approve Maker Checker Entry | Reject Maker Checker Entry")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = MakercheckersApiResourceSwagger.PostMakerCheckersResponse.class))) })
- public String approveMakerCheckerEntry(@PathParam("auditId") @Parameter(description = "auditId") final Long auditId,
+ public CommandProcessingResult approveMakerCheckerEntry(@PathParam("auditId") @Parameter(description = "auditId") final Long auditId,
@QueryParam("command") @Parameter(description = "command") final String commandParam) {
CommandProcessingResult result = null;
- if (is(commandParam, "approve")) {
- result = this.writePlatformService.approveEntry(auditId);
- } else if (is(commandParam, "reject")) {
- final Long id = this.writePlatformService.rejectEntry(auditId);
+ if (is(commandParam, COMMAND_APPROVE)) {
+ result = writePlatformService.approveEntry(auditId);
+ } else if (is(commandParam, COMMAND_REJECT)) {
+ final Long id = writePlatformService.rejectEntry(auditId);
result = CommandProcessingResult.commandOnlyResult(id);
} else {
throw new UnrecognizedQueryParamException("command", commandParam);
}
- return this.toApiJsonSerializerAudit.serialize(result);
+ return result;
}
private boolean is(final String commandParam, final String commandValue) {
@@ -156,31 +123,27 @@ public class MakercheckersApiResource {
@Operation(summary = "Delete Maker Checker Entry")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = MakercheckersApiResourceSwagger.PostMakerCheckersResponse.class))) })
- public String deleteMakerCheckerEntry(@PathParam("auditId") @Parameter(description = "auditId") final Long auditId) {
-
- final Long id = this.writePlatformService.deleteEntry(auditId);
-
- return this.toApiJsonSerializerAudit.serialize(CommandProcessingResult.commandOnlyResult(id));
+ public CommandProcessingResult deleteMakerCheckerEntry(@PathParam("auditId") @Parameter(description = "auditId") final Long auditId) {
+ final Long id = writePlatformService.deleteEntry(auditId);
+ return CommandProcessingResult.commandOnlyResult(id);
}
- private SQLBuilder getExtraCriteria(final String actionName, final String entityName, final Long resourceId, final Long makerId,
- final String makerDateTimeFrom, final String makerDateTimeTo, final Integer officeId, final Integer groupId,
- final Integer clientId, final Integer loanId, final Integer savingsAccountId) {
+ private SQLBuilder getExtraCriteria(MakerCheckerRequest makerCheckerRequest) {
SQLBuilder extraCriteria = new SQLBuilder();
- extraCriteria.addNonNullCriteria("aud.action_name = ", actionName);
- if (entityName != null) {
- extraCriteria.addCriteria("aud.entity_name like ", entityName + "%");
+ extraCriteria.addNonNullCriteria("aud.action_name = ", makerCheckerRequest.getActionName());
+ if (makerCheckerRequest.getEntityName() != null) {
+ extraCriteria.addCriteria("aud.entity_name like ", makerCheckerRequest.getEntityName() + "%");
}
- extraCriteria.addNonNullCriteria("aud.resource_id = ", resourceId);
- extraCriteria.addNonNullCriteria("aud.maker_id = ", makerId);
- extraCriteria.addNonNullCriteria("aud.made_on_date >= ", makerDateTimeFrom);
- extraCriteria.addNonNullCriteria("aud.made_on_date <= ", makerDateTimeTo);
- extraCriteria.addNonNullCriteria("aud.office_id = ", officeId);
- extraCriteria.addNonNullCriteria("aud.group_id = ", groupId);
- extraCriteria.addNonNullCriteria("aud.client_id = ", clientId);
- extraCriteria.addNonNullCriteria("aud.loan_id = ", loanId);
- extraCriteria.addNonNullCriteria("aud.savings_account_id = ", savingsAccountId);
+ extraCriteria.addNonNullCriteria("aud.resource_id = ", makerCheckerRequest.getResourceId());
+ extraCriteria.addNonNullCriteria("aud.maker_id = ", makerCheckerRequest.getMakerId());
+ extraCriteria.addNonNullCriteria("aud.made_on_date >= ", makerCheckerRequest.getMakerDateTimeFrom());
+ extraCriteria.addNonNullCriteria("aud.made_on_date <= ", makerCheckerRequest.getMakerDateTimeTo());
+ extraCriteria.addNonNullCriteria("aud.office_id = ", makerCheckerRequest.getOfficeId());
+ extraCriteria.addNonNullCriteria("aud.group_id = ", makerCheckerRequest.getGroupId());
+ extraCriteria.addNonNullCriteria("aud.client_id = ", makerCheckerRequest.getClientId());
+ extraCriteria.addNonNullCriteria("aud.loan_id = ", makerCheckerRequest.getLoanId());
+ extraCriteria.addNonNullCriteria("aud.savings_account_id = ", makerCheckerRequest.getSavingsAccountId());
return extraCriteria;
}
diff --git a/fineract-provider/src/main/java/org/apache/fineract/commands/api/MakercheckersApiResourceSwagger.java b/fineract-provider/src/main/java/org/apache/fineract/commands/api/MakercheckersApiResourceSwagger.java
index eed05fb554..07f523e016 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/commands/api/MakercheckersApiResourceSwagger.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/commands/api/MakercheckersApiResourceSwagger.java
@@ -19,11 +19,6 @@
package org.apache.fineract.commands.api;
import io.swagger.v3.oas.annotations.media.Schema;
-import java.time.ZonedDateTime;
-import java.util.Collection;
-import java.util.List;
-import org.apache.fineract.commands.data.ProcessingResultLookup;
-import org.apache.fineract.useradministration.data.AppUserData;
/**
* Created by sanyam on 27/7/17.
@@ -34,49 +29,6 @@ final class MakercheckersApiResourceSwagger {
// only to initialize swagger documentation
}
- @Schema(description = "GetMakerCheckerResponse")
- public static final class GetMakerCheckerResponse {
-
- private GetMakerCheckerResponse() {
-
- }
-
- public Long id;
- public String actionName;
- public String entityName;
- public Long resourceId;
- public Long subresourceId;
- public String maker;
- public ZonedDateTime madeOnDate;
- public String checker;
- public ZonedDateTime checkedOnDate;
- public String processingResult;
- public String commandAsJson;
- public String officeName;
- public String groupLevelName;
- public String groupName;
- public String clientName;
- public String loanAccountNo;
- public String savingsAccountNo;
- public Long clientId;
- public Long loanId;
- public String url;
-
- }
-
- @Schema(description = "GetMakerCheckersSearchTemplateResponse")
- public static final class GetMakerCheckersSearchTemplateResponse {
-
- private GetMakerCheckersSearchTemplateResponse() {
-
- }
-
- public Collection<AppUserData> appUsers;
- public List<String> actionNames;
- public List<String> entityNames;
- public Collection<ProcessingResultLookup> processingResults;
- }
-
@Schema(description = "PostMakerCheckersResponse")
public static final class PostMakerCheckersResponse {
diff --git a/fineract-provider/src/main/java/org/apache/fineract/commands/data/request/MakerCheckerRequest.java b/fineract-provider/src/main/java/org/apache/fineract/commands/data/request/MakerCheckerRequest.java
new file mode 100644
index 0000000000..4d8bbe0c61
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/commands/data/request/MakerCheckerRequest.java
@@ -0,0 +1,59 @@
+/**
+ * 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.data.request;
+
+import jakarta.ws.rs.QueryParam;
+import java.io.Serial;
+import java.io.Serializable;
+import java.time.ZonedDateTime;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+@Setter
+@Getter
+@NoArgsConstructor
+public class MakerCheckerRequest implements Serializable {
+
+ @Serial
+ private static final long serialVersionUID = 1L;
+
+ @QueryParam("actionName")
+ private String actionName;
+ @QueryParam("entityName")
+ private String entityName;
+ @QueryParam("resourceId")
+ private Long resourceId;
+ @QueryParam("makerId")
+ private Long makerId;
+ @QueryParam("makerDateTimeFrom")
+ private ZonedDateTime makerDateTimeFrom;
+ @QueryParam("makerDateTimeTo")
+ private ZonedDateTime makerDateTimeTo;
+ @QueryParam("clientId")
+ private Long clientId;
+ @QueryParam("loanid")
+ private Long loanId;
+ @QueryParam("officeId")
+ private Long officeId;
+ @QueryParam("groupId")
+ private Long groupId;
+ @QueryParam("savingsAccountId")
+ private Long savingsAccountId;
+}