From 74542c08675ff8716b124f6b12f25e9d8a81c9ff Mon Sep 17 00:00:00 2001 From: Muhimbura Brian Mart Date: Fri, 22 Sep 2023 16:09:22 +0300 Subject: [PATCH] Create prequalification from existing group --- .../command/PrequalificationCollectionConstants.java | 4 ++-- .../command/PrequalificatoinApiConstants.java | 1 + .../domain/PrequalificationGroup.java | 11 ++++++++--- .../PrequalificationWritePlatformServiceImpl.java | 7 ++++++- .../0086_Add_Prequalification_link_to_groups.xml | 5 +++++ 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/command/PrequalificationCollectionConstants.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/command/PrequalificationCollectionConstants.java index 036db99ca28..fd07e011bff 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/command/PrequalificationCollectionConstants.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/command/PrequalificationCollectionConstants.java @@ -26,11 +26,11 @@ public class PrequalificationCollectionConstants extends PrequalificatoinApiCons protected static final Set NEW_GROUP_PREQUALIFICATION_REQUEST_DATA_PARAMETERS = new HashSet<>(Arrays.asList(groupIdParamName, groupNameParamName, productIdParamName, portfolioIdParamName, centerIdParamName, membersParamName, dateFormatParamName, - localeParamName, agencyIdParamName, facilitatorParamName, "individual", prequalilficationTimespanParamName)); + localeParamName, agencyIdParamName, facilitatorParamName, "individual", prequalilficationTimespanParamName,previousPrequalificationParamName)); protected static final Set EDIT_GROUP_PREQUALIFICATION_REQUEST_DATA_PARAMETERS = new HashSet<>( Arrays.asList(groupIdParamName, groupNameParamName, productIdParamName, portfolioIdParamName, centerIdParamName, membersParamName, dateFormatParamName, localeParamName, agencyIdParamName, facilitatorParamName, "individual", - prequalificationNumberParamName, prequalilficationTimespanParamName)); + prequalificationNumberParamName, prequalilficationTimespanParamName,previousPrequalificationParamName)); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/command/PrequalificatoinApiConstants.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/command/PrequalificatoinApiConstants.java index e715b552220..f4fa5847eb8 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/command/PrequalificatoinApiConstants.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/command/PrequalificatoinApiConstants.java @@ -39,6 +39,7 @@ public class PrequalificatoinApiConstants { public static final String facilitatorParamName = "facilitator"; public static final String prequalificationNumberParamName = "prequalificationNumber"; public static final String prequalilficationTimespanParamName = "prequalilficationTimespan"; + public static final String previousPrequalificationParamName = "previousPrequalification"; // Members public static final String memberNameParamName = "name"; diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/domain/PrequalificationGroup.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/domain/PrequalificationGroup.java index af1896c2bbd..fc90fe9a26b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/domain/PrequalificationGroup.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/domain/PrequalificationGroup.java @@ -86,18 +86,22 @@ public class PrequalificationGroup extends AbstractPersistableCustom { @Column(name = "created_at") private LocalDateTime createdAt; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "previous_prequalification") + private PrequalificationGroup parent; + @OneToMany(mappedBy = "prequalificationGroup", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) private List members; public static PrequalificationGroup fromJson(final AppUser appUser, final AppUser facilitator, final Agency agency, final Group group, - final LoanProduct loanProduct, final JsonCommand command) { + final LoanProduct loanProduct, PrequalificationGroup parentGroup, final JsonCommand command) { String groupName = command.stringValueOfParameterNamed("groupName"); Long prequalilficationTimespan = command.longValueOfParameterNamed(PrequalificatoinApiConstants.prequalilficationTimespanParamName); Long center = command.longValueOfParameterNamed(PrequalificatoinApiConstants.centerIdParamName); if (group != null) { groupName = group.getName(); } - return new PrequalificationGroup(appUser, facilitator, agency, group, groupName, center, loanProduct, prequalilficationTimespan); + return new PrequalificationGroup(appUser, facilitator, agency, group, groupName, center, loanProduct, prequalilficationTimespan, parentGroup); } protected PrequalificationGroup() { @@ -105,7 +109,7 @@ protected PrequalificationGroup() { } private PrequalificationGroup(final AppUser appUser, final AppUser facilitator, final Agency agency, final Group group, - final String groupName, Long center, final LoanProduct loanProduct, Long prequalilficationTimespan) { + final String groupName, Long center, final LoanProduct loanProduct, Long prequalilficationTimespan, PrequalificationGroup parentGroup) { this.addedBy = appUser; this.facilitator = facilitator; this.status = PrequalificationStatus.BLACKLIST_CHECKED.getValue(); @@ -116,6 +120,7 @@ private PrequalificationGroup(final AppUser appUser, final AppUser facilitator, this.agency = agency; this.prequalificationDuration = prequalilficationTimespan; this.createdAt = DateUtils.getLocalDateTimeOfTenant(); + this.parent = parentGroup; } public void updateStatus(final PrequalificationStatus prequalificationStatus) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationWritePlatformServiceImpl.java index 27803aa4e25..b38d70f8761 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/prequalification/service/PrequalificationWritePlatformServiceImpl.java @@ -124,7 +124,12 @@ public CommandProcessingResult processPrequalification(JsonCommand command) { final Long productId = command.longValueOfParameterNamed(PrequalificatoinApiConstants.productIdParamName); final Long centerGroupId = command.longValueOfParameterNamed(PrequalificatoinApiConstants.groupIdParamName); final Long agencyId = command.longValueOfParameterNamed(PrequalificatoinApiConstants.agencyIdParamName); + final Long previousPrequalificationId = command.longValueOfParameterNamed(PrequalificatoinApiConstants.previousPrequalificationParamName); + PrequalificationGroup parentGroup = null; + if (previousPrequalificationId != null) { + parentGroup = this.prequalificationGroupRepositoryWrapper.findOneWithNotFoundDetection(previousPrequalificationId); + } Optional productOption = this.loanProductRepository.findById(productId); if (productOption.isEmpty()) throw new LoanProductNotFoundException(productId); LoanProduct loanProduct = productOption.get(); @@ -144,7 +149,7 @@ public CommandProcessingResult processPrequalification(JsonCommand command) { if (facilitatorId != null) { facilitator = this.appUserRepository.findById(facilitatorId).orElseThrow(() -> new UserNotFoundException(facilitatorId)); } - PrequalificationGroup prequalificationGroup = PrequalificationGroup.fromJson(addedBy, facilitator, agency, group, loanProduct, + PrequalificationGroup prequalificationGroup = PrequalificationGroup.fromJson(addedBy, facilitator, agency, group, loanProduct, parentGroup, command); this.prequalificationGroupRepositoryWrapper.saveAndFlush(prequalificationGroup); diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/parts/0086_Add_Prequalification_link_to_groups.xml b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0086_Add_Prequalification_link_to_groups.xml index 0b1e0845df4..9ee28b37675 100644 --- a/fineract-provider/src/main/resources/db/changelog/tenant/parts/0086_Add_Prequalification_link_to_groups.xml +++ b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0086_Add_Prequalification_link_to_groups.xml @@ -27,4 +27,9 @@ + + + + +