use of org.mifos.service.BusinessRuleException 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.service.BusinessRuleException in project head by mifos.
the class ClientPhotoServiceFileSystem method update.
@Override
public boolean update(Long clientId, InputStream in) {
if (in == null) {
return false;
}
ClientPhoto clientPhoto = read(clientId);
if (clientPhoto == null) {
return create(clientId, in);
}
try {
ImageInfo updateImageInfo = ImageStorageManager.updateImage(in, clientPhoto.getImageInfo());
if (updateImageInfo == null) {
return false;
}
hibernateTransactionHelper.startTransaction();
genericDao.getSession().save(updateImageInfo);
hibernateTransactionHelper.commitTransaction();
} catch (IOException e) {
LOG.error("Unable to persist", e);
return false;
} catch (Exception e) {
throw new BusinessRuleException(ClientConstants.INVALID_PHOTO, new Object[] { e.getMessage() }, e);
}
return true;
}
use of org.mifos.service.BusinessRuleException in project head by mifos.
the class LoanDisbursementAction method update.
@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward update(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
LoanDisbursementActionForm actionForm = (LoanDisbursementActionForm) form;
UserContext uc = getUserContext(request);
Date trxnDate = getDateFromString(actionForm.getTransactionDate(), uc.getPreferredLocale());
trxnDate = DateUtils.getDateWithoutTimeStamp(trxnDate.getTime());
Date receiptDate = getDateFromString(actionForm.getReceiptDate(), uc.getPreferredLocale());
Integer loanAccountId = Integer.valueOf(actionForm.getAccountId());
Integer accountForTransferId = (StringUtils.isBlank(actionForm.getAccountForTransfer())) ? null : legacyAccountDao.getAccountIdByGlobalAccountNumber(actionForm.getAccountForTransfer());
AccountBO accountBO = new AccountBusinessService().getAccount(loanAccountId);
Date originalDisbursementDate = DateUtils.getDateWithoutTimeStamp(((LoanBO) accountBO).getDisbursementDate());
createGroupQuestionnaire.saveResponses(request, actionForm, loanAccountId);
try {
String paymentTypeIdStringForDisbursement = actionForm.getPaymentTypeId();
String paymentTypeIdStringForFees = actionForm.getPaymentModeOfPayment();
Short paymentTypeIdForDisbursement = StringUtils.isEmpty(paymentTypeIdStringForDisbursement) ? PaymentTypes.CASH.getValue() : Short.valueOf(paymentTypeIdStringForDisbursement);
Short paymentTypeIdForFees = StringUtils.isEmpty(paymentTypeIdStringForFees) ? PaymentTypes.CASH.getValue() : Short.valueOf(paymentTypeIdStringForFees);
Short paymentTypeId = Short.valueOf(paymentTypeIdForDisbursement);
final String comment = "";
final BigDecimal disbursalAmount = new BigDecimal(actionForm.getLoanAmount());
CustomerDto customerDto = null;
PaymentTypeDto paymentType = null;
AccountPaymentParametersDto loanDisbursement = new AccountPaymentParametersDto(new UserReferenceDto(uc.getId()), new AccountReferenceDto(loanAccountId), disbursalAmount, new LocalDate(trxnDate), paymentType, comment, new LocalDate(receiptDate), actionForm.getReceiptId(), customerDto);
monthClosingServiceFacade.validateTransactionDate(trxnDate);
// GLIM
List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(loanAccountId);
for (LoanBO individual : individualLoans) {
if (!loanAccountServiceFacade.isTrxnDateValid(Integer.valueOf(individual.getAccountId()), trxnDate)) {
throw new BusinessRuleException("errors.invalidTxndateOfDisbursal");
}
}
this.loanAccountServiceFacade.disburseLoan(loanDisbursement, paymentTypeId, paymentTypeIdForFees, accountForTransferId);
for (LoanBO individual : individualLoans) {
loanDisbursement = new AccountPaymentParametersDto(new UserReferenceDto(uc.getId()), new AccountReferenceDto(individual.getAccountId()), individual.getLoanAmount().getAmount(), new LocalDate(trxnDate), paymentType, comment, new LocalDate(receiptDate), actionForm.getReceiptId(), customerDto);
this.loanAccountServiceFacade.disburseLoan(loanDisbursement, paymentTypeId, paymentTypeIdForFees, accountForTransferId);
}
if (!((LoanBO) accountBO).isFixedRepaymentSchedule() && !originalDisbursementDate.equals(((LoanBO) accountBO).getDisbursementDate())) {
this.loanAccountServiceFacade.updateMemberLoansFeeAmounts(loanAccountId);
}
} catch (BusinessRuleException e) {
throw new AccountException(e.getMessage());
} catch (MifosRuntimeException e) {
if (e.getCause() != null && e.getCause() instanceof AccountException) {
throw new AccountException(e.getCause().getMessage());
}
String msg = "errors.cannotDisburseLoan.because.disburseFailed";
logger.error(msg, e);
throw new AccountException(msg);
} catch (Exception e) {
String msg = "errors.cannotDisburseLoan.because.disburseFailed";
logger.error(msg, e);
throw new AccountException(msg);
}
return mapping.findForward(Constants.UPDATE_SUCCESS);
}
use of org.mifos.service.BusinessRuleException in project head by mifos.
the class GroupCustAction method update.
@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
GroupBO group = (GroupBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
GroupCustActionForm actionForm = (GroupCustActionForm) form;
boolean trained = false;
if (actionForm.getTrainedValue() != null && actionForm.getTrainedValue().equals(Short.valueOf("1"))) {
trained = true;
}
AddressDto address = null;
if (actionForm.getAddress() != null) {
address = Address.toDto(actionForm.getAddress());
}
GroupUpdate groupUpdate = new GroupUpdate(group.getCustomerId(), group.getGlobalCustNum(), group.getVersionNo(), actionForm.getDisplayName(), actionForm.getLoanOfficerIdValue(), actionForm.getExternalId(), trained, actionForm.getTrainedDate(), address, actionForm.getCustomFields(), actionForm.getCustomerPositions());
try {
this.groupServiceFacade.updateGroup(groupUpdate);
} catch (BusinessRuleException e) {
throw new ApplicationException(e.getMessageKey(), e);
}
return mapping.findForward(ActionForwards.update_success.toString());
}
use of org.mifos.service.BusinessRuleException in project head by mifos.
the class CustomerApplyAdjustmentAction method applyAdjustment.
@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward applyAdjustment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
String forward = null;
request.setAttribute(CustomerConstants.METHOD, CustomerConstants.METHOD_APPLY_ADJUSTMENT);
CustomerApplyAdjustmentActionForm applyAdjustmentActionForm = (CustomerApplyAdjustmentActionForm) form;
String globalCustNum = applyAdjustmentActionForm.getGlobalCustNum();
CustomerBO customerBO = this.customerDao.findCustomerBySystemId(globalCustNum);
SessionUtils.removeAttribute(Constants.BUSINESS_KEY, request);
SessionUtils.setAttribute(Constants.BUSINESS_KEY, customerBO, request);
if (null == customerBO.getCustomerAccount().findMostRecentNonzeroPaymentByPaymentDate()) {
request.setAttribute(CustomerConstants.METHOD, CustomerConstants.METHOD_PREVIEW_ADJUSTMENT);
throw new ApplicationException(AccountExceptionConstants.ZEROAMNTADJUSTMENT);
}
try {
this.centerServiceFacade.revertLastChargesPayment(globalCustNum, applyAdjustmentActionForm.getAdjustmentNote());
} catch (BusinessRuleException e) {
request.setAttribute(CustomerConstants.METHOD, CustomerConstants.METHOD_PREVIEW_ADJUSTMENT);
throw e;
}
String inputPage = applyAdjustmentActionForm.getInput();
resetActionFormFields(applyAdjustmentActionForm);
if (inputPage != null) {
if (inputPage.equals(CustomerConstants.VIEW_GROUP_CHARGES)) {
forward = CustomerConstants.APPLY_ADJUSTMENT_GROUP_SUCCESS;
} else if (inputPage.equals(CustomerConstants.VIEW_CENTER_CHARGES)) {
forward = CustomerConstants.APPLY_ADJUSTMENT_CENTER_SUCCESS;
} else if (inputPage.equals(CustomerConstants.VIEW_CLIENT_CHARGES)) {
forward = CustomerConstants.APPLY_ADJUSTMENT_CLIENT_SUCCESS;
}
}
return mapping.findForward(forward);
}
Aggregations