From 0959c8e4011e7b7c817b73a5612da997d5d4284b Mon Sep 17 00:00:00 2001 From: zeyad2003 Date: Sat, 20 Jul 2024 16:13:06 +0300 Subject: [PATCH] FINERACT-1716: remove redundant boilerplate code within `CommandSource` class --- .../commands/domain/CommandSource.java | 211 +++--------------- .../service/CommandSourceService.java | 4 +- ...CommandSourceWritePlatformServiceImpl.java | 4 +- .../SynchronousCommandProcessingService.java | 4 +- 4 files changed, 37 insertions(+), 186 deletions(-) diff --git a/fineract-core/src/main/java/org/apache/fineract/commands/domain/CommandSource.java b/fineract-core/src/main/java/org/apache/fineract/commands/domain/CommandSource.java index 2fadde646..97b4cbbe1 100644 --- a/fineract-core/src/main/java/org/apache/fineract/commands/domain/CommandSource.java +++ b/fineract-core/src/main/java/org/apache/fineract/commands/domain/CommandSource.java @@ -24,6 +24,11 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import java.time.OffsetDateTime; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; import org.apache.fineract.infrastructure.core.api.JsonCommand; import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; @@ -32,6 +37,11 @@ import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.useradministration.domain.AppUser; @Entity +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor @Table(name = "m_portfolio_command_source") public class CommandSource extends AbstractPersistableCustom { @@ -123,195 +133,36 @@ public class CommandSource extends AbstractPersistableCustom { @Column(name = "result_status_code") private Integer resultStatusCode; - private CommandSource(final String actionName, final String entityName, final String href, final Long resourceId, - final Long subResourceId, final String commandSerializedAsJson, final AppUser maker, final String idempotencyKey, - final Integer status) { - this.actionName = actionName; - this.entityName = entityName; - this.resourceGetUrl = href; - this.resourceId = resourceId; - this.subResourceId = subResourceId; - this.commandAsJson = commandSerializedAsJson; - this.maker = maker; - this.madeOnDate = DateUtils.getAuditOffsetDateTime(); - this.status = status; - this.idempotencyKey = idempotencyKey; - } - public static CommandSource fullEntryFrom(final CommandWrapper wrapper, final JsonCommand command, final AppUser maker, String idempotencyKey, Integer status) { - CommandSource commandSource = new CommandSource(wrapper.actionName(), wrapper.entityName(), wrapper.getHref(), command.entityId(), - command.subentityId(), command.json(), maker, idempotencyKey, status); - commandSource.officeId = wrapper.getOfficeId(); - commandSource.groupId = command.getGroupId(); - commandSource.clientId = command.getClientId(); - commandSource.loanId = command.getLoanId(); - commandSource.savingsId = command.getSavingsId(); - commandSource.productId = command.getProductId(); - commandSource.transactionId = command.getTransactionId(); - commandSource.creditBureauId = command.getCreditBureauId(); - commandSource.organisationCreditBureauId = command.getOrganisationCreditBureauId(); - return commandSource; - } - protected CommandSource() { - // - } - - public Long getCreditBureauId() { - return this.creditBureauId; - } - - public void setCreditBureauId(Long creditBureauId) { - this.creditBureauId = creditBureauId; - } - - public Long getOrganisationCreditBureauId() { - return this.organisationCreditBureauId; - } - - public void setOrganisationCreditBureauId(Long organisationCreditBureauId) { - this.organisationCreditBureauId = organisationCreditBureauId; - } - - public String getJobName() { - return this.jobName; - } - - public Long getResourceId() { - return this.resourceId; - } - - public void setResourceId(final Long resourceId) { - this.resourceId = resourceId; - } - - public Long getSubResourceId() { - return this.subResourceId; - } - - public void setSubResourceId(final Long subResourceId) { - this.subResourceId = subResourceId; - } - - public String getCommandJson() { - return this.commandAsJson; - } - - public void setCommandJson(final String json) { - this.commandAsJson = json; - } - - public AppUser getMaker() { - return maker; - } - - public AppUser getChecker() { - return checker; - } - - public String getActionName() { - return this.actionName; - } - - public String getEntityName() { - return this.entityName; + return CommandSource.builder() // + .actionName(wrapper.actionName()) // + .entityName(wrapper.entityName()) // + .resourceGetUrl(wrapper.getHref()) // + .resourceId(command.entityId()) // + .subResourceId(command.subentityId()) // + .commandAsJson(command.json()) // + .maker(maker) // + .madeOnDate(DateUtils.getAuditOffsetDateTime()) // + .status(status) // + .idempotencyKey(idempotencyKey) // + .officeId(wrapper.getOfficeId()) // + .groupId(command.getGroupId()) // + .clientId(command.getClientId()) // + .loanId(command.getLoanId()) // + .savingsId(command.getSavingsId()) // + .productId(command.getProductId()) // + .transactionId(command.getTransactionId()) // + .creditBureauId(command.getCreditBureauId()) // + .organisationCreditBureauId(command.getOrganisationCreditBureauId()) // + .build(); // } public String getPermissionCode() { return this.actionName + "_" + this.entityName; } - public String getResourceGetUrl() { - return this.resourceGetUrl; - } - - public Long getProductId() { - return this.productId; - } - - /** - * @return the clientId - */ - public Long getClientId() { - return clientId; - } - - /** - * @return the groupId - */ - public Long getGroupId() { - return groupId; - } - - /** - * @return the loanId - */ - public Long getLoanId() { - return loanId; - } - - /** - * @return the officeId - */ - public Long getOfficeId() { - return officeId; - } - - /** - * @return the savingsId - */ - public Long getSavingsId() { - return savingsId; - } - - /** - * @return the transactionId - */ - public String getTransactionId() { - return this.transactionId; - } - - public void setTransactionId(final String transactionId) { - this.transactionId = transactionId; - } - - public String getIdempotencyKey() { - return idempotencyKey; - } - - public void setIdempotencyKey(String idempotencyKey) { - this.idempotencyKey = idempotencyKey; - } - - public String getResult() { - return result; - } - - public void setResult(String result) { - this.result = result; - } - - public Integer getStatus() { - return status; - } - - public void setStatus(Integer status) { - this.status = status; - } - - public void setStatus(CommandProcessingResultType status) { - setStatus(status == null ? null : status.getValue()); - } - - public Integer getResultStatusCode() { - return resultStatusCode; - } - - public void setResultStatusCode(Integer resultStatusCode) { - this.resultStatusCode = resultStatusCode; - } - public void markAsAwaitingApproval() { this.status = CommandProcessingResultType.AWAITING_APPROVAL.getValue(); } diff --git a/fineract-core/src/main/java/org/apache/fineract/commands/service/CommandSourceService.java b/fineract-core/src/main/java/org/apache/fineract/commands/service/CommandSourceService.java index 46432d613..cabada788 100644 --- a/fineract-core/src/main/java/org/apache/fineract/commands/service/CommandSourceService.java +++ b/fineract-core/src/main/java/org/apache/fineract/commands/service/CommandSourceService.java @@ -111,8 +111,8 @@ public class CommandSourceService { public CommandSource getInitialCommandSource(CommandWrapper wrapper, JsonCommand jsonCommand, AppUser maker, String idempotencyKey) { CommandSource commandSourceResult = CommandSource.fullEntryFrom(wrapper, jsonCommand, maker, idempotencyKey, UNDER_PROCESSING.getValue()); - if (commandSourceResult.getCommandJson() == null) { - commandSourceResult.setCommandJson("{}"); + if (commandSourceResult.getCommandAsJson() == null) { + commandSourceResult.setCommandAsJson("{}"); } return commandSourceResult; } diff --git a/fineract-core/src/main/java/org/apache/fineract/commands/service/PortfolioCommandSourceWritePlatformServiceImpl.java b/fineract-core/src/main/java/org/apache/fineract/commands/service/PortfolioCommandSourceWritePlatformServiceImpl.java index fcd17c3f6..1de67b6e8 100644 --- a/fineract-core/src/main/java/org/apache/fineract/commands/service/PortfolioCommandSourceWritePlatformServiceImpl.java +++ b/fineract-core/src/main/java/org/apache/fineract/commands/service/PortfolioCommandSourceWritePlatformServiceImpl.java @@ -89,8 +89,8 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio commandSourceInput.getGroupId(), commandSourceInput.getClientId(), commandSourceInput.getLoanId(), commandSourceInput.getSavingsId(), commandSourceInput.getTransactionId(), commandSourceInput.getCreditBureauId(), commandSourceInput.getOrganisationCreditBureauId(), commandSourceInput.getIdempotencyKey()); - final JsonElement parsedCommand = this.fromApiJsonHelper.parse(commandSourceInput.getCommandJson()); - final JsonCommand command = JsonCommand.fromExistingCommand(makerCheckerId, commandSourceInput.getCommandJson(), parsedCommand, + final JsonElement parsedCommand = this.fromApiJsonHelper.parse(commandSourceInput.getCommandAsJson()); + final JsonCommand command = JsonCommand.fromExistingCommand(makerCheckerId, commandSourceInput.getCommandAsJson(), parsedCommand, this.fromApiJsonHelper, commandSourceInput.getEntityName(), commandSourceInput.getResourceId(), commandSourceInput.getSubResourceId(), commandSourceInput.getGroupId(), commandSourceInput.getClientId(), commandSourceInput.getLoanId(), commandSourceInput.getSavingsId(), commandSourceInput.getTransactionId(), diff --git a/fineract-core/src/main/java/org/apache/fineract/commands/service/SynchronousCommandProcessingService.java b/fineract-core/src/main/java/org/apache/fineract/commands/service/SynchronousCommandProcessingService.java index 3df570b1f..6b4868f2b 100644 --- a/fineract-core/src/main/java/org/apache/fineract/commands/service/SynchronousCommandProcessingService.java +++ b/fineract-core/src/main/java/org/apache/fineract/commands/service/SynchronousCommandProcessingService.java @@ -134,7 +134,7 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer commandSource.setResultStatusCode(statusCode); commandSource.setResult(errorInfo.getMessage()); if (statusCode != SC_OK) { - commandSource.setStatus(ERROR); + commandSource.setStatus(ERROR.getValue()); } if (!isEnclosingTransaction) { // TODO: temporary solution commandSource = commandSourceService.saveResultNewTransaction(commandSource); @@ -148,7 +148,7 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer commandSource.setResultStatusCode(SC_OK); commandSource.updateForAudit(result); commandSource.setResult(toApiJsonSerializer.serializeResult(result)); - commandSource.setStatus(PROCESSED); + commandSource.setStatus(PROCESSED.getValue()); commandSource = commandSourceService.saveResultSameTransaction(commandSource); storeCommandIdInContext(commandSource); // Store command id as a request attribute