Skip to content

Commit 76d1089

Browse files
rhopmanadamsaghy
authored andcommitted
FINERACT-2498: Add GROUP as a Guarantor Type to Support Group Savings Accounts as Loan Collateral
1 parent 55c51b1 commit 76d1089

File tree

11 files changed

+387
-9
lines changed

11 files changed

+387
-9
lines changed

fineract-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/guarantor/domain/GuarantorType.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public enum GuarantorType {
2525

2626
CUSTOMER(1, "guarantor.existing.customer"), //
2727
STAFF(2, "guarantor.staff"), //
28-
EXTERNAL(3, "guarantor.external"); //
28+
EXTERNAL(3, "guarantor.external"), //
29+
GROUP(4, "guarantor.existing.group"); //
2930

3031
private final Integer value;
3132
private final String code;
@@ -90,4 +91,8 @@ public boolean isStaff() {
9091
return this.value.equals(GuarantorType.STAFF.getValue());
9192
}
9293

94+
public boolean isGroup() {
95+
return this.value.equals(GuarantorType.GROUP.getValue());
96+
}
97+
9398
}

fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/constants/TemplatePopulateImportConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ private TemplatePopulateImportConstants() {
141141
// Guarantor Types
142142
public static final String GUARANTOR_INTERNAL = "Internal";
143143
public static final String GUARANTOR_EXTERNAL = "External";
144+
public static final String GUARANTOR_GROUP = "Group";
144145

145146
// Loan Account/Loan repayment Client External Id
146147
public static final Boolean CONTAINS_CLIENT_EXTERNAL_ID = true;

fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/importhandler/guarantor/GuarantorImportHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ private GuarantorData readGuarantor(final Workbook workbook, final Row row, Long
9494
guarantorTypeId = 1;
9595
} else if (guarantorType.equalsIgnoreCase(TemplatePopulateImportConstants.GUARANTOR_EXTERNAL)) {
9696
guarantorTypeId = 3;
97+
} else if (guarantorType.equalsIgnoreCase(TemplatePopulateImportConstants.GUARANTOR_GROUP)) {
98+
guarantorTypeId = 4;
9799
}
98100
}
99101
String clientName = ImportHandlerUtils.readAsString(GuarantorConstants.ENTITY_ID_COL, row);

fineract-provider/src/main/java/org/apache/fineract/infrastructure/bulkimport/populator/guarantor/GuarantorWorkbookPopulator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,9 @@ private void setRules(Sheet worksheet) {
209209
"INDIRECT(CONCATENATE(\"Account_\",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($B1,\" \",\"_\"),\"(\",\"_\"),\")\",\"_\")))");
210210
DataValidationConstraint savingsaccountNumberConstraint = validationHelper.createFormulaListConstraint(
211211
"INDIRECT(CONCATENATE(\"SavingsAccount_\",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($G1,\" \",\"_\"),\"(\",\"_\"),\")\",\"_\")))");
212-
DataValidationConstraint guranterTypeConstraint = validationHelper.createExplicitListConstraint(
213-
new String[] { TemplatePopulateImportConstants.GUARANTOR_INTERNAL, TemplatePopulateImportConstants.GUARANTOR_EXTERNAL });
212+
DataValidationConstraint guranterTypeConstraint = validationHelper
213+
.createExplicitListConstraint(new String[] { TemplatePopulateImportConstants.GUARANTOR_INTERNAL,
214+
TemplatePopulateImportConstants.GUARANTOR_EXTERNAL, TemplatePopulateImportConstants.GUARANTOR_GROUP });
214215
DataValidationConstraint guarantorRelationshipConstraint = validationHelper.createFormulaListConstraint("GuarantorRelationship");
215216
DataValidationConstraint entityofficeNameConstraint = validationHelper.createFormulaListConstraint("Office");
216217
DataValidationConstraint entityclientNameConstraint = validationHelper

fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/guarantor/data/GuarantorData.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,8 @@ public boolean isExistingClient() {
207207
public boolean isStaffMember() {
208208
return GuarantorType.STAFF.getValue().equals(this.guarantorType.getId().intValue());
209209
}
210+
211+
public boolean isExistingGroup() {
212+
return GuarantorType.GROUP.getValue().equals(this.guarantorType.getId().intValue());
213+
}
210214
}

fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/guarantor/domain/Guarantor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ public boolean isExistingEmployee() {
188188
return GuarantorType.STAFF.getValue().equals(this.gurantorType);
189189
}
190190

191+
public boolean isExistingGroup() {
192+
return GuarantorType.GROUP.getValue().equals(this.gurantorType);
193+
}
194+
191195
public boolean isExternalGuarantor() {
192196
return GuarantorType.EXTERNAL.getValue().equals(this.gurantorType);
193197
}

fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/guarantor/service/GuarantorDomainServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ private void releaseGuarantorFunds(final LoanTransaction loanTransaction) {
390390
if (guarantor.isSelfGuarantee()) {
391391
selfGuarantorList.add(guarantorFundingDetails);
392392
selfGuarantee = selfGuarantee.add(guarantorFundingDetails.getAmountRemaining());
393-
} else if (guarantor.isExistingCustomer()) {
393+
} else if (guarantor.isExistingCustomer() || guarantor.isExistingGroup()) {
394394
externalGuarantorList.add(guarantorFundingDetails);
395395
guarantorGuarantee = guarantorGuarantee.add(guarantorFundingDetails.getAmountRemaining());
396396
}

fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/guarantor/service/GuarantorWritePlatformServiceJpaRepositoryIImpl.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.apache.fineract.portfolio.account.domain.AccountAssociations;
3939
import org.apache.fineract.portfolio.account.domain.AccountAssociationsRepository;
4040
import org.apache.fineract.portfolio.client.domain.ClientRepositoryWrapper;
41+
import org.apache.fineract.portfolio.group.domain.GroupRepositoryWrapper;
4142
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
4243
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepositoryWrapper;
4344
import org.apache.fineract.portfolio.loanaccount.guarantor.GuarantorConstants;
@@ -70,6 +71,7 @@ public class GuarantorWritePlatformServiceJpaRepositoryIImpl implements Guaranto
7071

7172
private final ClientRepositoryWrapper clientRepositoryWrapper;
7273
private final StaffRepositoryWrapper staffRepositoryWrapper;
74+
private final GroupRepositoryWrapper groupRepositoryWrapper;
7375
private final LoanRepositoryWrapper loanRepositoryWrapper;
7476
private final GuarantorRepository guarantorRepository;
7577
private final GuarantorCommandFromApiJsonDeserializer fromApiJsonDeserializer;
@@ -81,11 +83,13 @@ public class GuarantorWritePlatformServiceJpaRepositoryIImpl implements Guaranto
8183
@Autowired
8284
public GuarantorWritePlatformServiceJpaRepositoryIImpl(final LoanRepositoryWrapper loanRepositoryWrapper,
8385
final GuarantorRepository guarantorRepository, final ClientRepositoryWrapper clientRepositoryWrapper,
84-
final StaffRepositoryWrapper staffRepositoryWrapper, final GuarantorCommandFromApiJsonDeserializer fromApiJsonDeserializer,
86+
final StaffRepositoryWrapper staffRepositoryWrapper, final GroupRepositoryWrapper groupRepositoryWrapper,
87+
final GuarantorCommandFromApiJsonDeserializer fromApiJsonDeserializer,
8588
final CodeValueRepositoryWrapper codeValueRepositoryWrapper, final SavingsAccountAssembler savingsAccountAssembler,
8689
final AccountAssociationsRepository accountAssociationsRepository, final GuarantorDomainService guarantorDomainService) {
8790
this.loanRepositoryWrapper = loanRepositoryWrapper;
8891
this.clientRepositoryWrapper = clientRepositoryWrapper;
92+
this.groupRepositoryWrapper = groupRepositoryWrapper;
8993
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
9094
this.guarantorRepository = guarantorRepository;
9195
this.staffRepositoryWrapper = staffRepositoryWrapper;
@@ -148,6 +152,8 @@ private CommandProcessingResult createGuarantor(final Loan loan, final JsonComma
148152
String defaultUserMessage = null;
149153
if (guarantorTypeId.equals(GuarantorType.STAFF.getValue())) {
150154
defaultUserMessage = this.staffRepositoryWrapper.findOneWithNotFoundDetection(entityId).displayName();
155+
} else if (guarantorTypeId.equals(GuarantorType.GROUP.getValue())) {
156+
defaultUserMessage = this.groupRepositoryWrapper.findOneWithNotFoundDetection(entityId).getName();
151157
} else {
152158
defaultUserMessage = this.clientRepositoryWrapper.findOneWithNotFoundDetection(entityId).getDisplayName();
153159
}
@@ -225,12 +231,19 @@ public CommandProcessingResult updateGuarantor(final Long loanId, final Long gua
225231
final List<Guarantor> existGuarantorList = this.guarantorRepository.findByLoan(loan);
226232
final Integer guarantorTypeId = guarantorCommand.getGuarantorTypeId();
227233
final GuarantorType guarantorType = GuarantorType.fromInt(guarantorTypeId);
228-
if (guarantorType.isCustomer() || guarantorType.isStaff()) {
234+
if (guarantorType.isCustomer() || guarantorType.isStaff() || guarantorType.isGroup()) {
229235
final Long entityId = guarantorCommand.getEntityId();
230236
for (final Guarantor guarantor : existGuarantorList) {
231237
if (guarantor.getEntityId().equals(entityId) && guarantor.getGurantorType().equals(guarantorTypeId)
232238
&& !guarantorForUpdate.getId().equals(guarantor.getId())) {
233-
String defaultUserMessage = this.clientRepositoryWrapper.findOneWithNotFoundDetection(entityId).getDisplayName();
239+
String defaultUserMessage = null;
240+
if (guarantorTypeId.equals(GuarantorType.STAFF.getValue())) {
241+
defaultUserMessage = this.staffRepositoryWrapper.findOneWithNotFoundDetection(entityId).displayName();
242+
} else if (guarantorTypeId.equals(GuarantorType.GROUP.getValue())) {
243+
defaultUserMessage = this.groupRepositoryWrapper.findOneWithNotFoundDetection(entityId).getName();
244+
} else {
245+
defaultUserMessage = this.clientRepositoryWrapper.findOneWithNotFoundDetection(entityId).getDisplayName();
246+
}
234247
defaultUserMessage = defaultUserMessage + " is already exist as a guarantor for this loan";
235248
final String action = loan.client() != null ? "client.guarantor" : "group.guarantor";
236249
throw new DuplicateGuarantorException(action, "is.already.exist.same.loan", defaultUserMessage, entityId, loanId);
@@ -336,6 +349,9 @@ private void validateGuarantorBusinessRules(final Guarantor guarantor) {
336349

337350
} else if (guarantor.isExistingEmployee()) {
338351
this.staffRepositoryWrapper.findOneWithNotFoundDetection(guarantor.getEntityId());
352+
} else if (guarantor.isExistingGroup()) {
353+
// check group exists
354+
this.groupRepositoryWrapper.findOneWithNotFoundDetection(guarantor.getEntityId());
339355
}
340356
}
341357

0 commit comments

Comments
 (0)