Search in sources :

Example 6 with PersistenceException

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

the class LegacyLoanDao method findClientPerformanceHistoryLastLoanAmountWhenRepaidLoanAdjusted.

public Money findClientPerformanceHistoryLastLoanAmountWhenRepaidLoanAdjusted(Integer clientId, Integer excludeAccountId) {
    HashMap<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put("CLIENT_ID", clientId);
    queryParameters.put("EXCLUDE_ACCOUNT_ID", excludeAccountId);
    try {
        final Object[] obj = (Object[]) execUniqueResultNamedQuery("ClientPerformanceHistory.getLastLoanAmountWhenRepaidLoanAdjusted", queryParameters);
        if (obj == null || obj[1] == null) {
            return null;
        }
        Integer loanAccountId = (Integer) obj[0];
        BigDecimal lastLoanAmount = (BigDecimal) obj[1];
        LoanBO loan = (LoanBO) StaticHibernateUtil.getSessionTL().get(LoanBO.class, loanAccountId);
        return new Money(loan.getCurrency(), lastLoanAmount);
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) HashMap(java.util.HashMap) LoanBO(org.mifos.accounts.loan.business.LoanBO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) BigDecimal(java.math.BigDecimal) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 7 with PersistenceException

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

the class LegacyLoanDao method countOfSavingsAccounts.

@SuppressWarnings("unchecked")
public int countOfSavingsAccounts() {
    HashMap<String, Object> queryParameters = new HashMap<String, Object>();
    try {
        List queryResult = executeNamedQuery("countOfSavingsAccounts", queryParameters);
        int count = 0;
        if (null != queryResult && queryResult.size() > 0) {
            Object obj = queryResult.get(0);
            if (obj != null) {
                count = ((Number) obj).intValue();
            }
        }
        return count;
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : HashMap(java.util.HashMap) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ArrayList(java.util.ArrayList) List(java.util.List) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 8 with PersistenceException

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

the class LegacyLoanDao method getTotalOutstandingPrincipalOfLoanAccountsInActiveGoodStanding.

@SuppressWarnings("unchecked")
public BigDecimal getTotalOutstandingPrincipalOfLoanAccountsInActiveGoodStanding(final Short branchId, final Short loanOfficerId, final Short loanProductId) throws PersistenceException {
    BigDecimal loanBalanceAmount = new BigDecimal(0);
    try {
        Session session = StaticHibernateUtil.getSessionTL();
        Criteria criteria = session.createCriteria(LoanBO.class).setProjection(Projections.sum("loanBalance.amount")).add(Restrictions.eq("accountState.id", (short) 5)).add(Restrictions.eq("office.officeId", branchId));
        if (loanOfficerId != (short) -1) {
            criteria.add(Restrictions.eq("personnel.personnelId", loanOfficerId));
        }
        if (loanProductId != (short) -1) {
            criteria.add(Restrictions.eq("loanOffering.prdOfferingId", loanProductId));
        }
        List list = criteria.list();
        loanBalanceAmount = (BigDecimal) list.get(0);
    } catch (Exception e) {
        throw new PersistenceException(e);
    }
    return loanBalanceAmount;
}
Also used : LoanBO(org.mifos.accounts.loan.business.LoanBO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ArrayList(java.util.ArrayList) List(java.util.List) Criteria(org.hibernate.Criteria) BigDecimal(java.math.BigDecimal) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) HibernateException(org.hibernate.HibernateException) Session(org.hibernate.Session)

Example 9 with PersistenceException

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

the class LegacyLoanDao method countOfLoanAccounts.

@SuppressWarnings("unchecked")
public int countOfLoanAccounts() {
    HashMap<String, Object> queryParameters = new HashMap<String, Object>();
    try {
        List queryResult = executeNamedQuery("countOfLoanAccounts", queryParameters);
        int count = 0;
        if (null != queryResult && queryResult.size() > 0) {
            Object obj = queryResult.get(0);
            if (obj != null) {
                count = ((Number) obj).intValue();
            }
        }
        return count;
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : HashMap(java.util.HashMap) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ArrayList(java.util.ArrayList) List(java.util.List) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 10 with PersistenceException

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

the class LegacyLoanDao method getLoanAccountsInActiveBadStanding.

@SuppressWarnings("unchecked")
public List<LoanBO> getLoanAccountsInActiveBadStanding(final Short branchId, final Short loanOfficerId, final Short loanProductId) throws PersistenceException {
    String activeBadAccountIdQuery = "from org.mifos.accounts.loan.business.LoanBO loan where loan.accountState.id = 9";
    StringBuilder queryString = loanQueryString(branchId, loanOfficerId, loanProductId, activeBadAccountIdQuery);
    try {
        Session session = StaticHibernateUtil.getSessionTL();
        Query query = session.createQuery(queryString.toString());
        return query.list();
    } catch (Exception e) {
        throw new PersistenceException(e);
    }
}
Also used : Query(org.hibernate.Query) PersistenceException(org.mifos.framework.exceptions.PersistenceException) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) HibernateException(org.hibernate.HibernateException) Session(org.hibernate.Session)

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