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