Search in sources :

Example 16 with ServiceException

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

the class WebTierAccountServiceFacade method getAccountPaymentInformation.

@Override
public AccountPaymentDto getAccountPaymentInformation(Integer accountId, String paymentType, Short localeId, UserReferenceDto userReferenceDto, Date paymentDate) {
    try {
        AccountBO account = accountBusinessService.getAccount(accountId);
        CustomerDto customer = account.getCustomer().toCustomerDto();
        List<SavingsDetailDto> savingsInUse = clientServiceFacade.retrieveSavingsInUseForClient(customer.getCustomerId());
        List<SavingsDetailDto> accountsForTransfer = new ArrayList<SavingsDetailDto>();
        if (savingsInUse != null) {
            for (SavingsDetailDto savingsAccount : savingsInUse) {
                if (savingsAccount.getAccountStateId().equals(AccountState.SAVINGS_ACTIVE.getValue())) {
                    accountsForTransfer.add(savingsAccount);
                }
            }
        }
        if (isLoanPayment(paymentType)) {
            scheduleCalculatorAdaptor.computeExtraInterest((LoanBO) account, paymentDate);
        }
        UserReferenceDto accountUser = userReferenceDto;
        if (account.getPersonnel() != null) {
            accountUser = new UserReferenceDto(account.getPersonnel().getPersonnelId());
        }
        List<ListItem<Short>> paymentTypeList = constructPaymentTypeList(paymentType, localeId);
        AccountTypeDto accountType = AccountTypeDto.getAccountType(account.getAccountType().getAccountTypeId());
        Money totalPaymentDueMoney = account.getTotalPaymentDue();
        String totalPaymentDue;
        if (account instanceof LoanBO && totalPaymentDueMoney.isZero()) {
            totalPaymentDue = ((LoanBO) account).getTotalRepayableAmount().toString();
        } else {
            totalPaymentDue = totalPaymentDueMoney.toString();
        }
        clearSessionAndRollback();
        return new AccountPaymentDto(accountType, account.getVersionNo(), paymentTypeList, totalPaymentDue, accountUser, getLastPaymentDate(account), accountsForTransfer, customer);
    } catch (ServiceException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : SavingsDetailDto(org.mifos.dto.domain.SavingsDetailDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) CustomerDto(org.mifos.dto.domain.CustomerDto) ArrayList(java.util.ArrayList) UserReferenceDto(org.mifos.dto.domain.UserReferenceDto) AccountBO(org.mifos.accounts.business.AccountBO) Money(org.mifos.framework.util.helpers.Money) ServiceException(org.mifos.framework.exceptions.ServiceException) ListItem(org.mifos.application.servicefacade.ListItem) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 17 with ServiceException

use of org.mifos.framework.exceptions.ServiceException 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 18 with ServiceException

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

the class AccountBusinessServiceTest method shouldGrantPermissionForDifferentDayAdjustments.

@Test
public void shouldGrantPermissionForDifferentDayAdjustments() {
    Date lastPaymentDate = TestUtils.getDate(10, 10, 2010);
    when(activityMapper.isAdjustmentPermittedForBackDatedPayments(lastPaymentDate, userContext, recordOfficeId, recordLoanOfficer)).thenReturn(true);
    try {
        accountBusinessService.checkPermissionForAdjustmentOnBackDatedPayments(lastPaymentDate, userContext, recordOfficeId, recordLoanOfficer);
    } catch (ServiceException e) {
        Assert.fail("Should not have thrown exception when back dated adjustments are permitted");
    }
    verify(activityMapper, times(1)).isAdjustmentPermittedForBackDatedPayments(lastPaymentDate, userContext, recordOfficeId, recordLoanOfficer);
}
Also used : ServiceException(org.mifos.framework.exceptions.ServiceException) Date(java.util.Date) Test(org.junit.Test)

Example 19 with ServiceException

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

the class AccountBusinessServiceTest method shouldNotGrantPermissionForDifferentDayAdjustmentsIfNotPermitted.

@Test
public void shouldNotGrantPermissionForDifferentDayAdjustmentsIfNotPermitted() {
    Date lastPaymentDate = TestUtils.getDate(10, 10, 2010);
    when(activityMapper.isAdjustmentPermittedForBackDatedPayments(lastPaymentDate, userContext, recordOfficeId, recordLoanOfficer)).thenReturn(false);
    try {
        accountBusinessService.checkPermissionForAdjustmentOnBackDatedPayments(lastPaymentDate, userContext, recordOfficeId, recordLoanOfficer);
        Assert.fail("Should have thrown exception when back dated adjustments are not permitted");
    } catch (ServiceException e) {
        assertThat(e.getKey(), is(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED));
    }
    verify(activityMapper, times(1)).isAdjustmentPermittedForBackDatedPayments(lastPaymentDate, userContext, recordOfficeId, recordLoanOfficer);
}
Also used : ServiceException(org.mifos.framework.exceptions.ServiceException) Date(java.util.Date) Test(org.junit.Test)

Example 20 with ServiceException

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

the class LoanPrdBusinessServiceTest method testInvalidConnectionThrowsExceptionInGetApplicableProductCategories.

@Test
@ExpectedException(value = ServiceException.class)
public void testInvalidConnectionThrowsExceptionInGetApplicableProductCategories() throws PersistenceException {
    try {
        when(prdOfferingPersistence.getApplicableProductCategories(ProductType.LOAN, PrdCategoryStatus.ACTIVE)).thenThrow(new PersistenceException("some exception"));
        loanPrdBusinessService.getActiveLoanProductCategories();
        Assert.fail("should fail because of invalid session");
    } catch (ServiceException e) {
    }
}
Also used : ServiceException(org.mifos.framework.exceptions.ServiceException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) Test(org.junit.Test) ExpectedException(org.springframework.test.annotation.ExpectedException)

Aggregations

ServiceException (org.mifos.framework.exceptions.ServiceException)93 PersistenceException (org.mifos.framework.exceptions.PersistenceException)46 MifosRuntimeException (org.mifos.core.MifosRuntimeException)39 Test (org.junit.Test)34 ExpectedException (org.springframework.test.annotation.ExpectedException)29 ArrayList (java.util.ArrayList)24 UserContext (org.mifos.security.util.UserContext)19 AccountBO (org.mifos.accounts.business.AccountBO)17 MifosUser (org.mifos.security.MifosUser)16 LoanBO (org.mifos.accounts.loan.business.LoanBO)15 AccountBusinessService (org.mifos.accounts.business.service.AccountBusinessService)14 AccountException (org.mifos.accounts.exceptions.AccountException)13 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)13 BusinessRuleException (org.mifos.service.BusinessRuleException)11 Date (java.util.Date)8 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)7 BigDecimal (java.math.BigDecimal)6 ProductCategoryBusinessService (org.mifos.accounts.productdefinition.business.service.ProductCategoryBusinessService)6 DateTimeService (org.mifos.framework.util.DateTimeService)6 LocalDate (org.joda.time.LocalDate)5