FINERACT-1716: remove redundant boilerplate code within CommandSource class
This commit is contained in:
+31
-180
@@ -24,6 +24,11 @@ import jakarta.persistence.JoinColumn;
|
|||||||
import jakarta.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
import java.time.OffsetDateTime;
|
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.api.JsonCommand;
|
||||||
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
|
||||||
import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
|
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;
|
import org.apache.fineract.useradministration.domain.AppUser;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
@Table(name = "m_portfolio_command_source")
|
@Table(name = "m_portfolio_command_source")
|
||||||
public class CommandSource extends AbstractPersistableCustom<Long> {
|
public class CommandSource extends AbstractPersistableCustom<Long> {
|
||||||
|
|
||||||
@@ -123,195 +133,36 @@ public class CommandSource extends AbstractPersistableCustom<Long> {
|
|||||||
@Column(name = "result_status_code")
|
@Column(name = "result_status_code")
|
||||||
private Integer resultStatusCode;
|
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,
|
public static CommandSource fullEntryFrom(final CommandWrapper wrapper, final JsonCommand command, final AppUser maker,
|
||||||
String idempotencyKey, Integer status) {
|
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() {
|
return CommandSource.builder() //
|
||||||
//
|
.actionName(wrapper.actionName()) //
|
||||||
}
|
.entityName(wrapper.entityName()) //
|
||||||
|
.resourceGetUrl(wrapper.getHref()) //
|
||||||
public Long getCreditBureauId() {
|
.resourceId(command.entityId()) //
|
||||||
return this.creditBureauId;
|
.subResourceId(command.subentityId()) //
|
||||||
}
|
.commandAsJson(command.json()) //
|
||||||
|
.maker(maker) //
|
||||||
public void setCreditBureauId(Long creditBureauId) {
|
.madeOnDate(DateUtils.getAuditOffsetDateTime()) //
|
||||||
this.creditBureauId = creditBureauId;
|
.status(status) //
|
||||||
}
|
.idempotencyKey(idempotencyKey) //
|
||||||
|
.officeId(wrapper.getOfficeId()) //
|
||||||
public Long getOrganisationCreditBureauId() {
|
.groupId(command.getGroupId()) //
|
||||||
return this.organisationCreditBureauId;
|
.clientId(command.getClientId()) //
|
||||||
}
|
.loanId(command.getLoanId()) //
|
||||||
|
.savingsId(command.getSavingsId()) //
|
||||||
public void setOrganisationCreditBureauId(Long organisationCreditBureauId) {
|
.productId(command.getProductId()) //
|
||||||
this.organisationCreditBureauId = organisationCreditBureauId;
|
.transactionId(command.getTransactionId()) //
|
||||||
}
|
.creditBureauId(command.getCreditBureauId()) //
|
||||||
|
.organisationCreditBureauId(command.getOrganisationCreditBureauId()) //
|
||||||
public String getJobName() {
|
.build(); //
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPermissionCode() {
|
public String getPermissionCode() {
|
||||||
return this.actionName + "_" + this.entityName;
|
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() {
|
public void markAsAwaitingApproval() {
|
||||||
this.status = CommandProcessingResultType.AWAITING_APPROVAL.getValue();
|
this.status = CommandProcessingResultType.AWAITING_APPROVAL.getValue();
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -111,8 +111,8 @@ public class CommandSourceService {
|
|||||||
public CommandSource getInitialCommandSource(CommandWrapper wrapper, JsonCommand jsonCommand, AppUser maker, String idempotencyKey) {
|
public CommandSource getInitialCommandSource(CommandWrapper wrapper, JsonCommand jsonCommand, AppUser maker, String idempotencyKey) {
|
||||||
CommandSource commandSourceResult = CommandSource.fullEntryFrom(wrapper, jsonCommand, maker, idempotencyKey,
|
CommandSource commandSourceResult = CommandSource.fullEntryFrom(wrapper, jsonCommand, maker, idempotencyKey,
|
||||||
UNDER_PROCESSING.getValue());
|
UNDER_PROCESSING.getValue());
|
||||||
if (commandSourceResult.getCommandJson() == null) {
|
if (commandSourceResult.getCommandAsJson() == null) {
|
||||||
commandSourceResult.setCommandJson("{}");
|
commandSourceResult.setCommandAsJson("{}");
|
||||||
}
|
}
|
||||||
return commandSourceResult;
|
return commandSourceResult;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -89,8 +89,8 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio
|
|||||||
commandSourceInput.getGroupId(), commandSourceInput.getClientId(), commandSourceInput.getLoanId(),
|
commandSourceInput.getGroupId(), commandSourceInput.getClientId(), commandSourceInput.getLoanId(),
|
||||||
commandSourceInput.getSavingsId(), commandSourceInput.getTransactionId(), commandSourceInput.getCreditBureauId(),
|
commandSourceInput.getSavingsId(), commandSourceInput.getTransactionId(), commandSourceInput.getCreditBureauId(),
|
||||||
commandSourceInput.getOrganisationCreditBureauId(), commandSourceInput.getIdempotencyKey());
|
commandSourceInput.getOrganisationCreditBureauId(), commandSourceInput.getIdempotencyKey());
|
||||||
final JsonElement parsedCommand = this.fromApiJsonHelper.parse(commandSourceInput.getCommandJson());
|
final JsonElement parsedCommand = this.fromApiJsonHelper.parse(commandSourceInput.getCommandAsJson());
|
||||||
final JsonCommand command = JsonCommand.fromExistingCommand(makerCheckerId, commandSourceInput.getCommandJson(), parsedCommand,
|
final JsonCommand command = JsonCommand.fromExistingCommand(makerCheckerId, commandSourceInput.getCommandAsJson(), parsedCommand,
|
||||||
this.fromApiJsonHelper, commandSourceInput.getEntityName(), commandSourceInput.getResourceId(),
|
this.fromApiJsonHelper, commandSourceInput.getEntityName(), commandSourceInput.getResourceId(),
|
||||||
commandSourceInput.getSubResourceId(), commandSourceInput.getGroupId(), commandSourceInput.getClientId(),
|
commandSourceInput.getSubResourceId(), commandSourceInput.getGroupId(), commandSourceInput.getClientId(),
|
||||||
commandSourceInput.getLoanId(), commandSourceInput.getSavingsId(), commandSourceInput.getTransactionId(),
|
commandSourceInput.getLoanId(), commandSourceInput.getSavingsId(), commandSourceInput.getTransactionId(),
|
||||||
|
|||||||
+2
-2
@@ -134,7 +134,7 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
|
|||||||
commandSource.setResultStatusCode(statusCode);
|
commandSource.setResultStatusCode(statusCode);
|
||||||
commandSource.setResult(errorInfo.getMessage());
|
commandSource.setResult(errorInfo.getMessage());
|
||||||
if (statusCode != SC_OK) {
|
if (statusCode != SC_OK) {
|
||||||
commandSource.setStatus(ERROR);
|
commandSource.setStatus(ERROR.getValue());
|
||||||
}
|
}
|
||||||
if (!isEnclosingTransaction) { // TODO: temporary solution
|
if (!isEnclosingTransaction) { // TODO: temporary solution
|
||||||
commandSource = commandSourceService.saveResultNewTransaction(commandSource);
|
commandSource = commandSourceService.saveResultNewTransaction(commandSource);
|
||||||
@@ -148,7 +148,7 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
|
|||||||
commandSource.setResultStatusCode(SC_OK);
|
commandSource.setResultStatusCode(SC_OK);
|
||||||
commandSource.updateForAudit(result);
|
commandSource.updateForAudit(result);
|
||||||
commandSource.setResult(toApiJsonSerializer.serializeResult(result));
|
commandSource.setResult(toApiJsonSerializer.serializeResult(result));
|
||||||
commandSource.setStatus(PROCESSED);
|
commandSource.setStatus(PROCESSED.getValue());
|
||||||
commandSource = commandSourceService.saveResultSameTransaction(commandSource);
|
commandSource = commandSourceService.saveResultSameTransaction(commandSource);
|
||||||
storeCommandIdInContext(commandSource); // Store command id as a request attribute
|
storeCommandIdInContext(commandSource); // Store command id as a request attribute
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user