Search in sources :

Example 31 with PersistenceException

use of org.mifos.framework.exceptions.PersistenceException in project head by mifos.

the class RolesPermissionsBusinessService method getRoleActivityRestrictionAmountValueByRestrictionTypeId.

public BigDecimal getRoleActivityRestrictionAmountValueByRestrictionTypeId(Short roleId, Short activityRestrictionTypeId) throws ServiceException {
    try {
        RoleBO roleBO = rolesPermissionsPersistence.getRole(roleId);
        Set<RoleActivityRestrictionBO> restrictions = roleBO.getRestrictions();
        for (RoleActivityRestrictionBO restrictionBO : restrictions) {
            if (restrictionBO.getActivityRestrictionType().getId().equals(ActivityRestrictionType.MAX_LOAN_AMOUNT_FOR_APPROVE.getValue())) {
                return restrictionBO.getRestrictionAmountValue();
            }
        }
        return null;
    } catch (PersistenceException e) {
        throw new ServiceException(e);
    }
}
Also used : ServiceException(org.mifos.framework.exceptions.ServiceException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) RoleActivityRestrictionBO(org.mifos.security.rolesandpermission.business.RoleActivityRestrictionBO) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO)

Example 32 with PersistenceException

use of org.mifos.framework.exceptions.PersistenceException in project head by mifos.

the class LoanServiceFacadeWebTier method retrieveOriginalLoanSchedule.

@Override
public OriginalScheduleInfoDto retrieveOriginalLoanSchedule(Integer accountId) {
    try {
        List<OriginalLoanScheduleEntity> loanScheduleEntities = loanBusinessService.retrieveOriginalLoanSchedule(accountId);
        ArrayList<RepaymentScheduleInstallment> repaymentScheduleInstallments = new ArrayList<RepaymentScheduleInstallment>();
        for (OriginalLoanScheduleEntity loanScheduleEntity : loanScheduleEntities) {
            repaymentScheduleInstallments.add(loanScheduleEntity.toDto());
        }
        LoanBO loan = this.loanDao.findById(accountId);
        return new OriginalScheduleInfoDto(loan.getLoanAmount().toString(), loan.getDisbursementDate(), repaymentScheduleInstallments);
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) OriginalScheduleInfoDto(org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto) OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) PersistenceException(org.mifos.framework.exceptions.PersistenceException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 33 with PersistenceException

use of org.mifos.framework.exceptions.PersistenceException in project head by mifos.

the class CustomerTagGenerator method buildLink.

private void buildLink(StringBuilder strBuilder, CustomerBO customer, CustomerBO originalCustomer, boolean selfLinkRequired, Object randomNum) {
    if (customer == null) {
        return;
    }
    try {
        CustomerBO customerReloaded = new CustomerPersistence().getCustomer(customer.getCustomerId());
        buildLink(strBuilder, customerReloaded.getParentCustomer(), originalCustomer, selfLinkRequired, randomNum);
        strBuilder.append(" / ");
        createCustomerLink(strBuilder, customer, originalCustomer, selfLinkRequired, randomNum);
    } catch (PersistenceException e) {
        throw new RuntimeException(e);
    }
}
Also used : PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence)

Example 34 with PersistenceException

use of org.mifos.framework.exceptions.PersistenceException in project head by mifos.

the class LoanBO method removeFeesAssociatedWithUpcomingAndAllKnownFutureInstallments.

/**
     * Remove the fee from all unpaid current or future installments, and update the loan accordingly.
     */
@Override
public final void removeFeesAssociatedWithUpcomingAndAllKnownFutureInstallments(final Short feeId, final Short personnelId) throws AccountException {
    List<Short> installmentIds = getApplicableInstallmentIdsForRemoveFees();
    Money totalFeeAmount;
    if (installmentIds != null && installmentIds.size() != 0 && isFeeActive(feeId)) {
        FeeBO fee = getAccountFeesObject(feeId);
        if (havePaymentsBeenMade() && fee.doesFeeInvolveFractionalAmounts()) {
            throw new AccountException(AccountExceptionConstants.CANT_REMOVE_FEE_EXCEPTION);
        }
        if (fee.isTimeOfDisbursement()) {
            AccountFeesEntity accountFee = getAccountFees(feeId);
            totalFeeAmount = accountFee.getAccountFeeAmount();
            removeAccountFee(accountFee);
            this.delete(accountFee);
        } else {
            totalFeeAmount = updateAccountActionDateEntity(installmentIds, feeId);
            updateAccountFeesEntity(feeId);
        }
        updateTotalFeeAmount(totalFeeAmount);
        String description = fee.getFeeName() + " " + AccountConstants.FEES_REMOVED;
        updateAccountActivity(null, null, totalFeeAmount, null, personnelId, description);
        if (!havePaymentsBeenMade()) {
            LoanScheduleRounderHelper loanScheduleRounderHelper = new DefaultLoanScheduleRounderHelper();
            LoanScheduleRounder loanScheduleInstallmentRounder = getLoanScheduleRounder(loanScheduleRounderHelper);
            List<LoanScheduleEntity> unroundedLoanSchedules = new ArrayList<LoanScheduleEntity>();
            List<LoanScheduleEntity> allExistingLoanSchedules = new ArrayList<LoanScheduleEntity>();
            List<AccountActionDateEntity> installmentsToRound = getInstallmentsToRound();
            for (AccountActionDateEntity installment : installmentsToRound) {
                unroundedLoanSchedules.add((LoanScheduleEntity) installment);
            }
            List<AccountActionDateEntity> allExistingInstallments = this.getAllInstallments();
            for (AccountActionDateEntity installment : allExistingInstallments) {
                allExistingLoanSchedules.add((LoanScheduleEntity) installment);
            }
            List<LoanScheduleEntity> roundedLoanSchedules = loanScheduleInstallmentRounder.round(this.gracePeriodType.asEnum(), this.gracePeriodDuration, this.loanAmount, this.interestType.asEnum(), unroundedLoanSchedules, allExistingLoanSchedules);
        //                applyRounding_v2();
        }
        try {
            ApplicationContextProvider.getBean(LegacyAccountDao.class).createOrUpdate(this);
        } catch (PersistenceException e) {
            throw new AccountException(e);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) DefaultLoanScheduleRounderHelper(org.mifos.clientportfolio.newloan.domain.DefaultLoanScheduleRounderHelper) Money(org.mifos.framework.util.helpers.Money) AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) AccountException(org.mifos.accounts.exceptions.AccountException) LegacyAccountDao(org.mifos.accounts.persistence.LegacyAccountDao) FirstInstallmentRoudingDifferenceLoanScheduleRounder(org.mifos.clientportfolio.newloan.domain.FirstInstallmentRoudingDifferenceLoanScheduleRounder) LoanScheduleRounder(org.mifos.clientportfolio.newloan.domain.LoanScheduleRounder) DefaultLoanScheduleRounder(org.mifos.clientportfolio.newloan.domain.DefaultLoanScheduleRounder) PersistenceException(org.mifos.framework.exceptions.PersistenceException) FeeBO(org.mifos.accounts.fees.business.FeeBO) RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) DefaultLoanScheduleRounderHelper(org.mifos.clientportfolio.newloan.domain.DefaultLoanScheduleRounderHelper) LoanScheduleRounderHelper(org.mifos.clientportfolio.newloan.domain.LoanScheduleRounderHelper) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity)

Example 35 with PersistenceException

use of org.mifos.framework.exceptions.PersistenceException in project head by mifos.

the class LoanBO method updateLoan.

public void updateLoan(final Boolean interestDeductedAtDisbursement, final Money loanAmount, final Double interestRate, final Short noOfInstallments, final Date disbursementDate, final Short gracePeriodDuration, final Integer businessActivityId, final String collateralNote, final Integer collateralTypeId, final List<CustomFieldDto> customFields, final boolean isRepaymentIndepOfMeetingEnabled, final MeetingBO newMeetingForRepaymentDay, final FundBO fund) throws AccountException {
    if (interestDeductedAtDisbursement) {
        try {
            if (noOfInstallments <= 1) {
                throw new AccountException(LoanExceptionConstants.INVALIDNOOFINSTALLMENTS);
            }
            setGracePeriodType(legacyMasterDao.findMasterDataEntityWithLocale(GracePeriodTypeEntity.class, GraceType.NONE.getValue()));
        } catch (PersistenceException e) {
            throw new AccountException(e);
        }
    } else {
        setGracePeriodType(getLoanOffering().getGracePeriodType());
    }
    setLoanAmount(loanAmount);
    setInterestRate(interestRate);
    setNoOfInstallments(noOfInstallments);
    setGracePeriodDuration(gracePeriodDuration);
    setInterestDeductedAtDisbursement(interestDeductedAtDisbursement);
    setBusinessActivityId(businessActivityId);
    setCollateralNote(collateralNote);
    setCollateralTypeId(collateralTypeId);
    setFund(fund);
    if (getAccountState().getId().equals(AccountState.LOAN_APPROVED.getValue()) || getAccountState().getId().equals(AccountState.LOAN_DISBURSED_TO_LOAN_OFFICER.getValue()) || getAccountState().getId().equals(AccountState.LOAN_PARTIAL_APPLICATION.getValue()) || getAccountState().getId().equals(AccountState.LOAN_PENDING_APPROVAL.getValue())) {
        // only check the disbursement date if it has changed
        if (disbursementDate != null && !disbursementDate.equals(getDisbursementDate()) && isDisbursementDateLessThanCurrentDate(disbursementDate)) {
            throw new AccountException(LoanExceptionConstants.ERROR_INVALIDDISBURSEMENTDATE);
        }
        setDisbursementDate(disbursementDate);
        regeneratePaymentSchedule(isRepaymentIndepOfMeetingEnabled, newMeetingForRepaymentDay);
    }
    try {
        updateCustomFields(customFields);
    } catch (InvalidDateException ide) {
        throw new AccountException(ide);
    }
    loanSummary.setOriginalPrincipal(loanAmount);
    update();
}
Also used : AccountException(org.mifos.accounts.exceptions.AccountException) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) GracePeriodTypeEntity(org.mifos.accounts.productdefinition.business.GracePeriodTypeEntity)

Aggregations

PersistenceException (org.mifos.framework.exceptions.PersistenceException)215 MifosRuntimeException (org.mifos.core.MifosRuntimeException)98 ArrayList (java.util.ArrayList)55 ServiceException (org.mifos.framework.exceptions.ServiceException)53 AccountException (org.mifos.accounts.exceptions.AccountException)40 Test (org.junit.Test)35 ExpectedException (org.springframework.test.annotation.ExpectedException)32 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)24 BusinessRuleException (org.mifos.service.BusinessRuleException)23 Money (org.mifos.framework.util.helpers.Money)22 HibernateSearchException (org.mifos.framework.exceptions.HibernateSearchException)20 MifosUser (org.mifos.security.MifosUser)19 UserContext (org.mifos.security.util.UserContext)19 HashMap (java.util.HashMap)18 HibernateException (org.hibernate.HibernateException)18 Query (org.hibernate.Query)18 LoanBO (org.mifos.accounts.loan.business.LoanBO)18 Session (org.hibernate.Session)14 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)14 QueryResult (org.mifos.framework.hibernate.helper.QueryResult)14