Skip to content

Commit

Permalink
FINERACT-2152: API update and delete interest pause
Browse files Browse the repository at this point in the history
  • Loading branch information
kulminsky committed Dec 27, 2024
1 parent c2ec015 commit 44c9a81
Show file tree
Hide file tree
Showing 34 changed files with 513 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ public class CommandSource extends AbstractPersistableCustom<Long> {
@Column(name = "loan_external_id", length = 100)
private ExternalId loanExternalId;

@Column(name = "term_variation_id", length = 100)
private Long termVariationId;

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

Expand All @@ -160,7 +163,7 @@ public static CommandSource fullEntryFrom(final CommandWrapper wrapper, final Js
.creditBureauId(command.getCreditBureauId()) //
.organisationCreditBureauId(command.getOrganisationCreditBureauId()) //
.loanExternalId(command.getLoanExternalId()) //
.build(); //
.termVariationId(command.getTermVariationId()).build(); //
}

public String getPermissionCode() {
Expand Down Expand Up @@ -200,5 +203,6 @@ public void updateForAudit(final CommandProcessingResult result) {
this.subResourceId = result.getSubResourceId();
this.subResourceExternalId = result.getSubResourceExternalId();
this.loanExternalId = result.getLoanExternalId();
this.termVariationId = result.getTermVariationId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class CommandWrapper {
private final Long organisationCreditBureauId;
private final String jobName;
private final ExternalId loanExternalId;
private final Long termVariationId;

private final String idempotencyKey;

Expand All @@ -63,11 +64,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 ExternalId loanExternalId) {
final Long creditBureauId, final Long organisationCreditBureauId, final String idempotencyKey, final ExternalId loanExternalId,
final Long termVariationId) {
return new CommandWrapper(commandId, actionName, entityName, resourceId, subresourceId, resourceGetUrl, productId, officeId,
groupId, clientId, loanId, savingsId, transactionId, creditBureauId, organisationCreditBureauId, idempotencyKey,
loanExternalId);
loanExternalId, termVariationId);
}

private CommandWrapper(final Long commandId, final String actionName, final String entityName, final Long resourceId,
Expand All @@ -92,12 +93,14 @@ private CommandWrapper(final Long commandId, final String actionName, final Stri
this.jobName = null;
this.idempotencyKey = null;
this.loanExternalId = null;
this.termVariationId = 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 ExternalId loanExternalId) {
final Long organisationCreditBureauId, final String jobName, final String idempotencyKey, final ExternalId loanExternalId,
final Long termVariationId) {

this.commandId = null;
this.officeId = officeId;
Expand All @@ -120,12 +123,14 @@ public CommandWrapper(final Long officeId, final Long groupId, final Long client
this.jobName = jobName;
this.idempotencyKey = idempotencyKey;
this.loanExternalId = loanExternalId;
this.termVariationId = termVariationId;
}

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 ExternalId loanExternalId) {
final Long organisationCreditBureauId, final String idempotencyKey, final ExternalId loanExternalId,
final Long termVariationId) {

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

public boolean isCreate() {
Expand Down Expand Up @@ -251,8 +257,16 @@ public boolean isInterestPauseResource() {
return this.entityName.equalsIgnoreCase("INTEREST_PAUSE");
}

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

public boolean isInterestPauseUpdateResource() {
return this.entityName.equalsIgnoreCase("INTEREST_PAUSE") && "UPDATE".equalsIgnoreCase(this.actionName);
}

public boolean isInterestPauseDeleteResource() {
return this.entityName.equalsIgnoreCase("INTEREST_PAUSE") && "DELETE".equalsIgnoreCase(this.actionName);
}

public Long commandId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,21 @@ public class CommandWrapperBuilder {
private String jobName;
private String idempotencyKey;
private ExternalId loanExternalId;
private Long termVariationId;

@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.loanExternalId);
this.creditBureauId, this.organisationCreditBureauId, this.jobName, this.idempotencyKey, this.loanExternalId,
this.termVariationId);
}

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.loanExternalId);
this.creditBureauId, this.organisationCreditBureauId, this.jobName, idempotencyKey, this.loanExternalId,
this.termVariationId);
}

public CommandWrapperBuilder updateCreditBureau() {
Expand Down Expand Up @@ -3732,4 +3735,22 @@ public CommandWrapperBuilder createInterestPauseByExternalId(final String loanEx
this.href = "/v1/loans/external-id/" + loanExternalId + "/interest-pauses";
return this;
}

public CommandWrapperBuilder deleteInterestPause(final long loanId, final long variationId) {
this.actionName = "DELETE";
this.entityName = "INTEREST_PAUSE";
this.loanId = loanId;
this.termVariationId = variationId;
this.href = "/v1/loans/" + loanId + "/interest-pauses/" + variationId;
return this;
}

public CommandWrapperBuilder updateInterestPause(final long loanId, final long variationId) {
this.actionName = "UPDATE";
this.entityName = "INTEREST_PAUSE";
this.loanId = loanId;
this.termVariationId = variationId;
this.href = "/v1/loans/" + loanId + "/interest-pauses/" + variationId;
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.getLoanExternalId());
wrapper.getOrganisationCreditBureauId(), wrapper.getJobName(), wrapper.getLoanExternalId(), wrapper.getTermVariationId());

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

return this.processAndLogCommandService.executeCommand(wrapper, command, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,16 @@ 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 if (wrapper.isInterestPauseResource()) {
if (wrapper.isInterestPauseCreateResource()) {
handler = applicationContext.getBean("createInterestPauseCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isInterestPauseUpdateResource()) {
handler = applicationContext.getBean("updateInterestPauseCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isInterestPauseDeleteResource()) {
handler = applicationContext.getBean("deleteInterestPauseCommandHandler", NewCommandSourceHandler.class);
} else {
throw new UnsupportedCommandException(wrapper.commandName());
}
} else {
handler = commandHandlerProvider.getHandler(wrapper.entityName(), wrapper.actionName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,33 +72,35 @@ public final class JsonCommand {
private final Long organisationCreditBureauId;
private final String jobName;
private final ExternalId loanExternalId;
private final Long termVariationId;

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 ExternalId loanExternalId) {
final Long creditBureauId, final Long organisationCreditBureauId, final String jobName, final ExternalId loanExternalId,
final Long termVariationId) {
return new JsonCommand(null, jsonCommand, parsedCommand, fromApiJsonHelper, entityName, resourceId, subresourceId, groupId,
clientId, loanId, savingsId, transactionId, url, productId, creditBureauId, organisationCreditBureauId, jobName,
loanExternalId);
loanExternalId, termVariationId);

}

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 ExternalId loanExternalId) {
final ExternalId loanExternalId, final Long termVariationId) {
return new JsonCommand(commandId, jsonCommand, parsedCommand, fromApiJsonHelper, entityName, resourceId, subresourceId, null, null,
null, null, null, url, productId, creditBureauId, organisationCreditBureauId, jobName, loanExternalId);
null, null, null, url, productId, creditBureauId, organisationCreditBureauId, jobName, loanExternalId, termVariationId);
}

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 ExternalId loanExternalId) {
final ExternalId loanExternalId, final Long termVariationId) {
return new JsonCommand(commandId, jsonCommand, parsedCommand, fromApiJsonHelper, entityName, resourceId, subresourceId, groupId,
clientId, loanId, savingsId, transactionId, url, productId, creditBureauId, organisationCreditBureauId, jobName,
loanExternalId);
loanExternalId, termVariationId);

}

Expand All @@ -107,22 +109,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.loanExternalId);
command.jobName, command.loanExternalId, command.termVariationId);
}

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.loanExternalId);
command.jobName, command.loanExternalId, command.termVariationId);
}

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 ExternalId loanExternalId) {
final ExternalId loanExternalId, final Long termVariationId) {

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

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

public JsonCommand(final Long resourceId, final JsonElement parsedCommand, final FromJsonHelper fromApiJsonHelper) {
Expand All @@ -193,11 +197,12 @@ public JsonCommand(final Long resourceId, final JsonElement parsedCommand, final
this.organisationCreditBureauId = null;
this.jobName = null;
this.loanExternalId = null;
this.termVariationId = 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,
null);
null, null);

}

Expand Down
Loading

0 comments on commit 44c9a81

Please sign in to comment.