FINERACT-1760: Fix error handling
This commit is contained in:
+7
@@ -18,6 +18,8 @@
|
||||
*/
|
||||
package org.apache.fineract.portfolio.charge.exception;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.fineract.infrastructure.core.domain.ExternalId;
|
||||
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException;
|
||||
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
|
||||
|
||||
@@ -38,4 +40,9 @@ public class LoanChargeNotFoundException extends AbstractPlatformResourceNotFoun
|
||||
super("error.msg.loanCharge.id.invalid.for.given.loan", "Loan charge with identifier " + id + " does not exist for loan " + loanId,
|
||||
id, loanId);
|
||||
}
|
||||
|
||||
public LoanChargeNotFoundException(ExternalId externalId) {
|
||||
super("error.msg.loanCharge.external.id.invalid", "Loan Charge with external identifier "
|
||||
+ ObjectUtils.defaultIfNull(externalId, ExternalId.empty()).getValue() + " does not exist", externalId);
|
||||
}
|
||||
}
|
||||
|
||||
+8
@@ -58,9 +58,11 @@ import org.apache.fineract.infrastructure.core.service.ExternalIdFactory;
|
||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.apache.fineract.portfolio.charge.data.ChargeData;
|
||||
import org.apache.fineract.portfolio.charge.domain.ChargeTimeType;
|
||||
import org.apache.fineract.portfolio.charge.exception.LoanChargeNotFoundException;
|
||||
import org.apache.fineract.portfolio.charge.service.ChargeReadPlatformService;
|
||||
import org.apache.fineract.portfolio.loanaccount.data.LoanChargeData;
|
||||
import org.apache.fineract.portfolio.loanaccount.data.LoanInstallmentChargeData;
|
||||
import org.apache.fineract.portfolio.loanaccount.exception.LoanNotFoundException;
|
||||
import org.apache.fineract.portfolio.loanaccount.service.LoanChargeReadPlatformService;
|
||||
import org.apache.fineract.portfolio.loanaccount.service.LoanReadPlatformService;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
@@ -549,6 +551,9 @@ public class LoanChargesApiResource {
|
||||
if (resolvedLoanChargeId == null) {
|
||||
loanChargeExternalId.throwExceptionIfEmpty();
|
||||
resolvedLoanChargeId = this.loanChargeReadPlatformService.retrieveLoanChargeIdByExternalId(loanChargeExternalId);
|
||||
if (resolvedLoanChargeId == null) {
|
||||
throw new LoanChargeNotFoundException(loanChargeExternalId);
|
||||
}
|
||||
}
|
||||
return resolvedLoanChargeId;
|
||||
}
|
||||
@@ -558,6 +563,9 @@ public class LoanChargesApiResource {
|
||||
if (resolvedLoanId == null) {
|
||||
loanExternalId.throwExceptionIfEmpty();
|
||||
resolvedLoanId = this.loanReadPlatformService.retrieveLoanIdByExternalId(loanExternalId.getValue());
|
||||
if (resolvedLoanId == null) {
|
||||
throw new LoanNotFoundException(loanExternalId);
|
||||
}
|
||||
}
|
||||
return resolvedLoanId;
|
||||
}
|
||||
|
||||
+8
@@ -62,6 +62,8 @@ import org.apache.fineract.infrastructure.security.service.PlatformSecurityConte
|
||||
import org.apache.fineract.portfolio.loanaccount.data.LoanRepaymentScheduleInstallmentData;
|
||||
import org.apache.fineract.portfolio.loanaccount.data.LoanTransactionData;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionType;
|
||||
import org.apache.fineract.portfolio.loanaccount.exception.LoanNotFoundException;
|
||||
import org.apache.fineract.portfolio.loanaccount.exception.LoanTransactionNotFoundException;
|
||||
import org.apache.fineract.portfolio.loanaccount.service.LoanChargePaidByReadPlatformService;
|
||||
import org.apache.fineract.portfolio.loanaccount.service.LoanReadPlatformService;
|
||||
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeData;
|
||||
@@ -576,6 +578,9 @@ public class LoanTransactionsApiResource {
|
||||
if (resolvedLoanTransactionId == null) {
|
||||
externalTransactionId.throwExceptionIfEmpty();
|
||||
resolvedLoanTransactionId = this.loanReadPlatformService.retrieveLoanTransactionIdByExternalId(externalTransactionId);
|
||||
if (resolvedLoanTransactionId == null) {
|
||||
throw new LoanTransactionNotFoundException(externalTransactionId);
|
||||
}
|
||||
}
|
||||
return resolvedLoanTransactionId;
|
||||
}
|
||||
@@ -585,6 +590,9 @@ public class LoanTransactionsApiResource {
|
||||
if (resolvedLoanId == null) {
|
||||
loanExternalId.throwExceptionIfEmpty();
|
||||
resolvedLoanId = this.loanReadPlatformService.retrieveLoanIdByExternalId(loanExternalId.getValue());
|
||||
if (resolvedLoanId == null) {
|
||||
throw new LoanNotFoundException(loanExternalId);
|
||||
}
|
||||
}
|
||||
return resolvedLoanId;
|
||||
}
|
||||
|
||||
+7
-2
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.apache.fineract.portfolio.loanaccount.exception;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.fineract.infrastructure.core.domain.ExternalId;
|
||||
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
|
||||
|
||||
@@ -39,10 +40,14 @@ public class LoanNotFoundException extends AbstractPlatformResourceNotFoundExcep
|
||||
}
|
||||
|
||||
public LoanNotFoundException(ExternalId externalId) {
|
||||
super("error.msg.loan.external.id.invalid", "Loan with external identifier " + externalId + " does not exist", externalId);
|
||||
super("error.msg.loan.external.id.invalid",
|
||||
"Loan with external identifier " + ObjectUtils.defaultIfNull(externalId, ExternalId.empty()).getValue() + " does not exist",
|
||||
externalId);
|
||||
}
|
||||
|
||||
public LoanNotFoundException(ExternalId externalId, Exception e) {
|
||||
super("error.msg.loan.external.id.invalid", "Loan with external identifier " + externalId + " does not exist", externalId, e);
|
||||
super("error.msg.loan.external.id.invalid",
|
||||
"Loan with external identifier " + ObjectUtils.defaultIfNull(externalId, ExternalId.empty()).getValue() + " does not exist",
|
||||
externalId, e);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-1
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.apache.fineract.portfolio.loanaccount.exception;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.fineract.infrastructure.core.domain.ExternalId;
|
||||
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
@@ -40,8 +41,15 @@ public class LoanTransactionNotFoundException extends AbstractPlatformResourceNo
|
||||
super("error.msg.loan.transaction.id.invalid", "Transaction with identifier " + id + " does not exist", id, e);
|
||||
}
|
||||
|
||||
public LoanTransactionNotFoundException(ExternalId transactionExternalId) {
|
||||
super("error.msg.loan.transaction.external.id.invalid", "Transaction with external identifier "
|
||||
+ ObjectUtils.defaultIfNull(transactionExternalId, ExternalId.empty()).getValue() + " does not exist",
|
||||
transactionExternalId);
|
||||
}
|
||||
|
||||
public LoanTransactionNotFoundException(ExternalId transactionExternalId, EmptyResultDataAccessException e) {
|
||||
super("error.msg.loan.transaction.id.invalid", "Transaction with external identifier " + transactionExternalId + " does not exist",
|
||||
super("error.msg.loan.transaction.external.id.invalid", "Transaction with external identifier "
|
||||
+ ObjectUtils.defaultIfNull(transactionExternalId, ExternalId.empty()).getValue() + " does not exist",
|
||||
transactionExternalId, e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user