Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FINERACT-1971: Fix Delinquency bucket error upon Loan product editing #3712

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public class LoanProduct extends AbstractPersistableCustom {
private Integer overAppliedNumber;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "delinquency_bucket_id")
@JoinColumn(name = "delinquency_bucket_id", nullable = true)
private DelinquencyBucket delinquencyBucket;

@Column(name = "enable_installment_level_delinquency", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ public LoanProductData mapRow(@NotNull final ResultSet rs, @SuppressWarnings("un
final boolean isRatesEnabled = false;

// Delinquency Buckets
final Long delinquencyBucketId = rs.getLong("delinquencyBucketId");
final Long delinquencyBucketId = JdbcSupport.getLong(rs, "delinquencyBucketId");
final String delinquencyBucketName = rs.getString("delinquencyBucketName");
final DelinquencyBucketData delinquencyBucket = new DelinquencyBucketData(delinquencyBucketId, delinquencyBucketName,
new ArrayList<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,8 @@ public CommandProcessingResult createLoanProduct(final JsonCommand command) {
loanRepaymentScheduleTransactionProcessorFactory.determineProcessor(loanTransactionProcessingStrategyCode).getName());

if (command.parameterExists("delinquencyBucketId")) {
DelinquencyBucket delinquencyBucket = this.delinquencyBucketRepository
.getReferenceById(command.longValueOfParameterNamed("delinquencyBucketId"));
loanProduct.setDelinquencyBucket(delinquencyBucket);
loanProduct
.setDelinquencyBucket(findDelinquencyBucketIdIfProvided(command.longValueOfParameterNamed("delinquencyBucketId")));
}

this.loanProductRepository.saveAndFlush(loanProduct);
Expand Down Expand Up @@ -168,6 +167,15 @@ private Fund findFundByIdIfProvided(final Long fundId) {
return fund;
}

private DelinquencyBucket findDelinquencyBucketIdIfProvided(final Long delinquencyBucketId) {
DelinquencyBucket delinquencyBucket = null;
if (delinquencyBucketId != null) {
delinquencyBucket = delinquencyBucketRepository.findById(delinquencyBucketId)
.orElseThrow(() -> new FundNotFoundException(delinquencyBucketId));
}
return delinquencyBucket;
}

@Transactional
@Override
public CommandProcessingResult updateLoanProduct(final Long loanProductId, final JsonCommand command) {
Expand Down Expand Up @@ -201,9 +209,7 @@ public CommandProcessingResult updateLoanProduct(final Long loanProductId, final
}

if (changes.containsKey("delinquencyBucketId")) {
final Long delinquencyBucketId = (Long) changes.get("delinquencyBucketId");
final DelinquencyBucket delinquencyBucket = this.delinquencyBucketRepository.getReferenceById(delinquencyBucketId);
product.setDelinquencyBucket(delinquencyBucket);
product.setDelinquencyBucket(findDelinquencyBucketIdIfProvided((Long) changes.get("delinquencyBucketId")));
}

if (changes.containsKey("transactionProcessingStrategyCode")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,20 @@ public void testLoanProductCreationWithAndWithoutDelinquencyBucket() {
// Loan product creation without Delinquency bucket
GetLoanProductsProductIdResponse getLoanProductResponse = createLoanProduct(loanTransactionHelper, null, null);
assertNotNull(getLoanProductResponse);
assertNull(getLoanProductResponse.getDelinquencyBucket().getId());

// Loan product creation with Delinquency bucket
getLoanProductResponse = createLoanProduct(loanTransactionHelper, Math.toIntExact(delinquencyBucket.getId()), null);
assertNotNull(getLoanProductResponse);
log.info("Loan Product Bucket Name: {}", getLoanProductResponse.getDelinquencyBucket().getName());
assertEquals(getLoanProductResponse.getDelinquencyBucket().getName(), delinquencyBucket.getName());

// Update Loan product to remove the Delinquency bucket
final Long loanProductId = getLoanProductResponse.getId();
loanTransactionHelper.updateLoanProduct(loanProductId, "{delinquencyBucketId: null}");
getLoanProductResponse = loanTransactionHelper.getLoanProduct(loanProductId.intValue());
assertNotNull(getLoanProductResponse);
assertNull(getLoanProductResponse.getDelinquencyBucket().getId());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
public class LoanTransactionHelper extends IntegrationTest {

public static final String DATE_TIME_FORMAT = "dd MMMM yyyy HH:mm";
private static final String LOAN_PRODUCTS_URL = "/fineract-provider/api/v1/loanproducts";
private static final String CREATE_LOAN_PRODUCT_URL = "/fineract-provider/api/v1/loanproducts?" + Utils.TENANT_IDENTIFIER;
private static final String APPLY_LOAN_URL = "/fineract-provider/api/v1/loans?" + Utils.TENANT_IDENTIFIER;
private static final String LOAN_ACCOUNT_URL = "/fineract-provider/api/v1/loans";
Expand Down Expand Up @@ -1975,4 +1976,10 @@ public Object addChargesForLoanWithError(final Integer loanId, final String requ
final String ADD_CHARGES_URL = LOAN_ACCOUNT_URL + "/" + loanId + "/charges?" + Utils.TENANT_IDENTIFIER;
return Utils.performServerPost(requestSpec, responseSpec, ADD_CHARGES_URL, request, jsonAttributeToGetBack);
}

public Object updateLoanProduct(final Long loanProductId, final String request) {
final String UPDATE_LOAN_PRODUCT_URL = LOAN_PRODUCTS_URL + "/" + loanProductId + "?" + Utils.TENANT_IDENTIFIER;
return Utils.performServerPut(requestSpec, responseSpec, UPDATE_LOAN_PRODUCT_URL, request, null);
}

}
Loading