Search in sources :

Example 21 with PersistenceException

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

the class AdminServiceFacadeWebTier method retrieveLoanProductFormReferenceData.

@Override
public LoanProductFormDto retrieveLoanProductFormReferenceData() {
    try {
        LoanPrdBusinessService service = new LoanPrdBusinessService();
        List<ListElement> productCategoryOptions = new ArrayList<ListElement>();
        List<ProductCategoryBO> productCategories = service.getActiveLoanProductCategories();
        for (ProductCategoryBO category : productCategories) {
            productCategoryOptions.add(new ListElement(category.getProductCategoryID().intValue(), category.getProductCategoryName()));
        }
        List<ListElement> applicableForOptions = new ArrayList<ListElement>();
        List<PrdApplicableMasterEntity> applicableCustomerTypes = this.loanProductDao.retrieveLoanApplicableProductCategories();
        for (PrdApplicableMasterEntity entity : applicableCustomerTypes) {
            applicableForOptions.add(new ListElement(entity.getId().intValue(), entity.getName()));
        }
        List<ListElement> gracePeriodTypeOptions = new ArrayList<ListElement>();
        List<GracePeriodTypeEntity> gracePeriodTypes = this.loanProductDao.retrieveGracePeriodTypes();
        for (GracePeriodTypeEntity gracePeriodTypeEntity : gracePeriodTypes) {
            gracePeriodTypeOptions.add(new ListElement(gracePeriodTypeEntity.getId().intValue(), gracePeriodTypeEntity.getName()));
        }
        List<ListElement> interestCalcTypesOptions = new ArrayList<ListElement>();
        List<InterestTypesEntity> interestCalcTypes = this.loanProductDao.retrieveInterestTypes();
        for (InterestTypesEntity entity : interestCalcTypes) {
            interestCalcTypesOptions.add(new ListElement(entity.getId().intValue(), entity.getName()));
        }
        List<ListElement> sourceOfFunds = new ArrayList<ListElement>();
        List<FundBO> funds = this.fundDao.findAllFunds();
        for (FundBO fund : funds) {
            sourceOfFunds.add(new ListElement(fund.getFundId().intValue(), fund.getFundName()));
        }
        List<ListElement> loanFee = new ArrayList<ListElement>();
        List<FeeBO> fees = feeDao.getAllAppllicableFeeForLoanCreation();
        for (FeeBO fee : fees) {
            loanFee.add(new ListElement(fee.getFeeId().intValue(), fee.getFeeName()));
        }
        List<ListElement> principalGlCodes = new ArrayList<ListElement>();
        List<GLCodeEntity> principalGlCodeEntities = new FinancialBusinessService().getGLCodes(FinancialActionConstants.PRINCIPALPOSTING, FinancialConstants.CREDIT);
        for (GLCodeEntity glCode : principalGlCodeEntities) {
            principalGlCodes.add(new ListElement(glCode.getGlcodeId().intValue(), glCode.getGlcode()));
        }
        List<ListElement> interestGlCodes = new ArrayList<ListElement>();
        List<GLCodeEntity> interestGlCodeEntities = new FinancialBusinessService().getGLCodes(FinancialActionConstants.INTERESTPOSTING, FinancialConstants.CREDIT);
        for (GLCodeEntity glCode : interestGlCodeEntities) {
            interestGlCodes.add(new ListElement(glCode.getGlcodeId().intValue(), glCode.getGlcode()));
        }
        List<ListElement> statusOptions = new ArrayList<ListElement>();
        List<PrdStatusEntity> applicableStatuses = service.getApplicablePrdStatus(Short.valueOf("1"));
        for (PrdStatusEntity entity : applicableStatuses) {
            statusOptions.add(new ListElement(entity.getOfferingStatusId().intValue(), entity.getPrdState().getName()));
        }
        boolean multiCurrencyEnabled = AccountingRules.isMultiCurrencyEnabled();
        List<ListElement> currencyOptions = new ArrayList<ListElement>();
        if (multiCurrencyEnabled) {
            LinkedList<MifosCurrency> currencies = AccountingRules.getCurrencies();
            for (MifosCurrency mifosCurrency : currencies) {
                currencyOptions.add(new ListElement(mifosCurrency.getCurrencyId().intValue(), mifosCurrency.getCurrencyCode()));
            }
        }
        return new LoanProductFormDto(productCategoryOptions, gracePeriodTypeOptions, sourceOfFunds, loanFee, principalGlCodes, interestGlCodes, interestCalcTypesOptions, applicableForOptions, statusOptions, currencyOptions, multiCurrencyEnabled);
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    } catch (SystemException e) {
        throw new MifosRuntimeException(e);
    } catch (ApplicationException e) {
        throw new BusinessRuleException(e.getKey(), e);
    }
}
Also used : InterestTypesEntity(org.mifos.application.master.business.InterestTypesEntity) LoanPrdBusinessService(org.mifos.accounts.productdefinition.business.service.LoanPrdBusinessService) ArrayList(java.util.ArrayList) FinancialBusinessService(org.mifos.accounts.financial.business.service.FinancialBusinessService) LoanProductFormDto(org.mifos.dto.screen.LoanProductFormDto) BusinessRuleException(org.mifos.service.BusinessRuleException) SystemException(org.mifos.framework.exceptions.SystemException) GracePeriodTypeEntity(org.mifos.accounts.productdefinition.business.GracePeriodTypeEntity) MifosCurrency(org.mifos.application.master.business.MifosCurrency) ProductCategoryBO(org.mifos.accounts.productdefinition.business.ProductCategoryBO) FundBO(org.mifos.accounts.fund.business.FundBO) GLCodeEntity(org.mifos.accounts.financial.business.GLCodeEntity) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ListElement(org.mifos.dto.screen.ListElement) PersistenceException(org.mifos.framework.exceptions.PersistenceException) FeeBO(org.mifos.accounts.fees.business.FeeBO) PrdStatusEntity(org.mifos.accounts.productdefinition.business.PrdStatusEntity) PrdApplicableMasterEntity(org.mifos.accounts.productdefinition.business.PrdApplicableMasterEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 22 with PersistenceException

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

the class CollectionSheetServiceFacadeWebTier method loadAllActiveBranchesAndSubsequentDataIfApplicable.

@Override
public CollectionSheetEntryFormDto loadAllActiveBranchesAndSubsequentDataIfApplicable(final UserContext userContext) {
    final Short branchId = userContext.getBranchId();
    final Short centerHierarchyExists = ClientRules.getCenterHierarchyExists() ? Constants.YES : Constants.NO;
    List<OfficeDetailsDto> activeBranches = new ArrayList<OfficeDetailsDto>();
    List<ListItem<Short>> paymentTypesDtoList = new ArrayList<ListItem<Short>>();
    List<CustomerDto> customerList = new ArrayList<CustomerDto>();
    List<PersonnelDto> loanOfficerList = new ArrayList<PersonnelDto>();
    Short reloadFormAutomatically = Constants.YES;
    final Short backDatedTransactionAllowed = Constants.NO;
    try {
        final List<PaymentTypeEntity> paymentTypesList = legacyMasterDao.findMasterDataEntitiesWithLocale(PaymentTypeEntity.class);
        paymentTypesDtoList = convertToPaymentTypesListItemDto(paymentTypesList);
        activeBranches = officePersistence.getActiveOffices(branchId);
        if (activeBranches.size() == 1) {
            loanOfficerList = legacyPersonnelDao.getActiveLoanOfficersInBranch(PersonnelConstants.LOAN_OFFICER, branchId, userContext.getId(), userContext.getLevelId());
            if (loanOfficerList.size() == 1) {
                Short customerLevel;
                if (centerHierarchyExists.equals(Constants.YES)) {
                    customerLevel = Short.valueOf(CustomerLevel.CENTER.getValue());
                } else {
                    customerLevel = Short.valueOf(CustomerLevel.GROUP.getValue());
                }
                customerList = customerPersistence.getActiveParentList(loanOfficerList.get(0).getPersonnelId(), customerLevel, branchId);
                if (customerList.size() == 1) {
                    reloadFormAutomatically = Constants.YES;
                }
                reloadFormAutomatically = Constants.NO;
            }
        }
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
    return new CollectionSheetEntryFormDto(activeBranches, paymentTypesDtoList, loanOfficerList, customerList, reloadFormAutomatically, centerHierarchyExists, backDatedTransactionAllowed);
}
Also used : ArrayList(java.util.ArrayList) CustomerDto(org.mifos.dto.domain.CustomerDto) PersonnelDto(org.mifos.dto.domain.PersonnelDto) OfficeDetailsDto(org.mifos.dto.domain.OfficeDetailsDto) PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) PersistenceException(org.mifos.framework.exceptions.PersistenceException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 23 with PersistenceException

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

the class LegacyMasterDao method findMasterDataEntityWithLocale.

@SuppressWarnings("unchecked")
public <T extends MasterDataEntity> T findMasterDataEntityWithLocale(final Class<T> entityType, final Short entityId) throws PersistenceException {
    Session session = getSession();
    List<T> masterEntities = session.createQuery("from " + entityType.getName() + " masterEntity where masterEntity.id = " + entityId).list();
    if (masterEntities != null && masterEntities.size() > 0) {
        T masterDataEntity = masterEntities.get(0);
        Hibernate.initialize(masterDataEntity.getNames());
        return masterDataEntity;
    }
    throw new PersistenceException("errors.entityNotFound");
}
Also used : PersistenceException(org.mifos.framework.exceptions.PersistenceException) Session(org.hibernate.Session)

Example 24 with PersistenceException

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

the class AdminServiceFacadeWebTier method retrieveNotAllowedProductsForMix.

@Override
public List<PrdOfferingDto> retrieveNotAllowedProductsForMix(Integer productTypeId, Integer productId) {
    try {
        List<PrdOfferingDto> notAllowedProductDtos = new ArrayList<PrdOfferingDto>();
        List<PrdOfferingBO> allowedProducts = new PrdOfferingPersistence().getNotAllowedPrdOfferingsForMixProduct(productId.toString(), productTypeId.toString());
        for (PrdOfferingBO product : allowedProducts) {
            notAllowedProductDtos.add(product.toDto());
        }
        return notAllowedProductDtos;
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : PrdOfferingPersistence(org.mifos.accounts.productdefinition.persistence.PrdOfferingPersistence) PrdOfferingBO(org.mifos.accounts.productdefinition.business.PrdOfferingBO) ArrayList(java.util.ArrayList) PersistenceException(org.mifos.framework.exceptions.PersistenceException) PrdOfferingDto(org.mifos.dto.domain.PrdOfferingDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 25 with PersistenceException

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

the class AdminServiceFacadeWebTier method updateAcceptedPaymentTypes.

@Override
public void updateAcceptedPaymentTypes(String[] chosenAcceptedFees, String[] chosenAcceptedLoanDisbursements, String[] chosenAcceptedLoanRepayments, String[] chosenAcceptedSavingDeposits, String[] chosenAcceptedSavingWithdrawals) {
    LegacyAcceptedPaymentTypeDao persistence = legacyAcceptedPaymentTypeDao;
    List<AcceptedPaymentType> deletedPaymentTypeList = new ArrayList<AcceptedPaymentType>();
    List<AcceptedPaymentType> addedPaymentTypeList = new ArrayList<AcceptedPaymentType>();
    List<PaymentTypeDto> allPayments = getAllPaymentTypes(null);
    AcceptedPaymentTypeDto oldAcceptedPaymentTypeDto = retrieveAcceptedPaymentTypes();
    for (int i = 0; i < TrxnTypes.values().length; i++) {
        TrxnTypes transactionType = TrxnTypes.values()[i];
        List<PaymentTypeDto> selectedPaymentTypes = new ArrayList<PaymentTypeDto>();
        List<PaymentTypeDto> outList = null;
        if (transactionType == TrxnTypes.fee) {
            selectedPaymentTypes = populateSelectedPayments(chosenAcceptedFees, allPayments);
            outList = oldAcceptedPaymentTypeDto.getOutFeeList();
        } else if (transactionType == TrxnTypes.loan_disbursement) {
            selectedPaymentTypes = populateSelectedPayments(chosenAcceptedLoanDisbursements, allPayments);
            outList = oldAcceptedPaymentTypeDto.getOutDisbursementList();
        } else if (transactionType == TrxnTypes.loan_repayment) {
            selectedPaymentTypes = populateSelectedPayments(chosenAcceptedLoanRepayments, allPayments);
            outList = oldAcceptedPaymentTypeDto.getOutRepaymentList();
        } else if (transactionType == TrxnTypes.savings_deposit) {
            selectedPaymentTypes = populateSelectedPayments(chosenAcceptedSavingDeposits, allPayments);
            outList = oldAcceptedPaymentTypeDto.getOutDepositList();
        } else if (transactionType == TrxnTypes.savings_withdrawal) {
            selectedPaymentTypes = populateSelectedPayments(chosenAcceptedSavingWithdrawals, allPayments);
            outList = oldAcceptedPaymentTypeDto.getOutWithdrawalList();
        } else {
            throw new MifosRuntimeException("Unknown account action for accepted payment type " + transactionType.toString());
        }
        process(selectedPaymentTypes, outList, deletedPaymentTypeList, addedPaymentTypeList, persistence, transactionType);
    }
    try {
        if (addedPaymentTypeList.size() > 0) {
            persistence.addAcceptedPaymentTypes(addedPaymentTypeList);
            StaticHibernateUtil.commitTransaction();
        }
        if (deletedPaymentTypeList.size() > 0) {
            persistence.deleteAcceptedPaymentTypes(deletedPaymentTypeList);
            StaticHibernateUtil.commitTransaction();
        }
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : AcceptedPaymentType(org.mifos.accounts.acceptedpaymenttype.business.AcceptedPaymentType) TrxnTypes(org.mifos.application.util.helpers.TrxnTypes) ArrayList(java.util.ArrayList) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AcceptedPaymentTypeDto(org.mifos.dto.domain.AcceptedPaymentTypeDto) PaymentTypeDto(org.mifos.dto.screen.PaymentTypeDto) LegacyAcceptedPaymentTypeDao(org.mifos.accounts.acceptedpaymenttype.persistence.LegacyAcceptedPaymentTypeDao) AcceptedPaymentTypeDto(org.mifos.dto.domain.AcceptedPaymentTypeDto) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

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