MIFOSX-1709 : added test cases and api documentation

This commit is contained in:
Pramod Nuthakki
2014-12-09 09:46:25 +05:30
parent 3d399eba10
commit 6d79d59b74
14 changed files with 1148 additions and 101 deletions
@@ -7,10 +7,22 @@ package org.mifosplatform.portfolio.common.service;
import org.springframework.data.jpa.domain.AbstractPersistable;
/**
* The interface to be implemented by classes that want to be informed when a
* Business Event executes. example: on completion of loan approval event need
* to block guarantor funds
*
*/
public interface BusinessEventListner {
/**
* Implement this method for notifications before executing Business Event
*/
public void businessEventToBeExecuted(AbstractPersistable<Long> businessEventEntity);
/**
* Implement this method for notifications after executing Business Event
*/
public void businessEventWasExecuted(AbstractPersistable<Long> businessEventEntity);
}
@@ -8,14 +8,35 @@ package org.mifosplatform.portfolio.common.service;
import org.mifosplatform.portfolio.common.BusinessEventNotificationConstants.BUSINESS_EVENTS;
import org.springframework.data.jpa.domain.AbstractPersistable;
/**
* Implemented class is responsible for notifying the business event to
* registered listeners.
*
*/
public interface BusinessEventNotifierService {
/**
* Method should be called to notify listeners before Business event
* execution for any pre-processing of event
*/
public void notifyBusinessEventToBeExecuted(BUSINESS_EVENTS businessEvent, AbstractPersistable<Long> businessEventEntity);
/**
* Method should be called to notify listeners after Business event
* execution for any post-processing of event
*/
public void notifyBusinessEventWasExecuted(BUSINESS_EVENTS businessEvent, AbstractPersistable<Long> businessEventEntity);
/**
* Method is to register a class as listener for pre-processing of any
* Business event
*/
public void addBusinessEventPreListners(BUSINESS_EVENTS businessEvent, BusinessEventListner businessEventListner);
/**
* Method is to register a class as listener for post-processing of any
* Business event
*/
public void addBusinessEventPostListners(BUSINESS_EVENTS businessEvent, BusinessEventListner businessEventListner);
}
@@ -20,6 +20,16 @@ public class BusinessEventNotifierServiceImpl implements BusinessEventNotifierSe
private final Map<BUSINESS_EVENTS, List<BusinessEventListner>> preListners = new HashMap<>(5);
private final Map<BUSINESS_EVENTS, List<BusinessEventListner>> postListners = new HashMap<>(5);
/*
* (non-Javadoc)
*
* @see
* org.mifosplatform.portfolio.common.service.BusinessEventNotifierService
* #notifyBusinessEventToBeExecuted
* (org.mifosplatform.portfolio.common.BusinessEventNotificationConstants
* .BUSINESS_EVENTS,
* org.springframework.data.jpa.domain.AbstractPersistable)
*/
@Override
public void notifyBusinessEventToBeExecuted(BUSINESS_EVENTS businessEvent, AbstractPersistable<Long> businessEventEntity) {
List<BusinessEventListner> businessEventListners = this.preListners.get(businessEvent);
@@ -30,6 +40,16 @@ public class BusinessEventNotifierServiceImpl implements BusinessEventNotifierSe
}
}
/*
* (non-Javadoc)
*
* @see
* org.mifosplatform.portfolio.common.service.BusinessEventNotifierService
* #notifyBusinessEventWasExecuted
* (org.mifosplatform.portfolio.common.BusinessEventNotificationConstants
* .BUSINESS_EVENTS,
* org.springframework.data.jpa.domain.AbstractPersistable)
*/
@Override
public void notifyBusinessEventWasExecuted(BUSINESS_EVENTS businessEvent, AbstractPersistable<Long> businessEventEntity) {
List<BusinessEventListner> businessEventListners = this.postListners.get(businessEvent);
@@ -40,11 +60,31 @@ public class BusinessEventNotifierServiceImpl implements BusinessEventNotifierSe
}
}
/*
* (non-Javadoc)
*
* @see
* org.mifosplatform.portfolio.common.service.BusinessEventNotifierService
* #addBusinessEventPreListners
* (org.mifosplatform.portfolio.common.BusinessEventNotificationConstants
* .BUSINESS_EVENTS,
* org.mifosplatform.portfolio.common.service.BusinessEventListner)
*/
@Override
public void addBusinessEventPreListners(BUSINESS_EVENTS businessEvent, BusinessEventListner businessEventListner) {
addBusinessEventListners(businessEvent, businessEventListner, preListners);
}
/*
* (non-Javadoc)
*
* @see
* org.mifosplatform.portfolio.common.service.BusinessEventNotifierService
* #addBusinessEventPostListners
* (org.mifosplatform.portfolio.common.BusinessEventNotificationConstants
* .BUSINESS_EVENTS,
* org.mifosplatform.portfolio.common.service.BusinessEventListner)
*/
@Override
public void addBusinessEventPostListners(BUSINESS_EVENTS businessEvent, BusinessEventListner businessEventListner) {
addBusinessEventListners(businessEvent, businessEventListner, postListners);
@@ -146,6 +146,10 @@ public class GuarantorDomainServiceImpl implements GuarantorDomainService {
}
/**
* Method assigns a guarantor to loan and blocks the funds on guarantor's
* account
*/
@Override
public void assignGuarantor(final GuarantorFundingDetails guarantorFundingDetails, final LocalDate transactionDate) {
if (guarantorFundingDetails.getStatus().isActive()) {
@@ -168,6 +172,10 @@ public class GuarantorDomainServiceImpl implements GuarantorDomainService {
}
}
/**
* Method releases(withdraw) a guarantor from loan and unblocks the funds on
* guarantor's account
*/
@Override
public void releaseGuarantor(final GuarantorFundingDetails guarantorFundingDetails, final LocalDate transactionDate) {
BigDecimal amoutForWithdraw = guarantorFundingDetails.getAmountRemaining();
@@ -187,6 +195,11 @@ public class GuarantorDomainServiceImpl implements GuarantorDomainService {
}
}
/**
* Method is to recover funds from guarantor's in case loan is unpaid.
* (Transfers guarantee amount from guarantor's account to loan account and
* releases guarantor)
*/
@Override
public void transaferFundsFromGuarantor(final Loan loan) {
if (loan.getGuaranteeAmount().compareTo(BigDecimal.ZERO) != 1) { return; }
@@ -254,6 +267,11 @@ public class GuarantorDomainServiceImpl implements GuarantorDomainService {
}
}
/**
* Method reverses all blocked fund(both hold and release) transactions.
* example: reverses all transactions on undo approval of loan account.
*
*/
private void reverseAllFundTransaction(final Loan loan) {
if (loan.getGuaranteeAmount().compareTo(BigDecimal.ZERO) == 1) {
@@ -274,6 +292,11 @@ public class GuarantorDomainServiceImpl implements GuarantorDomainService {
}
}
/**
* Method holds all guarantor's guarantee amount for a loan account.
* example: hold funds on approval of loan account.
*
*/
private void holdGuarantorFunds(final Loan loan) {
if (loan.loanProduct().isHoldGuaranteeFundsEnabled()) {
final List<Guarantor> existGuarantorList = this.guarantorRepository.findByLoan(loan);
@@ -318,6 +341,13 @@ public class GuarantorDomainServiceImpl implements GuarantorDomainService {
}
}
/**
* Method releases all guarantor's guarantee amount(first external guarantee
* and then self guarantee) for a loan account in the portion of guarantee
* percentage on a paid principal. example: releases funds on repayments of
* loan account.
*
*/
private void releaseGuarantorFunds(final LoanTransaction loanTransaction) {
final Loan loan = loanTransaction.getLoan();
if (loan.getGuaranteeAmount().compareTo(BigDecimal.ZERO) == 1) {
@@ -364,6 +394,11 @@ public class GuarantorDomainServiceImpl implements GuarantorDomainService {
}
/**
* Method releases all guarantor's guarantee amount. example: releases funds
* on write-off of a loan account.
*
*/
private void releaseAllGuarantors(final LoanTransaction loanTransaction) {
Loan loan = loanTransaction.getLoan();
if (loan.getGuaranteeAmount().compareTo(BigDecimal.ZERO) == 1) {
@@ -398,6 +433,11 @@ public class GuarantorDomainServiceImpl implements GuarantorDomainService {
}
}
/**
* Method releases guarantor's guarantee amount on transferring guarantee
* amount to loan account. example: on recovery of guarantee funds from
* guarantor's.
*/
private void completeGuarantorFund(final LoanTransaction loanTransaction) {
Loan loan = loanTransaction.getLoan();
GuarantorFundingDetails guarantorFundingDetails = this.guarantorFundingRepository.findOne(releaseLoanIds.get(loan.getId()));
@@ -437,6 +477,10 @@ public class GuarantorDomainServiceImpl implements GuarantorDomainService {
return amountLeft;
}
/**
* Method reverses the fund release transactions in case of loan transaction
* reversed
*/
private void reverseTransaction(final List<Long> loanTransactionIds) {
List<GuarantorFundingTransaction> fundingTransactions = this.guarantorFundingTransactionRepository
@@ -123,7 +123,7 @@ public class GuarantorWritePlatformServiceJpaRepositoryIImpl implements Guaranto
final Integer guarantorTypeId = guarantorCommand.getGuarantorTypeId();
Guarantor guarantor = null;
for (final Guarantor avilableGuarantor : existGuarantorList) {
if (entityId != null && avilableGuarantor.getEntityId() == entityId
if (entityId != null && avilableGuarantor.getEntityId() != null && avilableGuarantor.getEntityId().equals(entityId)
&& avilableGuarantor.getGurantorType() == guarantorTypeId && avilableGuarantor.isActive()) {
if (guarantorCommand.getSavingsId() == null || avilableGuarantor.hasGuarantor(guarantorCommand.getSavingsId())) {
/** Get the right guarantor based on guarantorType **/
@@ -251,15 +251,7 @@ public class GuarantorWritePlatformServiceJpaRepositoryIImpl implements Guaranto
GuarantorFundingDetails guarantorFundingDetails = guarantorForDelete.getGuarantorFundingDetail(guarantorFundingId);
if (guarantorFundingDetails == null) { throw new GuarantorNotFoundException(loanId, guarantorForDelete.getId(),
guarantorFundingId); }
if (!guarantorFundingDetails.getStatus().isActive()) {
baseDataValidator.failWithCodeNoParameterAddedToErrorCode(GuarantorConstants.GUARANTOR_NOT_ACTIVE_ERROR);
}
GuarantorFundStatusType fundStatusType = GuarantorFundStatusType.DELETED;
if (guarantorForDelete.getLoan().isDisbursed() || guarantorForDelete.getLoan().isApproved()) {
fundStatusType = GuarantorFundStatusType.WITHDRAWN;
this.guarantorDomainService.releaseGuarantor(guarantorFundingDetails, LocalDate.now());
}
guarantorForDelete.updateStatus(guarantorFundingDetails, fundStatusType);
removeguarantorFundDetails(guarantorForDelete, baseDataValidator, guarantorFundingDetails);
}
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
@@ -274,6 +266,19 @@ public class GuarantorWritePlatformServiceJpaRepositoryIImpl implements Guaranto
return commandProcessingResultBuilder.build();
}
private void removeguarantorFundDetails(final Guarantor guarantorForDelete, final DataValidatorBuilder baseDataValidator,
GuarantorFundingDetails guarantorFundingDetails) {
if (!guarantorFundingDetails.getStatus().isActive()) {
baseDataValidator.failWithCodeNoParameterAddedToErrorCode(GuarantorConstants.GUARANTOR_NOT_ACTIVE_ERROR);
}
GuarantorFundStatusType fundStatusType = GuarantorFundStatusType.DELETED;
if (guarantorForDelete.getLoan().isDisbursed() || guarantorForDelete.getLoan().isApproved()) {
fundStatusType = GuarantorFundStatusType.WITHDRAWN;
this.guarantorDomainService.releaseGuarantor(guarantorFundingDetails, LocalDate.now());
}
guarantorForDelete.updateStatus(guarantorFundingDetails, fundStatusType);
}
private void validateGuarantorBusinessRules(final Guarantor guarantor) {
// validate guarantor conditions
if (guarantor.isExistingCustomer()) {