Skip to content

Commit

Permalink
Bug/FBR-418: Make Loan Additional Optional (#336)
Browse files Browse the repository at this point in the history
Co-authored-by: Julius Peter Oketayot <[email protected]>
  • Loading branch information
fiter-julius-oketayot and Julius Peter Oketayot authored Dec 13, 2023
1 parent 4f143e8 commit 7f7c97c
Showing 1 changed file with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -706,16 +706,18 @@ public CommandProcessingResult submitApplication(final JsonCommand command) {
// Additional Data (Individual Prequalification)
final PrequalificationGroup prequalificationGroup = newLoanApplication.getPrequalificationGroup();
if (prequalificationGroup != null && prequalificationGroup.isPrequalificationTypeIndividual()) {
this.fromApiJsonDeserializer.validateLoanAdditionalData(command);
final JsonElement loanAdditionalDataJson = command.jsonElement(LoanApiConstants.LOAN_ADDITIONAL_DATA);
final LoanAdditionalData loanAdditionalData = bureauValidationWritePlatformService.mapFromJson(loanAdditionalDataJson);
final String caseId = this.fromJsonHelper.extractStringNamed(LoanApiConstants.CASE_ID, loanAdditionalDataJson);
final Client loanClient = newLoanApplication.getClient();
final LoanAdditionProperties loanAdditionProperties = loanAdditionalData.toEntity();
loanAdditionProperties.setCaseId(caseId);
loanAdditionProperties.setClient(loanClient);
loanAdditionProperties.setLoan(newLoanApplication);
loanAdditionalPropertiesRepository.saveAndFlush(loanAdditionProperties);
if (loanAdditionalDataJson != null && loanAdditionalDataJson.isJsonObject()) {
this.fromApiJsonDeserializer.validateLoanAdditionalData(command);
final LoanAdditionalData loanAdditionalData = bureauValidationWritePlatformService.mapFromJson(loanAdditionalDataJson);
final String caseId = this.fromJsonHelper.extractStringNamed(LoanApiConstants.CASE_ID, loanAdditionalDataJson);
final Client loanClient = newLoanApplication.getClient();
final LoanAdditionProperties loanAdditionProperties = loanAdditionalData.toEntity();
loanAdditionProperties.setCaseId(caseId);
loanAdditionProperties.setClient(loanClient);
loanAdditionProperties.setLoan(newLoanApplication);
loanAdditionalPropertiesRepository.saveAndFlush(loanAdditionProperties);
}
}

if (command.parameterExists(LoanApiConstants.datatables)) {
Expand Down Expand Up @@ -1414,24 +1416,26 @@ public CommandProcessingResult modifyApplication(final Long loanId, final JsonCo
}

if (prequalificationGroup.isPrequalificationTypeIndividual()) {
this.fromApiJsonDeserializer.validateLoanAdditionalData(command);
final JsonElement loanAdditionalDataJson = command.jsonElement(LoanApiConstants.LOAN_ADDITIONAL_DATA);
final LoanAdditionalData loanAdditionalData = bureauValidationWritePlatformService.mapFromJson(loanAdditionalDataJson);
final String caseId = this.fromJsonHelper.extractStringNamed(LoanApiConstants.CASE_ID, loanAdditionalDataJson);
final Client loanClient = existingLoanApplication.getClient();
final List<LoanAdditionProperties> additionalList = this.loanAdditionalPropertiesRepository
.findByClientIdAndLoanId(loanClient.getId(), existingLoanApplication.getId());
LoanAdditionProperties loanAdditionEntity;
if (!CollectionUtils.isEmpty(additionalList)) {
loanAdditionEntity = additionalList.get(0);
BeanUtils.copyProperties(loanAdditionalData, loanAdditionEntity);
} else {
loanAdditionEntity = loanAdditionalData.toEntity();
if (loanAdditionalDataJson != null && loanAdditionalDataJson.isJsonObject()) {
this.fromApiJsonDeserializer.validateLoanAdditionalData(command);
final LoanAdditionalData loanAdditionalData = bureauValidationWritePlatformService.mapFromJson(loanAdditionalDataJson);
final String caseId = this.fromJsonHelper.extractStringNamed(LoanApiConstants.CASE_ID, loanAdditionalDataJson);
final Client loanClient = existingLoanApplication.getClient();
final List<LoanAdditionProperties> additionalList = this.loanAdditionalPropertiesRepository
.findByClientIdAndLoanId(loanClient.getId(), existingLoanApplication.getId());
LoanAdditionProperties loanAdditionEntity;
if (!CollectionUtils.isEmpty(additionalList)) {
loanAdditionEntity = additionalList.get(0);
BeanUtils.copyProperties(loanAdditionalData, loanAdditionEntity);
} else {
loanAdditionEntity = loanAdditionalData.toEntity();
}
loanAdditionEntity.setCaseId(caseId);
loanAdditionEntity.setClient(loanClient);
loanAdditionEntity.setLoan(existingLoanApplication);
loanAdditionalPropertiesRepository.saveAndFlush(loanAdditionEntity);
}
loanAdditionEntity.setCaseId(caseId);
loanAdditionEntity.setClient(loanClient);
loanAdditionEntity.setLoan(existingLoanApplication);
loanAdditionalPropertiesRepository.saveAndFlush(loanAdditionEntity);
}

// updating loan interest recalculation details throwing null
Expand Down

0 comments on commit 7f7c97c

Please sign in to comment.