Search in sources :

Example 41 with ApplicationException

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

the class FeeServiceImpl method create.

@Override
public FeeBO create(FeeCreateRequest feeCreateRequest, UserContext userContext) throws ApplicationException {
    FeeFrequencyTypeEntity feeFrequencyType = this.feeDao.findFeeFrequencyEntityByType(feeCreateRequest.getFeeFrequencyType());
    CategoryTypeEntity feeCategoryType = this.feeDao.findFeeCategoryTypeEntityByType(feeCreateRequest.getCategoryType());
    GLCodeEntity glCodeEntity = this.generalLedgerDao.findGlCodeById(feeCreateRequest.getGlCode());
    FeeBO feeBO = null;
    if (feeFrequencyType.isOneTime()) {
        feeBO = createOneTimeFee(feeCreateRequest, feeFrequencyType, feeCategoryType, glCodeEntity, userContext);
    } else {
        feeBO = createPeriodicFee(feeCreateRequest, feeFrequencyType, feeCategoryType, glCodeEntity, userContext);
    }
    try {
        hibernateTransactionHelper.startTransaction();
        this.feeDao.save(feeBO);
        hibernateTransactionHelper.commitTransaction();
    } catch (Exception e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        hibernateTransactionHelper.closeSession();
    }
    return feeBO;
}
Also used : FeeFrequencyTypeEntity(org.mifos.accounts.fees.business.FeeFrequencyTypeEntity) CategoryTypeEntity(org.mifos.accounts.fees.business.CategoryTypeEntity) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) FeeBO(org.mifos.accounts.fees.business.FeeBO) RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) FeeException(org.mifos.accounts.fees.exceptions.FeeException) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 42 with ApplicationException

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

the class FeeServiceImpl method update.

@Override
public void update(FeeUpdateRequest feeUpdateRequest, UserContext userContext) throws ApplicationException {
    FeeBO feeBo = this.feeDao.findById(feeUpdateRequest.getFeeId());
    feeBo.updateDetails(userContext);
    FeeChangeType feeChangeType;
    FeeStatus feeStatus = null;
    if (feeUpdateRequest.getFeeStatusValue() != null) {
        feeStatus = FeeStatus.getFeeStatus(feeUpdateRequest.getFeeStatusValue());
    }
    FeeStatusEntity feeStatusEntity = new FeeStatusEntity(feeStatus);
    if (feeBo.getFeeType().equals(RateAmountFlag.AMOUNT)) {
        AmountFeeBO amountFee = ((AmountFeeBO) feeBo);
        feeChangeType = amountFee.calculateNewFeeChangeType(new Money(getCurrency(feeUpdateRequest.getCurrencyId()), feeUpdateRequest.getAmount()), feeStatusEntity);
        amountFee.setFeeAmount(new Money(getCurrency(feeUpdateRequest.getCurrencyId()), feeUpdateRequest.getAmount()));
    } else {
        RateFeeBO rateFee = ((RateFeeBO) feeBo);
        feeChangeType = rateFee.calculateNewFeeChangeType(feeUpdateRequest.getRateValue(), feeStatusEntity);
        rateFee.setRate(feeUpdateRequest.getRateValue());
    }
    try {
        hibernateTransactionHelper.startTransaction();
        feeBo.updateStatus(feeStatus);
        feeBo.updateFeeChangeType(feeChangeType);
        this.feeDao.save(feeBo);
        hibernateTransactionHelper.commitTransaction();
    } catch (ApplicationException e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } catch (Exception e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        hibernateTransactionHelper.closeSession();
    }
}
Also used : RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) Money(org.mifos.framework.util.helpers.Money) FeeStatusEntity(org.mifos.accounts.fees.business.FeeStatusEntity) BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) FeeChangeType(org.mifos.accounts.fees.util.helpers.FeeChangeType) FeeBO(org.mifos.accounts.fees.business.FeeBO) RateFeeBO(org.mifos.accounts.fees.business.RateFeeBO) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) FeeStatus(org.mifos.accounts.fees.util.helpers.FeeStatus) AmountFeeBO(org.mifos.accounts.fees.business.AmountFeeBO) FeeException(org.mifos.accounts.fees.exceptions.FeeException) BusinessRuleException(org.mifos.service.BusinessRuleException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 43 with ApplicationException

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

the class FeeServiceFacadeWebTier method createFee.

@Override
public String createFee(FeeCreateDto feeCreateDto) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = new UserContextFactory().create(user);
    try {
        FeeCategory feeCategory = (feeCreateDto.getCategoryType() != null) ? FeeCategory.getFeeCategory(feeCreateDto.getCategoryType()) : null;
        FeeFrequencyType feeFrequencyType = (feeCreateDto.getFeeFrequencyType() != null) ? FeeFrequencyType.getFeeFrequencyType(feeCreateDto.getFeeFrequencyType()) : null;
        FeePayment feePayment = (feeCreateDto.getFeePaymentType() != null) ? FeePayment.getFeePayment(feeCreateDto.getFeePaymentType()) : null;
        FeeFormula feeFormula = (feeCreateDto.getFeeFormula() != null) ? FeeFormula.getFeeFormula(feeCreateDto.getFeeFormula()) : null;
        RecurrenceType feeRecurrenceType = (feeCreateDto.getFeeRecurrenceType() != null) ? RecurrenceType.fromInt(feeCreateDto.getFeeRecurrenceType()) : null;
        FeeCreateRequest feeCreateRequest = new FeeCreateRequest(feeCategory, feeFrequencyType, feeCreateDto.getGlCode(), feePayment, feeFormula, feeCreateDto.getFeeName(), feeCreateDto.isRateFee(), feeCreateDto.isCustomerDefaultFee(), feeCreateDto.getRate(), feeCreateDto.getCurrencyId(), feeCreateDto.getAmount(), feeRecurrenceType, feeCreateDto.getMonthRecurAfter(), feeCreateDto.getWeekRecurAfter());
        FeeBO fee = this.feeService.create(feeCreateRequest, userContext);
        return fee.getFeeId().toString();
    } catch (ApplicationException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : FeePayment(org.mifos.accounts.fees.util.helpers.FeePayment) BusinessRuleException(org.mifos.service.BusinessRuleException) FeeFormula(org.mifos.accounts.fees.util.helpers.FeeFormula) ApplicationException(org.mifos.framework.exceptions.ApplicationException) FeeFrequencyType(org.mifos.accounts.fees.util.helpers.FeeFrequencyType) UserContext(org.mifos.security.util.UserContext) RecurrenceType(org.mifos.application.meeting.util.helpers.RecurrenceType) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) FeeBO(org.mifos.accounts.fees.business.FeeBO) FeeCategory(org.mifos.accounts.fees.util.helpers.FeeCategory)

Example 44 with ApplicationException

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

the class AccountStateMachines method retrieveNextPossibleCustomerStateForCenter.

private List<CustomerStatusEntity> retrieveNextPossibleCustomerStateForCenter(StateEntity customerStateEntityObj) throws ApplicationException {
    logger.debug("In AccountStateMachines::retrieveNextPossibleCustomerStateForCenter()");
    List<CustomerStatusEntity> stateEntityList = new ArrayList<CustomerStatusEntity>();
    try {
        List<StateEntity> stateList = statesMapForCenter.get(customerStateEntityObj);
        if (null != stateList) {
            for (StateEntity customerStateEntity : stateList) {
                for (CustomerStatusEntity customerStatusEntry : customerStatusListForCenter) {
                    if (customerStatusEntry.sameId(customerStateEntity)) {
                        stateEntityList.add(customerStatusEntry);
                        break;
                    }
                }
            }
        }
        return stateEntityList;
    } catch (Exception e) {
        throw new StatesInitializationException(SavingsConstants.STATEINITIALIZATION_EXCEPTION, e);
    }
}
Also used : ArrayList(java.util.ArrayList) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) CustomerStatusEntity(org.mifos.customers.business.CustomerStatusEntity) ServiceException(org.mifos.framework.exceptions.ServiceException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) StateEntity(org.mifos.application.master.business.StateEntity)

Example 45 with ApplicationException

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

the class GroupServiceFacadeWebTier method transferGroupToBranch.

@Override
public CustomerDetailDto transferGroupToBranch(String globalCustNum, Short officeId, Integer previousGroupVersionNo) {
    try {
        MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        UserContext userContext = toUserContext(user);
        GroupBO group = this.customerDao.findGroupBySystemId(globalCustNum);
        group.updateDetails(userContext);
        checkVersionMismatch(previousGroupVersionNo, group.getVersionNo());
        OfficeBO transferToOffice = this.officeDao.findOfficeById(officeId);
        transferToOffice.setUserContext(userContext);
        String groupGlobalCustNum = this.customerService.transferGroupTo(group, transferToOffice);
        GroupBO transferedGroup = this.customerDao.findGroupBySystemId(groupGlobalCustNum);
        return transferedGroup.toCustomerDetailDto();
    } catch (ApplicationException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) OfficeBO(org.mifos.customers.office.business.OfficeBO) UserContext(org.mifos.security.util.UserContext) GroupBO(org.mifos.customers.group.business.GroupBO) MifosUser(org.mifos.security.MifosUser)

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