Skip to content

Commit

Permalink
Merge pull request #193 from fiterlatam/feature/FBR-311
Browse files Browse the repository at this point in the history
Create prequalification from existing group
  • Loading branch information
BrianMuhimbura authored Sep 22, 2023
2 parents 3933760 + 74542c0 commit a536b15
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public class PrequalificationCollectionConstants extends PrequalificatoinApiCons

protected static final Set<String> 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<String> 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));

}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,30 @@ 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<PrequalificationGroupMember> 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() {
//
}

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();
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<LoanProduct> productOption = this.loanProductRepository.findById(productId);
if (productOption.isEmpty()) throw new LoanProductNotFoundException(productId);
LoanProduct loanProduct = productOption.get();
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@
<column name="prequalification_id" type="BIGINT" />
</addColumn>
</changeSet>
<changeSet author="fineract" id="2">
<addColumn tableName="m_prequalification_group">
<column name="previous_prequalification" type="BIGINT" />
</addColumn>
</changeSet>
</databaseChangeLog>

0 comments on commit a536b15

Please sign in to comment.