Search in sources :

Example 41 with PersistenceException

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

the class SavingsServiceFacadeWebTier method closeSavingsAccount.

@Override
public void closeSavingsAccount(Long savingsId, String notes, SavingsWithdrawalDto closeAccountDto) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    SavingsBO savingsAccount = this.savingsDao.findById(savingsId);
    savingsAccount.updateDetails(userContext);
    PersonnelBO createdBy = this.personnelDao.findPersonnelById(userContext.getId());
    LocalDate closureDate = closeAccountDto.getDateOfWithdrawal();
    // Assumption that all previous interest postings occurred correctly
    InterestScheduledEvent postingSchedule = savingsInterestScheduledEventFactory.createScheduledEventFrom(savingsAccount.getInterestPostingMeeting());
    LocalDate nextPostingDate = new LocalDate(savingsAccount.getNextIntPostDate());
    LocalDate startOfPostingPeriod = postingSchedule.findFirstDateOfPeriodForMatchingDate(nextPostingDate);
    CalendarPeriod postingPeriodAtClosure;
    if (startOfPostingPeriod.isAfter(closureDate)) {
        postingPeriodAtClosure = new CalendarPeriod(closureDate, closureDate);
    } else {
        postingPeriodAtClosure = new CalendarPeriod(startOfPostingPeriod, closureDate);
    }
    List<EndOfDayDetail> allEndOfDayDetailsForAccount = savingsDao.retrieveAllEndOfDayDetailsFor(savingsAccount.getCurrency(), Long.valueOf(savingsId));
    InterestPostingPeriodResult postingPeriodAtClosureResult = determinePostingPeriodResult(postingPeriodAtClosure, savingsAccount, allEndOfDayDetailsForAccount);
    savingsAccount.postInterest(postingSchedule, postingPeriodAtClosureResult, createdBy);
    AccountNotesEntity notesEntity = new AccountNotesEntity(new DateTimeService().getCurrentJavaSqlDate(), notes, createdBy, savingsAccount);
    try {
        CustomerBO customer = savingsAccount.getCustomer();
        if (closeAccountDto.getCustomerId() != null) {
            List<CustomerBO> clientList = new CustomerPersistence().getActiveAndOnHoldChildren(savingsAccount.getCustomer().getSearchId(), savingsAccount.getCustomer().getOfficeId(), CustomerLevel.CLIENT);
            for (CustomerBO client : clientList) {
                if (closeAccountDto.getCustomerId().intValue() == client.getCustomerId().intValue()) {
                    customer = client;
                    break;
                }
            }
        }
        Money amount = new Money(savingsAccount.getCurrency(), closeAccountDto.getAmount().toString());
        PaymentTypeEntity paymentType = new PaymentTypeEntity(closeAccountDto.getModeOfPayment().shortValue());
        Date receiptDate = null;
        if (closeAccountDto.getDateOfReceipt() != null) {
            receiptDate = closeAccountDto.getDateOfReceipt().toDateMidnight().toDate();
        }
        AccountPaymentEntity closeAccount = new AccountPaymentEntity(savingsAccount, amount, closeAccountDto.getReceiptId(), receiptDate, paymentType, closeAccountDto.getDateOfWithdrawal().toDateMidnight().toDate());
        this.transactionHelper.startTransaction();
        this.transactionHelper.beginAuditLoggingFor(savingsAccount);
        savingsAccount.closeAccount(closeAccount, notesEntity, customer, createdBy);
        this.savingsDao.save(savingsAccount);
        this.transactionHelper.commitTransaction();
    } catch (BusinessRuleException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getMessageKey(), e);
    } catch (PersistenceException e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        this.transactionHelper.closeSession();
    }
}
Also used : InterestPostingPeriodResult(org.mifos.accounts.savings.interest.InterestPostingPeriodResult) UserContext(org.mifos.security.util.UserContext) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) AccountNotesEntity(org.mifos.accounts.business.AccountNotesEntity) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) LocalDate(org.joda.time.LocalDate) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) Money(org.mifos.framework.util.helpers.Money) BusinessRuleException(org.mifos.service.BusinessRuleException) InterestScheduledEvent(org.mifos.accounts.savings.interest.schedule.InterestScheduledEvent) EndOfDayDetail(org.mifos.accounts.savings.interest.EndOfDayDetail) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) CalendarPeriod(org.mifos.accounts.savings.interest.CalendarPeriod) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) DateTimeService(org.mifos.framework.util.DateTimeService) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 42 with PersistenceException

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

the class SavingsServiceFacadeWebTier method retrieveCustomerThatQualifyForSavings.

@Override
public List<CustomerSearchResultDto> retrieveCustomerThatQualifyForSavings(CustomerSearchDto customerSearchDto) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    try {
        List<CustomerSearchResultDto> pagedDetails = new ArrayList<CustomerSearchResultDto>();
        QueryResult customerForSavings = new CustomerPersistence().searchCustForSavings(customerSearchDto.getSearchTerm(), userContext.getId());
        int position = this.resultsetOffset(customerSearchDto.getPage(), customerSearchDto.getPageSize());
        List<AccountSearchResultsDto> pagedResults = customerForSavings.get(position, customerSearchDto.getPageSize());
        int i = 1;
        for (AccountSearchResultsDto customerBO : pagedResults) {
            CustomerSearchResultDto customer = new CustomerSearchResultDto();
            customer.setCustomerId(customerBO.getClientId());
            customer.setBranchName(customerBO.getOfficeName());
            customer.setGlobalId(customerBO.getGlobelNo());
            customer.setSearchIndex(i);
            customer.setCenterName(StringUtils.defaultIfEmpty(customerBO.getCenterName(), "--"));
            customer.setGroupName(StringUtils.defaultIfEmpty(customerBO.getGroupName(), "--"));
            customer.setClientName(customerBO.getClientName());
            pagedDetails.add(customer);
            i++;
        }
        return pagedDetails;
    } catch (PersistenceException e) {
        throw new MifosRuntimeException(e);
    } catch (HibernateSearchException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : UserContext(org.mifos.security.util.UserContext) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) QueryResult(org.mifos.framework.hibernate.helper.QueryResult) AccountSearchResultsDto(org.mifos.accounts.util.helpers.AccountSearchResultsDto) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerSearchResultDto(org.mifos.dto.domain.CustomerSearchResultDto) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 43 with PersistenceException

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

the class SavingsServiceFacadeWebTier method fundTransfer.

@Override
public void fundTransfer(FundTransferDto fundTransferDto) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    SavingsBO targetAcc = this.savingsDao.findBySystemId(fundTransferDto.getTargetGlobalAccountNum());
    SavingsBO sourceAcc = this.savingsDao.findBySystemId(fundTransferDto.getSourceGlobalAccountNum());
    SavingsDepositDto depositDto;
    SavingsWithdrawalDto withdrawalDto;
    // prepare data
    try {
        depositDto = new SavingsDepositDto(targetAcc.getAccountId().longValue(), targetAcc.getCustomer().getCustomerId().longValue(), fundTransferDto.getTrxnDate(), fundTransferDto.getAmount().doubleValue(), this.legacyAcceptedPaymentTypeDao.getSavingsTransferId().intValue(), fundTransferDto.getReceiptId(), fundTransferDto.getReceiptDate(), userContext.getPreferredLocale());
        withdrawalDto = new SavingsWithdrawalDto(sourceAcc.getAccountId().longValue(), sourceAcc.getCustomer().getCustomerId().longValue(), fundTransferDto.getTrxnDate(), fundTransferDto.getAmount().doubleValue(), this.legacyAcceptedPaymentTypeDao.getSavingsTransferId().intValue(), fundTransferDto.getReceiptId(), fundTransferDto.getReceiptDate(), userContext.getPreferredLocale());
    } catch (PersistenceException ex) {
        throw new MifosRuntimeException(ex);
    }
    // transaction
    try {
        this.transactionHelper.startTransaction();
        PaymentDto deposit = deposit(depositDto, true);
        PaymentDto withdrawal = withdraw(withdrawalDto, true);
        // connect the two payments
        AccountPaymentEntity sourcePayment = sourceAcc.findPaymentById(withdrawal.getPaymentId());
        AccountPaymentEntity targetPayment = targetAcc.findPaymentById(deposit.getPaymentId());
        sourcePayment.setOtherTransferPayment(targetPayment);
        targetPayment.setOtherTransferPayment(sourcePayment);
        this.savingsDao.save(sourceAcc);
        this.savingsDao.save(targetAcc);
        this.transactionHelper.commitTransaction();
    } catch (BusinessRuleException ex) {
        this.transactionHelper.rollbackTransaction();
        throw ex;
    } catch (Exception ex) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(ex);
    } finally {
        this.transactionHelper.closeSession();
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) SavingsDepositDto(org.mifos.dto.domain.SavingsDepositDto) UserContext(org.mifos.security.util.UserContext) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) MifosUser(org.mifos.security.MifosUser) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) SavingsWithdrawalDto(org.mifos.dto.domain.SavingsWithdrawalDto) AdjustableSavingsPaymentDto(org.mifos.dto.screen.AdjustableSavingsPaymentDto) PaymentDto(org.mifos.dto.domain.PaymentDto) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) AccountException(org.mifos.accounts.exceptions.AccountException) BusinessRuleException(org.mifos.service.BusinessRuleException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) HibernateSearchException(org.mifos.framework.exceptions.HibernateSearchException) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 44 with PersistenceException

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

the class ReportsBusinessService method runReport.

public String runReport(int reportId, HttpServletRequest request, String applPath, String exportType) throws ServiceException, PersistenceException {
    String exportFileName = "";
    String error = "";
    Connection conn = null;
    List<ReportsJasperMap> reportJasperMap = reportsPersistence.findJasperOfReportId(reportId);
    ReportsJasperMap rjm = null;
    Object[] obj = reportJasperMap.toArray();
    if (obj != null && obj.length > 0) {
        rjm = (ReportsJasperMap) obj[0];
    }
    List<ReportsParamsMap> reportParams = (List) request.getSession().getAttribute("listOfAllParametersForReportId");
    obj = reportParams.toArray();
    Map parameters = new HashMap();
    if (obj != null && obj.length > 0) {
        for (Object element : obj) {
            ReportsParamsMap rp = (ReportsParamsMap) element;
            String paramname = rp.getReportsParams().getName();
            int para = 0;
            double dblpara = 0;
            String paramvalue = request.getParameter(paramname) == null ? "" : request.getParameter(paramname);
            String type = rp.getReportsParams().getClassname();
            if (type.equalsIgnoreCase("java.lang.Integer")) {
                paramvalue = paramvalue.equals("") ? "0" : paramvalue;
                try {
                    para = Integer.parseInt(paramvalue);
                    parameters.put(paramname, para);
                } catch (Exception e) {
                    error = "Not a valid Integer";
                }
            } else if (type.equalsIgnoreCase("java.lang.Double")) {
                paramvalue = paramvalue.equals("") ? "0" : paramvalue;
                try {
                    dblpara = Double.parseDouble(paramvalue);
                    parameters.put(paramname, dblpara);
                } catch (Exception e) {
                    error = "Not a Valid Double";
                }
            } else {
                parameters.put(paramname, paramvalue);
            }
        }
        request.getSession().setAttribute("paramerror", error);
        if (error.equals("")) {
            try {
                String jaspername = "";
                if (rjm != null) {
                    jaspername = rjm.getReportJasper() == null ? "" : rjm.getReportJasper();
                }
                jaspername = jaspername.replaceAll(".jasper", ".jrxml");
                conn = reportsPersistence.getJasperConnection();
                String fullpath = applPath + jaspername;
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                try {
                // FIXME: why is this commented out? Looks like a
                // potential connection leak.
                /*
                         * if(conn!=null) conn.close();
                         */
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
    } else {
        try {
            String jaspername = "";
            if (rjm != null) {
                jaspername = rjm.getReportJasper() == null ? "" : rjm.getReportJasper();
            }
            jaspername = jaspername.replaceAll(".jasper", ".jrxml");
            conn = reportsPersistence.getJasperConnection();
            String fullpath = applPath + jaspername;
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            try {
            /*
                     * if(conn!=null) conn.close();
                     */
            } catch (Exception se) {
                throw new RuntimeException(se);
            }
        }
    }
    return exportFileName;
}
Also used : ReportsParamsMap(org.mifos.reports.business.ReportsParamsMap) HashMap(java.util.HashMap) Connection(java.sql.Connection) SystemException(org.mifos.framework.exceptions.SystemException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) ServiceException(org.mifos.framework.exceptions.ServiceException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ReportsJasperMap(org.mifos.reports.business.ReportsJasperMap) AbstractBusinessObject(org.mifos.framework.business.AbstractBusinessObject) List(java.util.List) HashMap(java.util.HashMap) ReportsJasperMap(org.mifos.reports.business.ReportsJasperMap) Map(java.util.Map) ReportsParamsMap(org.mifos.reports.business.ReportsParamsMap)

Example 45 with PersistenceException

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

the class LegacyGenericDao method save.

public Object save(final Object object) throws PersistenceException {
    try {
        getSession().saveOrUpdate(object);
        AuditInterceptor interceptor = (AuditInterceptor) StaticHibernateUtil.getInterceptor();
        if (interceptor.isAuditLogRequired()) {
            interceptor.createChangeValueMap(object);
        }
    } catch (HibernateException e) {
        throw new PersistenceException(e);
    }
    return object;
}
Also used : AuditInterceptor(org.mifos.framework.components.audit.util.helpers.AuditInterceptor) HibernateException(org.hibernate.HibernateException) PersistenceException(org.mifos.framework.exceptions.PersistenceException)

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