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);
}
}
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;
}
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);
}
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);
}
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) {
}
}
Aggregations