Skip to content

Commit

Permalink
FINERACT-2152: API Create and retrieve interest pause
Browse files Browse the repository at this point in the history
  • Loading branch information
kulminsky committed Dec 18, 2024
1 parent 8716751 commit 3f9c84e
Show file tree
Hide file tree
Showing 33 changed files with 833 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ public class CommandSource extends AbstractPersistableCustom<Long> {
@Column(name = "result_status_code")
private Integer resultStatusCode;

@Column(name = "loan_external_id", length = 100)
private ExternalId loanExternalId;

public static CommandSource fullEntryFrom(final CommandWrapper wrapper, final JsonCommand command, final AppUser maker,
String idempotencyKey, Integer status) {

Expand All @@ -156,6 +159,7 @@ public static CommandSource fullEntryFrom(final CommandWrapper wrapper, final Js
.transactionId(command.getTransactionId()) //
.creditBureauId(command.getCreditBureauId()) //
.organisationCreditBureauId(command.getOrganisationCreditBureauId()) //
.loanExternalId(command.getLoanExternalId()) //
.build(); //
}

Expand Down Expand Up @@ -195,5 +199,6 @@ public void updateForAudit(final CommandProcessingResult result) {
this.resourceExternalId = result.getResourceExternalId();
this.subResourceId = result.getSubResourceId();
this.subResourceExternalId = result.getSubResourceExternalId();
this.loanExternalId = result.getLoanExternalId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.fineract.commands.domain;

import lombok.Getter;
import org.apache.fineract.infrastructure.core.domain.ExternalId;
import org.apache.fineract.useradministration.api.PasswordPreferencesApiConstants;

@Getter
Expand All @@ -43,6 +44,7 @@ public class CommandWrapper {
private final Long creditBureauId;
private final Long organisationCreditBureauId;
private final String jobName;
private final ExternalId loanExternalId;

private final String idempotencyKey;

Expand All @@ -61,9 +63,11 @@ public static CommandWrapper fromExistingCommand(final Long commandId, final Str
public static CommandWrapper fromExistingCommand(final Long commandId, final String actionName, final String entityName,
final Long resourceId, final Long subresourceId, final String resourceGetUrl, final Long productId, final Long officeId,
final Long groupId, final Long clientId, final Long loanId, final Long savingsId, final String transactionId,
final Long creditBureauId, final Long organisationCreditBureauId, final String idempotencyKey) {
final Long creditBureauId, final Long organisationCreditBureauId, final String idempotencyKey,
final ExternalId loanExternalId) {
return new CommandWrapper(commandId, actionName, entityName, resourceId, subresourceId, resourceGetUrl, productId, officeId,
groupId, clientId, loanId, savingsId, transactionId, creditBureauId, organisationCreditBureauId, idempotencyKey);
groupId, clientId, loanId, savingsId, transactionId, creditBureauId, organisationCreditBureauId, idempotencyKey,
loanExternalId);
}

private CommandWrapper(final Long commandId, final String actionName, final String entityName, final Long resourceId,
Expand All @@ -87,12 +91,13 @@ private CommandWrapper(final Long commandId, final String actionName, final Stri
this.organisationCreditBureauId = null;
this.jobName = null;
this.idempotencyKey = null;
this.loanExternalId = null;
}

public CommandWrapper(final Long officeId, final Long groupId, final Long clientId, final Long loanId, final Long savingsId,
final String actionName, final String entityName, final Long entityId, final Long subentityId, final String href,
final String json, final String transactionId, final Long productId, final Long templateId, final Long creditBureauId,
final Long organisationCreditBureauId, final String jobName, final String idempotencyKey) {
final Long organisationCreditBureauId, final String jobName, final String idempotencyKey, final ExternalId loanExternalId) {

this.commandId = null;
this.officeId = officeId;
Expand All @@ -114,12 +119,13 @@ public CommandWrapper(final Long officeId, final Long groupId, final Long client
this.organisationCreditBureauId = organisationCreditBureauId;
this.jobName = jobName;
this.idempotencyKey = idempotencyKey;
this.loanExternalId = loanExternalId;
}

private CommandWrapper(final Long commandId, final String actionName, final String entityName, final Long resourceId,
final Long subresourceId, final String resourceGetUrl, final Long productId, final Long officeId, final Long groupId,
final Long clientId, final Long loanId, final Long savingsId, final String transactionId, final Long creditBureauId,
final Long organisationCreditBureauId, final String idempotencyKey) {
final Long organisationCreditBureauId, final String idempotencyKey, final ExternalId loanExternalId) {

this.commandId = commandId;
this.officeId = officeId;
Expand All @@ -140,6 +146,7 @@ private CommandWrapper(final Long commandId, final String actionName, final Stri
this.organisationCreditBureauId = organisationCreditBureauId;
this.jobName = null;
this.idempotencyKey = idempotencyKey;
this.loanExternalId = loanExternalId;
}

public boolean isCreate() {
Expand Down Expand Up @@ -240,6 +247,14 @@ public boolean isPasswordPreferencesResource() {
return this.entityName.equalsIgnoreCase(PasswordPreferencesApiConstants.ENTITY_NAME);
}

public boolean isInterestPauseResource() {
return this.entityName.equalsIgnoreCase("INTEREST_PAUSE");
}

public boolean isInterestPauseExternalIdResource() {
return this.entityName.equalsIgnoreCase("INTEREST_PAUSE") && this.href.contains("/external-id/");
}

public Long commandId() {
return this.commandId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.infrastructure.accountnumberformat.service.AccountNumberFormatConstants;
import org.apache.fineract.infrastructure.core.domain.ExternalId;
import org.apache.fineract.portfolio.client.api.ClientApiConstants;
import org.apache.fineract.portfolio.paymenttype.api.PaymentTypeApiResourceConstants;
import org.apache.fineract.portfolio.savings.DepositsApiConstants;
Expand All @@ -47,18 +48,19 @@ public class CommandWrapperBuilder {
private Long organisationCreditBureauId;
private String jobName;
private String idempotencyKey;
private ExternalId loanExternalId;

@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "TODO: fix this!")
public CommandWrapper build() {
return new CommandWrapper(this.officeId, this.groupId, this.clientId, this.loanId, this.savingsId, this.actionName, this.entityName,
this.entityId, this.subentityId, this.href, this.json, this.transactionId, this.productId, this.templateId,
this.creditBureauId, this.organisationCreditBureauId, this.jobName, this.idempotencyKey);
this.creditBureauId, this.organisationCreditBureauId, this.jobName, this.idempotencyKey, this.loanExternalId);
}

public CommandWrapper build(String idempotencyKey) {
return new CommandWrapper(this.officeId, this.groupId, this.clientId, this.loanId, this.savingsId, this.actionName, this.entityName,
this.entityId, this.subentityId, this.href, this.json, this.transactionId, this.productId, this.templateId,
this.creditBureauId, this.organisationCreditBureauId, this.jobName, idempotencyKey);
this.creditBureauId, this.organisationCreditBureauId, this.jobName, idempotencyKey, this.loanExternalId);
}

public CommandWrapperBuilder updateCreditBureau() {
Expand Down Expand Up @@ -3714,4 +3716,20 @@ public CommandWrapperBuilder createDelinquencyAction(final Long loanId) {
this.href = "/loans/" + loanId + "/delinquency-action";
return this;
}

public CommandWrapperBuilder createInterestPause(final long loanId) {
this.actionName = "CREATE";
this.entityName = "INTEREST_PAUSE";
this.loanId = loanId;
this.href = "/v1/loans/" + loanId + "/interest-pauses";
return this;
}

public CommandWrapperBuilder createInterestPauseByExternalId(final String loanExternalId) {
this.actionName = "CREATE";
this.entityName = "INTEREST_PAUSE";
this.loanExternalId = new ExternalId(loanExternalId);
this.href = "/v1/loans/external-id/" + loanExternalId + "/interest-pauses";
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public CommandProcessingResult logCommandSource(final CommandWrapper wrapper) {
JsonCommand command = JsonCommand.from(json, parsedCommand, this.fromApiJsonHelper, wrapper.getEntityName(), wrapper.getEntityId(),
wrapper.getSubentityId(), wrapper.getGroupId(), wrapper.getClientId(), wrapper.getLoanId(), wrapper.getSavingsId(),
wrapper.getTransactionId(), wrapper.getHref(), wrapper.getProductId(), wrapper.getCreditBureauId(),
wrapper.getOrganisationCreditBureauId(), wrapper.getJobName());
wrapper.getOrganisationCreditBureauId(), wrapper.getJobName(), wrapper.getLoanExternalId());

return this.processAndLogCommandService.executeCommand(wrapper, command, isApprovedByChecker);
}
Expand All @@ -88,14 +88,16 @@ public CommandProcessingResult approveEntry(final Long makerCheckerId) {
commandSourceInput.getResourceGetUrl(), commandSourceInput.getProductId(), commandSourceInput.getOfficeId(),
commandSourceInput.getGroupId(), commandSourceInput.getClientId(), commandSourceInput.getLoanId(),
commandSourceInput.getSavingsId(), commandSourceInput.getTransactionId(), commandSourceInput.getCreditBureauId(),
commandSourceInput.getOrganisationCreditBureauId(), commandSourceInput.getIdempotencyKey());
commandSourceInput.getOrganisationCreditBureauId(), commandSourceInput.getIdempotencyKey(),
commandSourceInput.getLoanExternalId());
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(),
commandSourceInput.getResourceGetUrl(), commandSourceInput.getProductId(), commandSourceInput.getCreditBureauId(),
commandSourceInput.getOrganisationCreditBureauId(), commandSourceInput.getJobName());
commandSourceInput.getOrganisationCreditBureauId(), commandSourceInput.getJobName(),
commandSourceInput.getLoanExternalId());

return this.processAndLogCommandService.executeCommand(wrapper, command, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ private NewCommandSourceHandler findCommandHandler(final CommandWrapper wrapper)
} else {
throw new UnsupportedCommandException(wrapper.commandName());
}
} else if (wrapper.isInterestPauseResource() || wrapper.isInterestPauseExternalIdResource()) {
handler = applicationContext.getBean("interestPauseCommandHandler", NewCommandSourceHandler.class);
} else {
handler = commandHandlerProvider.getHandler(wrapper.entityName(), wrapper.actionName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,34 @@ public final class JsonCommand {
private final Long creditBureauId;
private final Long organisationCreditBureauId;
private final String jobName;
private final ExternalId loanExternalId;

public static JsonCommand from(final String jsonCommand, final JsonElement parsedCommand, final FromJsonHelper fromApiJsonHelper,
final String entityName, final Long resourceId, final Long subresourceId, final Long groupId, final Long clientId,
final Long loanId, final Long savingsId, final String transactionId, final String url, final Long productId,
final Long creditBureauId, final Long organisationCreditBureauId, final String jobName) {
final Long creditBureauId, final Long organisationCreditBureauId, final String jobName, final ExternalId loanExternalId) {
return new JsonCommand(null, jsonCommand, parsedCommand, fromApiJsonHelper, entityName, resourceId, subresourceId, groupId,
clientId, loanId, savingsId, transactionId, url, productId, creditBureauId, organisationCreditBureauId, jobName);
clientId, loanId, savingsId, transactionId, url, productId, creditBureauId, organisationCreditBureauId, jobName,
loanExternalId);

}

public static JsonCommand fromExistingCommand(final Long commandId, final String jsonCommand, final JsonElement parsedCommand,
final FromJsonHelper fromApiJsonHelper, final String entityName, final Long resourceId, final Long subresourceId,
final String url, final Long productId, final Long creditBureauId, final Long organisationCreditBureauId,
final String jobName) {
final String url, final Long productId, final Long creditBureauId, final Long organisationCreditBureauId, final String jobName,
final ExternalId loanExternalId) {
return new JsonCommand(commandId, jsonCommand, parsedCommand, fromApiJsonHelper, entityName, resourceId, subresourceId, null, null,
null, null, null, url, productId, creditBureauId, organisationCreditBureauId, jobName);
null, null, null, url, productId, creditBureauId, organisationCreditBureauId, jobName, loanExternalId);
}

public static JsonCommand fromExistingCommand(final Long commandId, final String jsonCommand, final JsonElement parsedCommand,
final FromJsonHelper fromApiJsonHelper, final String entityName, final Long resourceId, final Long subresourceId,
final Long groupId, final Long clientId, final Long loanId, final Long savingsId, final String transactionId, final String url,
final Long productId, Long creditBureauId, final Long organisationCreditBureauId, final String jobName) {
final Long productId, Long creditBureauId, final Long organisationCreditBureauId, final String jobName,
final ExternalId loanExternalId) {
return new JsonCommand(commandId, jsonCommand, parsedCommand, fromApiJsonHelper, entityName, resourceId, subresourceId, groupId,
clientId, loanId, savingsId, transactionId, url, productId, creditBureauId, organisationCreditBureauId, jobName);
clientId, loanId, savingsId, transactionId, url, productId, creditBureauId, organisationCreditBureauId, jobName,
loanExternalId);

}

Expand All @@ -103,21 +107,22 @@ public static JsonCommand fromExistingCommand(JsonCommand command, final JsonEle
return new JsonCommand(command.commandId, jsonCommand, parsedCommand, command.fromApiJsonHelper, command.entityName,
command.resourceId, command.subresourceId, command.groupId, command.clientId, command.loanId, command.savingsId,
command.transactionId, command.url, command.productId, command.creditBureauId, command.organisationCreditBureauId,
command.jobName);
command.jobName, command.loanExternalId);
}

public static JsonCommand fromExistingCommand(JsonCommand command, final JsonElement parsedCommand, final Long clientId) {
final String jsonCommand = command.fromApiJsonHelper.toJson(parsedCommand);
return new JsonCommand(command.commandId, jsonCommand, parsedCommand, command.fromApiJsonHelper, command.entityName,
command.resourceId, command.subresourceId, command.groupId, clientId, command.loanId, command.savingsId,
command.transactionId, command.url, command.productId, command.creditBureauId, command.organisationCreditBureauId,
command.jobName);
command.jobName, command.loanExternalId);
}

public JsonCommand(final Long commandId, final String jsonCommand, final JsonElement parsedCommand,
final FromJsonHelper fromApiJsonHelper, final String entityName, final Long resourceId, final Long subresourceId,
final Long groupId, final Long clientId, final Long loanId, final Long savingsId, final String transactionId, final String url,
final Long productId, final Long creditBureauId, final Long organisationCreditBureauId, final String jobName) {
final Long productId, final Long creditBureauId, final Long organisationCreditBureauId, final String jobName,
final ExternalId loanExternalId) {

this.commandId = commandId;
this.jsonCommand = jsonCommand;
Expand All @@ -136,6 +141,7 @@ public JsonCommand(final Long commandId, final String jsonCommand, final JsonEle
this.creditBureauId = creditBureauId;
this.organisationCreditBureauId = organisationCreditBureauId;
this.jobName = jobName;
this.loanExternalId = loanExternalId;
}

public static JsonCommand fromJsonElement(final Long resourceId, final JsonElement parsedCommand) {
Expand Down Expand Up @@ -165,6 +171,7 @@ public JsonCommand(final Long resourceId, final JsonElement parsedCommand) {
this.creditBureauId = null;
this.organisationCreditBureauId = null;
this.jobName = null;
this.loanExternalId = null;
}

public JsonCommand(final Long resourceId, final JsonElement parsedCommand, final FromJsonHelper fromApiJsonHelper) {
Expand All @@ -185,10 +192,12 @@ public JsonCommand(final Long resourceId, final JsonElement parsedCommand, final
this.creditBureauId = null;
this.organisationCreditBureauId = null;
this.jobName = null;
this.loanExternalId = null;
}

public static JsonCommand from(final String jsonCommand) {
return new JsonCommand(null, jsonCommand, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
return new JsonCommand(null, jsonCommand, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null);

}

Expand Down
Loading

0 comments on commit 3f9c84e

Please sign in to comment.