FINERACT-1971: Fix Delinquency bucket error upon Loan product editing
This commit is contained in:
committed by
Adam Saghy
parent
f7a056204c
commit
1f00bb6d33
+1
-1
@@ -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)
|
||||
|
||||
+1
-1
@@ -501,7 +501,7 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
|
||||
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<>());
|
||||
|
||||
+12
-6
@@ -127,9 +127,8 @@ public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanPro
|
||||
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);
|
||||
@@ -168,6 +167,15 @@ public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanPro
|
||||
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) {
|
||||
@@ -201,9 +209,7 @@ public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanPro
|
||||
}
|
||||
|
||||
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")) {
|
||||
|
||||
+8
@@ -285,12 +285,20 @@ public class DelinquencyBucketsIntegrationTest {
|
||||
// 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
|
||||
|
||||
+7
@@ -100,6 +100,7 @@ import org.apache.poi.ss.usermodel.Workbook;
|
||||
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";
|
||||
@@ -1975,4 +1976,10 @@ public class LoanTransactionHelper extends IntegrationTest {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user