Search in sources :

Example 11 with ApplicationException

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

the class FeeServiceFacadeWebTier method updateFee.

@Override
public void updateFee(FeeUpdateRequest feeUpdateRequest) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    try {
        this.feeService.update(feeUpdateRequest, userContext);
    } catch (ApplicationException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) UserContext(org.mifos.security.util.UserContext) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory)

Example 12 with ApplicationException

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

the class WebTierAccountServiceFacade method applyGroupCharge.

@Override
public void applyGroupCharge(Map<Integer, String> idsAndValues, Short chargeId, boolean isPenaltyType) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    TreeMap<Integer, String> idsAndValueAsTreeMap = new TreeMap<Integer, String>(idsAndValues);
    try {
        AccountBO parentAccount = ((LoanBO) legacyAccountDao.getAccount(new AccountBusinessService().getAccount(idsAndValueAsTreeMap.firstKey()).getAccountId())).getParentAccount();
        BigDecimal parentAmount = ((LoanBO) parentAccount).getLoanAmount().getAmount();
        BigDecimal membersAmount = BigDecimal.ZERO;
        for (Map.Entry<Integer, String> entry : idsAndValues.entrySet()) {
            LoanBO individual = loanDao.findById(entry.getKey());
            Double chargeAmount = Double.valueOf(entry.getValue());
            if (chargeAmount.equals(0.0)) {
                continue;
            }
            membersAmount = membersAmount.add(individual.getLoanAmount().getAmount());
            individual.updateDetails(userContext);
            if (isPenaltyType && !chargeId.equals(Short.valueOf(AccountConstants.MISC_PENALTY))) {
                PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
                individual.addAccountPenalty(new AccountPenaltiesEntity(individual, penalty, chargeAmount));
            } else {
                individual.applyCharge(chargeId, chargeAmount);
            }
        }
        boolean isRateCharge = false;
        if (!chargeId.equals(Short.valueOf(AccountConstants.MISC_FEES)) && !chargeId.equals(Short.valueOf(AccountConstants.MISC_PENALTY))) {
            if (isPenaltyType) {
                PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
                if (penalty instanceof RatePenaltyBO) {
                    isRateCharge = true;
                }
            } else {
                FeeBO fee = feeDao.findById(chargeId);
                if (fee.getFeeType().equals(RateAmountFlag.RATE)) {
                    isRateCharge = true;
                }
            }
        }
        Double chargeAmount = null;
        if (!isRateCharge) {
            chargeAmount = sumCharge(idsAndValues);
        } else {
            chargeAmount = Double.valueOf(idsAndValueAsTreeMap.firstEntry().getValue());
            BigDecimal chargeAmountBig = new BigDecimal(chargeAmount);
            membersAmount = membersAmount.multiply(chargeAmountBig);
            int scale = Money.getInternalPrecision();
            chargeAmountBig = membersAmount.divide(parentAmount, scale, RoundingMode.HALF_EVEN);
            chargeAmount = chargeAmountBig.doubleValue();
        }
        parentAccount.updateDetails(userContext);
        CustomerLevel customerLevel = null;
        if (parentAccount.isCustomerAccount()) {
            customerLevel = parentAccount.getCustomer().getLevel();
        }
        if (parentAccount.getPersonnel() != null) {
            checkPermissionForApplyCharges(parentAccount.getType(), customerLevel, userContext, parentAccount.getOffice().getOfficeId(), parentAccount.getPersonnel().getPersonnelId());
        } else {
            checkPermissionForApplyCharges(parentAccount.getType(), customerLevel, userContext, parentAccount.getOffice().getOfficeId(), userContext.getId());
        }
        this.transactionHelper.startTransaction();
        if (isPenaltyType && parentAccount instanceof LoanBO) {
            PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
            ((LoanBO) parentAccount).addAccountPenalty(new AccountPenaltiesEntity(parentAccount, penalty, chargeAmount));
        } else {
            parentAccount.applyCharge(chargeId, chargeAmount);
        }
        this.transactionHelper.commitTransaction();
    } catch (ServiceException e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (ApplicationException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : AccountPenaltiesEntity(org.mifos.accounts.business.AccountPenaltiesEntity) RatePenaltyBO(org.mifos.accounts.penalties.business.RatePenaltyBO) CustomerLevel(org.mifos.customers.api.CustomerLevel) PenaltyBO(org.mifos.accounts.penalties.business.PenaltyBO) RatePenaltyBO(org.mifos.accounts.penalties.business.RatePenaltyBO) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) MifosUser(org.mifos.security.MifosUser) TreeMap(java.util.TreeMap) BigDecimal(java.math.BigDecimal) AccountBO(org.mifos.accounts.business.AccountBO) BusinessRuleException(org.mifos.service.BusinessRuleException) AccountBusinessService(org.mifos.accounts.business.service.AccountBusinessService) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ServiceException(org.mifos.framework.exceptions.ServiceException) FeeBO(org.mifos.accounts.fees.business.FeeBO) RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 13 with ApplicationException

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

the class ReportsPersistence method createReportsDataSource.

public void createReportsDataSource(ReportsDataSource reportsDataSource) throws ApplicationException, SystemException {
    Session session = null;
    try {
        session = StaticHibernateUtil.getSessionTL();
        StaticHibernateUtil.startTransaction();
        session.save(reportsDataSource);
        session.flush();
        StaticHibernateUtil.commitTransaction();
    } catch (HibernateProcessException hpe) {
        StaticHibernateUtil.rollbackTransaction();
        throw new ApplicationException(hpe);
    } catch (HibernateException e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new ReportException(ReportsConstants.CREATE_FAILED_EXCEPTION, e);
    } catch (Exception e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new ReportException(ReportsConstants.CREATE_FAILED_EXCEPTION, e);
    } finally {
        StaticHibernateUtil.closeSession();
    }
}
Also used : HibernateProcessException(org.mifos.framework.exceptions.HibernateProcessException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) HibernateException(org.hibernate.HibernateException) ReportException(org.mifos.reports.exceptions.ReportException) SystemException(org.mifos.framework.exceptions.SystemException) ReportException(org.mifos.reports.exceptions.ReportException) HibernateProcessException(org.mifos.framework.exceptions.HibernateProcessException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) HibernateException(org.hibernate.HibernateException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) Session(org.hibernate.Session)

Example 14 with ApplicationException

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

the class ReportsPersistence method deleteReportsParamsMap.

/**
     * Deletes a link between report and a parameter
     */
public void deleteReportsParamsMap(ReportsParamsMapValue reportsParamsMapValue) throws ApplicationException, SystemException {
    Session session = null;
    try {
        session = StaticHibernateUtil.getSessionTL();
        StaticHibernateUtil.startTransaction();
        session.delete(reportsParamsMapValue);
        session.flush();
        StaticHibernateUtil.commitTransaction();
    } catch (HibernateProcessException hpe) {
        StaticHibernateUtil.rollbackTransaction();
        throw new ApplicationException(hpe);
    } catch (HibernateException e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new ReportException(ReportsConstants.CREATE_FAILED_EXCEPTION, e);
    } catch (Exception e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new ReportException(ReportsConstants.CREATE_FAILED_EXCEPTION, e);
    } finally {
        StaticHibernateUtil.closeSession();
    }
}
Also used : HibernateProcessException(org.mifos.framework.exceptions.HibernateProcessException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) HibernateException(org.hibernate.HibernateException) ReportException(org.mifos.reports.exceptions.ReportException) SystemException(org.mifos.framework.exceptions.SystemException) ReportException(org.mifos.reports.exceptions.ReportException) HibernateProcessException(org.mifos.framework.exceptions.HibernateProcessException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) HibernateException(org.hibernate.HibernateException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) Session(org.hibernate.Session)

Example 15 with ApplicationException

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

the class ReportsPersistence method deleteReportParams.

public void deleteReportParams(ReportsParamsValue reportsParams) throws ApplicationException, SystemException {
    Session session = null;
    try {
        session = StaticHibernateUtil.getSessionTL();
        StaticHibernateUtil.startTransaction();
        session.delete(reportsParams);
        session.flush();
        StaticHibernateUtil.commitTransaction();
    } catch (HibernateProcessException hpe) {
        StaticHibernateUtil.rollbackTransaction();
        throw new ApplicationException(hpe);
    } catch (HibernateException e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new ReportException(ReportsConstants.CREATE_FAILED_EXCEPTION, e);
    } catch (Exception e) {
        StaticHibernateUtil.rollbackTransaction();
        throw new ReportException(ReportsConstants.CREATE_FAILED_EXCEPTION, e);
    } finally {
        StaticHibernateUtil.closeSession();
    }
}
Also used : HibernateProcessException(org.mifos.framework.exceptions.HibernateProcessException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) HibernateException(org.hibernate.HibernateException) ReportException(org.mifos.reports.exceptions.ReportException) SystemException(org.mifos.framework.exceptions.SystemException) ReportException(org.mifos.reports.exceptions.ReportException) HibernateProcessException(org.mifos.framework.exceptions.HibernateProcessException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) HibernateException(org.hibernate.HibernateException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) Session(org.hibernate.Session)

Aggregations

ApplicationException (org.mifos.framework.exceptions.ApplicationException)76 BusinessRuleException (org.mifos.service.BusinessRuleException)34 MifosRuntimeException (org.mifos.core.MifosRuntimeException)29 UserContext (org.mifos.security.util.UserContext)25 PersistenceException (org.mifos.framework.exceptions.PersistenceException)22 ArrayList (java.util.ArrayList)16 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)16 MifosUser (org.mifos.security.MifosUser)16 SystemException (org.mifos.framework.exceptions.SystemException)14 CustomerBO (org.mifos.customers.business.CustomerBO)10 ServiceException (org.mifos.framework.exceptions.ServiceException)10 Test (org.junit.Test)9 AccountException (org.mifos.accounts.exceptions.AccountException)9 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)9 CustomerException (org.mifos.customers.exceptions.CustomerException)9 HibernateException (org.hibernate.HibernateException)8 Session (org.hibernate.Session)7 LoanBO (org.mifos.accounts.loan.business.LoanBO)7 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)7 CenterBO (org.mifos.customers.center.business.CenterBO)7