Skip to content

Commit c2ec015

Browse files
kulminskyadamsaghy
authored andcommitted
FINERACT-2152: API Create and retrieve interest pause
1 parent e94e6c4 commit c2ec015

File tree

39 files changed

+1112
-43
lines changed

39 files changed

+1112
-43
lines changed

fineract-core/src/main/java/org/apache/fineract/commands/domain/CommandSource.java

+5
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ public class CommandSource extends AbstractPersistableCustom<Long> {
133133
@Column(name = "result_status_code")
134134
private Integer resultStatusCode;
135135

136+
@Column(name = "loan_external_id", length = 100)
137+
private ExternalId loanExternalId;
138+
136139
public static CommandSource fullEntryFrom(final CommandWrapper wrapper, final JsonCommand command, final AppUser maker,
137140
String idempotencyKey, Integer status) {
138141

@@ -156,6 +159,7 @@ public static CommandSource fullEntryFrom(final CommandWrapper wrapper, final Js
156159
.transactionId(command.getTransactionId()) //
157160
.creditBureauId(command.getCreditBureauId()) //
158161
.organisationCreditBureauId(command.getOrganisationCreditBureauId()) //
162+
.loanExternalId(command.getLoanExternalId()) //
159163
.build(); //
160164
}
161165

@@ -195,5 +199,6 @@ public void updateForAudit(final CommandProcessingResult result) {
195199
this.resourceExternalId = result.getResourceExternalId();
196200
this.subResourceId = result.getSubResourceId();
197201
this.subResourceExternalId = result.getSubResourceExternalId();
202+
this.loanExternalId = result.getLoanExternalId();
198203
}
199204
}

fineract-core/src/main/java/org/apache/fineract/commands/domain/CommandWrapper.java

+19-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.fineract.commands.domain;
2020

2121
import lombok.Getter;
22+
import org.apache.fineract.infrastructure.core.domain.ExternalId;
2223
import org.apache.fineract.useradministration.api.PasswordPreferencesApiConstants;
2324

2425
@Getter
@@ -43,6 +44,7 @@ public class CommandWrapper {
4344
private final Long creditBureauId;
4445
private final Long organisationCreditBureauId;
4546
private final String jobName;
47+
private final ExternalId loanExternalId;
4648

4749
private final String idempotencyKey;
4850

@@ -61,9 +63,11 @@ public static CommandWrapper fromExistingCommand(final Long commandId, final Str
6163
public static CommandWrapper fromExistingCommand(final Long commandId, final String actionName, final String entityName,
6264
final Long resourceId, final Long subresourceId, final String resourceGetUrl, final Long productId, final Long officeId,
6365
final Long groupId, final Long clientId, final Long loanId, final Long savingsId, final String transactionId,
64-
final Long creditBureauId, final Long organisationCreditBureauId, final String idempotencyKey) {
66+
final Long creditBureauId, final Long organisationCreditBureauId, final String idempotencyKey,
67+
final ExternalId loanExternalId) {
6568
return new CommandWrapper(commandId, actionName, entityName, resourceId, subresourceId, resourceGetUrl, productId, officeId,
66-
groupId, clientId, loanId, savingsId, transactionId, creditBureauId, organisationCreditBureauId, idempotencyKey);
69+
groupId, clientId, loanId, savingsId, transactionId, creditBureauId, organisationCreditBureauId, idempotencyKey,
70+
loanExternalId);
6771
}
6872

6973
private CommandWrapper(final Long commandId, final String actionName, final String entityName, final Long resourceId,
@@ -87,12 +91,13 @@ private CommandWrapper(final Long commandId, final String actionName, final Stri
8791
this.organisationCreditBureauId = null;
8892
this.jobName = null;
8993
this.idempotencyKey = null;
94+
this.loanExternalId = null;
9095
}
9196

9297
public CommandWrapper(final Long officeId, final Long groupId, final Long clientId, final Long loanId, final Long savingsId,
9398
final String actionName, final String entityName, final Long entityId, final Long subentityId, final String href,
9499
final String json, final String transactionId, final Long productId, final Long templateId, final Long creditBureauId,
95-
final Long organisationCreditBureauId, final String jobName, final String idempotencyKey) {
100+
final Long organisationCreditBureauId, final String jobName, final String idempotencyKey, final ExternalId loanExternalId) {
96101

97102
this.commandId = null;
98103
this.officeId = officeId;
@@ -114,12 +119,13 @@ public CommandWrapper(final Long officeId, final Long groupId, final Long client
114119
this.organisationCreditBureauId = organisationCreditBureauId;
115120
this.jobName = jobName;
116121
this.idempotencyKey = idempotencyKey;
122+
this.loanExternalId = loanExternalId;
117123
}
118124

119125
private CommandWrapper(final Long commandId, final String actionName, final String entityName, final Long resourceId,
120126
final Long subresourceId, final String resourceGetUrl, final Long productId, final Long officeId, final Long groupId,
121127
final Long clientId, final Long loanId, final Long savingsId, final String transactionId, final Long creditBureauId,
122-
final Long organisationCreditBureauId, final String idempotencyKey) {
128+
final Long organisationCreditBureauId, final String idempotencyKey, final ExternalId loanExternalId) {
123129

124130
this.commandId = commandId;
125131
this.officeId = officeId;
@@ -140,6 +146,7 @@ private CommandWrapper(final Long commandId, final String actionName, final Stri
140146
this.organisationCreditBureauId = organisationCreditBureauId;
141147
this.jobName = null;
142148
this.idempotencyKey = idempotencyKey;
149+
this.loanExternalId = loanExternalId;
143150
}
144151

145152
public boolean isCreate() {
@@ -240,6 +247,14 @@ public boolean isPasswordPreferencesResource() {
240247
return this.entityName.equalsIgnoreCase(PasswordPreferencesApiConstants.ENTITY_NAME);
241248
}
242249

250+
public boolean isInterestPauseResource() {
251+
return this.entityName.equalsIgnoreCase("INTEREST_PAUSE");
252+
}
253+
254+
public boolean isInterestPauseExternalIdResource() {
255+
return this.entityName.equalsIgnoreCase("INTEREST_PAUSE") && this.href.contains("/external-id/");
256+
}
257+
243258
public Long commandId() {
244259
return this.commandId;
245260
}

fineract-core/src/main/java/org/apache/fineract/commands/service/CommandWrapperBuilder.java

+20-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2222
import org.apache.fineract.commands.domain.CommandWrapper;
2323
import org.apache.fineract.infrastructure.accountnumberformat.service.AccountNumberFormatConstants;
24+
import org.apache.fineract.infrastructure.core.domain.ExternalId;
2425
import org.apache.fineract.portfolio.client.api.ClientApiConstants;
2526
import org.apache.fineract.portfolio.paymenttype.api.PaymentTypeApiResourceConstants;
2627
import org.apache.fineract.portfolio.savings.DepositsApiConstants;
@@ -47,18 +48,19 @@ public class CommandWrapperBuilder {
4748
private Long organisationCreditBureauId;
4849
private String jobName;
4950
private String idempotencyKey;
51+
private ExternalId loanExternalId;
5052

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

5860
public CommandWrapper build(String idempotencyKey) {
5961
return new CommandWrapper(this.officeId, this.groupId, this.clientId, this.loanId, this.savingsId, this.actionName, this.entityName,
6062
this.entityId, this.subentityId, this.href, this.json, this.transactionId, this.productId, this.templateId,
61-
this.creditBureauId, this.organisationCreditBureauId, this.jobName, idempotencyKey);
63+
this.creditBureauId, this.organisationCreditBureauId, this.jobName, idempotencyKey, this.loanExternalId);
6264
}
6365

6466
public CommandWrapperBuilder updateCreditBureau() {
@@ -3714,4 +3716,20 @@ public CommandWrapperBuilder createDelinquencyAction(final Long loanId) {
37143716
this.href = "/loans/" + loanId + "/delinquency-action";
37153717
return this;
37163718
}
3719+
3720+
public CommandWrapperBuilder createInterestPause(final long loanId) {
3721+
this.actionName = "CREATE";
3722+
this.entityName = "INTEREST_PAUSE";
3723+
this.loanId = loanId;
3724+
this.href = "/v1/loans/" + loanId + "/interest-pauses";
3725+
return this;
3726+
}
3727+
3728+
public CommandWrapperBuilder createInterestPauseByExternalId(final String loanExternalId) {
3729+
this.actionName = "CREATE";
3730+
this.entityName = "INTEREST_PAUSE";
3731+
this.loanExternalId = new ExternalId(loanExternalId);
3732+
this.href = "/v1/loans/external-id/" + loanExternalId + "/interest-pauses";
3733+
return this;
3734+
}
37173735
}

fineract-core/src/main/java/org/apache/fineract/commands/service/PortfolioCommandSourceWritePlatformServiceImpl.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public CommandProcessingResult logCommandSource(final CommandWrapper wrapper) {
7373
JsonCommand command = JsonCommand.from(json, parsedCommand, this.fromApiJsonHelper, wrapper.getEntityName(), wrapper.getEntityId(),
7474
wrapper.getSubentityId(), wrapper.getGroupId(), wrapper.getClientId(), wrapper.getLoanId(), wrapper.getSavingsId(),
7575
wrapper.getTransactionId(), wrapper.getHref(), wrapper.getProductId(), wrapper.getCreditBureauId(),
76-
wrapper.getOrganisationCreditBureauId(), wrapper.getJobName());
76+
wrapper.getOrganisationCreditBureauId(), wrapper.getJobName(), wrapper.getLoanExternalId());
7777

7878
return this.processAndLogCommandService.executeCommand(wrapper, command, isApprovedByChecker);
7979
}
@@ -88,14 +88,16 @@ public CommandProcessingResult approveEntry(final Long makerCheckerId) {
8888
commandSourceInput.getResourceGetUrl(), commandSourceInput.getProductId(), commandSourceInput.getOfficeId(),
8989
commandSourceInput.getGroupId(), commandSourceInput.getClientId(), commandSourceInput.getLoanId(),
9090
commandSourceInput.getSavingsId(), commandSourceInput.getTransactionId(), commandSourceInput.getCreditBureauId(),
91-
commandSourceInput.getOrganisationCreditBureauId(), commandSourceInput.getIdempotencyKey());
91+
commandSourceInput.getOrganisationCreditBureauId(), commandSourceInput.getIdempotencyKey(),
92+
commandSourceInput.getLoanExternalId());
9293
final JsonElement parsedCommand = this.fromApiJsonHelper.parse(commandSourceInput.getCommandAsJson());
9394
final JsonCommand command = JsonCommand.fromExistingCommand(makerCheckerId, commandSourceInput.getCommandAsJson(), parsedCommand,
9495
this.fromApiJsonHelper, commandSourceInput.getEntityName(), commandSourceInput.getResourceId(),
9596
commandSourceInput.getSubResourceId(), commandSourceInput.getGroupId(), commandSourceInput.getClientId(),
9697
commandSourceInput.getLoanId(), commandSourceInput.getSavingsId(), commandSourceInput.getTransactionId(),
9798
commandSourceInput.getResourceGetUrl(), commandSourceInput.getProductId(), commandSourceInput.getCreditBureauId(),
98-
commandSourceInput.getOrganisationCreditBureauId(), commandSourceInput.getJobName());
99+
commandSourceInput.getOrganisationCreditBureauId(), commandSourceInput.getJobName(),
100+
commandSourceInput.getLoanExternalId());
99101

100102
return this.processAndLogCommandService.executeCommand(wrapper, command, true);
101103
}

fineract-core/src/main/java/org/apache/fineract/commands/service/SynchronousCommandProcessingService.java

+2
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ private NewCommandSourceHandler findCommandHandler(final CommandWrapper wrapper)
249249
} else {
250250
throw new UnsupportedCommandException(wrapper.commandName());
251251
}
252+
} else if (wrapper.isInterestPauseResource() || wrapper.isInterestPauseExternalIdResource()) {
253+
handler = applicationContext.getBean("interestPauseCommandHandler", NewCommandSourceHandler.class);
252254
} else {
253255
handler = commandHandlerProvider.getHandler(wrapper.entityName(), wrapper.actionName());
254256
}

fineract-core/src/main/java/org/apache/fineract/infrastructure/core/api/JsonCommand.java

+20-11
Original file line numberDiff line numberDiff line change
@@ -71,30 +71,34 @@ public final class JsonCommand {
7171
private final Long creditBureauId;
7272
private final Long organisationCreditBureauId;
7373
private final String jobName;
74+
private final ExternalId loanExternalId;
7475

7576
public static JsonCommand from(final String jsonCommand, final JsonElement parsedCommand, final FromJsonHelper fromApiJsonHelper,
7677
final String entityName, final Long resourceId, final Long subresourceId, final Long groupId, final Long clientId,
7778
final Long loanId, final Long savingsId, final String transactionId, final String url, final Long productId,
78-
final Long creditBureauId, final Long organisationCreditBureauId, final String jobName) {
79+
final Long creditBureauId, final Long organisationCreditBureauId, final String jobName, final ExternalId loanExternalId) {
7980
return new JsonCommand(null, jsonCommand, parsedCommand, fromApiJsonHelper, entityName, resourceId, subresourceId, groupId,
80-
clientId, loanId, savingsId, transactionId, url, productId, creditBureauId, organisationCreditBureauId, jobName);
81+
clientId, loanId, savingsId, transactionId, url, productId, creditBureauId, organisationCreditBureauId, jobName,
82+
loanExternalId);
8183

8284
}
8385

8486
public static JsonCommand fromExistingCommand(final Long commandId, final String jsonCommand, final JsonElement parsedCommand,
8587
final FromJsonHelper fromApiJsonHelper, final String entityName, final Long resourceId, final Long subresourceId,
86-
final String url, final Long productId, final Long creditBureauId, final Long organisationCreditBureauId,
87-
final String jobName) {
88+
final String url, final Long productId, final Long creditBureauId, final Long organisationCreditBureauId, final String jobName,
89+
final ExternalId loanExternalId) {
8890
return new JsonCommand(commandId, jsonCommand, parsedCommand, fromApiJsonHelper, entityName, resourceId, subresourceId, null, null,
89-
null, null, null, url, productId, creditBureauId, organisationCreditBureauId, jobName);
91+
null, null, null, url, productId, creditBureauId, organisationCreditBureauId, jobName, loanExternalId);
9092
}
9193

9294
public static JsonCommand fromExistingCommand(final Long commandId, final String jsonCommand, final JsonElement parsedCommand,
9395
final FromJsonHelper fromApiJsonHelper, final String entityName, final Long resourceId, final Long subresourceId,
9496
final Long groupId, final Long clientId, final Long loanId, final Long savingsId, final String transactionId, final String url,
95-
final Long productId, Long creditBureauId, final Long organisationCreditBureauId, final String jobName) {
97+
final Long productId, Long creditBureauId, final Long organisationCreditBureauId, final String jobName,
98+
final ExternalId loanExternalId) {
9699
return new JsonCommand(commandId, jsonCommand, parsedCommand, fromApiJsonHelper, entityName, resourceId, subresourceId, groupId,
97-
clientId, loanId, savingsId, transactionId, url, productId, creditBureauId, organisationCreditBureauId, jobName);
100+
clientId, loanId, savingsId, transactionId, url, productId, creditBureauId, organisationCreditBureauId, jobName,
101+
loanExternalId);
98102

99103
}
100104

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

109113
public static JsonCommand fromExistingCommand(JsonCommand command, final JsonElement parsedCommand, final Long clientId) {
110114
final String jsonCommand = command.fromApiJsonHelper.toJson(parsedCommand);
111115
return new JsonCommand(command.commandId, jsonCommand, parsedCommand, command.fromApiJsonHelper, command.entityName,
112116
command.resourceId, command.subresourceId, command.groupId, clientId, command.loanId, command.savingsId,
113117
command.transactionId, command.url, command.productId, command.creditBureauId, command.organisationCreditBureauId,
114-
command.jobName);
118+
command.jobName, command.loanExternalId);
115119
}
116120

117121
public JsonCommand(final Long commandId, final String jsonCommand, final JsonElement parsedCommand,
118122
final FromJsonHelper fromApiJsonHelper, final String entityName, final Long resourceId, final Long subresourceId,
119123
final Long groupId, final Long clientId, final Long loanId, final Long savingsId, final String transactionId, final String url,
120-
final Long productId, final Long creditBureauId, final Long organisationCreditBureauId, final String jobName) {
124+
final Long productId, final Long creditBureauId, final Long organisationCreditBureauId, final String jobName,
125+
final ExternalId loanExternalId) {
121126

122127
this.commandId = commandId;
123128
this.jsonCommand = jsonCommand;
@@ -136,6 +141,7 @@ public JsonCommand(final Long commandId, final String jsonCommand, final JsonEle
136141
this.creditBureauId = creditBureauId;
137142
this.organisationCreditBureauId = organisationCreditBureauId;
138143
this.jobName = jobName;
144+
this.loanExternalId = loanExternalId;
139145
}
140146

141147
public static JsonCommand fromJsonElement(final Long resourceId, final JsonElement parsedCommand) {
@@ -165,6 +171,7 @@ public JsonCommand(final Long resourceId, final JsonElement parsedCommand) {
165171
this.creditBureauId = null;
166172
this.organisationCreditBureauId = null;
167173
this.jobName = null;
174+
this.loanExternalId = null;
168175
}
169176

170177
public JsonCommand(final Long resourceId, final JsonElement parsedCommand, final FromJsonHelper fromApiJsonHelper) {
@@ -185,10 +192,12 @@ public JsonCommand(final Long resourceId, final JsonElement parsedCommand, final
185192
this.creditBureauId = null;
186193
this.organisationCreditBureauId = null;
187194
this.jobName = null;
195+
this.loanExternalId = null;
188196
}
189197

190198
public static JsonCommand from(final String jsonCommand) {
191-
return new JsonCommand(null, jsonCommand, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
199+
return new JsonCommand(null, jsonCommand, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
200+
null);
192201

193202
}
194203

0 commit comments

Comments
 (0)