use of org.mifos.framework.exceptions.ApplicationException in project head by mifos.
the class FeeServiceFacadeWebTier method updateFee.
@Override
public void updateFee(FeeUpdateRequest feeUpdateRequest) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
try {
this.feeService.update(feeUpdateRequest, userContext);
} catch (ApplicationException e) {
throw new BusinessRuleException(e.getKey(), e);
}
}
use of org.mifos.framework.exceptions.ApplicationException in project head by mifos.
the class WebTierAccountServiceFacade method applyGroupCharge.
@Override
public void applyGroupCharge(Map<Integer, String> idsAndValues, Short chargeId, boolean isPenaltyType) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
TreeMap<Integer, String> idsAndValueAsTreeMap = new TreeMap<Integer, String>(idsAndValues);
try {
AccountBO parentAccount = ((LoanBO) legacyAccountDao.getAccount(new AccountBusinessService().getAccount(idsAndValueAsTreeMap.firstKey()).getAccountId())).getParentAccount();
BigDecimal parentAmount = ((LoanBO) parentAccount).getLoanAmount().getAmount();
BigDecimal membersAmount = BigDecimal.ZERO;
for (Map.Entry<Integer, String> entry : idsAndValues.entrySet()) {
LoanBO individual = loanDao.findById(entry.getKey());
Double chargeAmount = Double.valueOf(entry.getValue());
if (chargeAmount.equals(0.0)) {
continue;
}
membersAmount = membersAmount.add(individual.getLoanAmount().getAmount());
individual.updateDetails(userContext);
if (isPenaltyType && !chargeId.equals(Short.valueOf(AccountConstants.MISC_PENALTY))) {
PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
individual.addAccountPenalty(new AccountPenaltiesEntity(individual, penalty, chargeAmount));
} else {
individual.applyCharge(chargeId, chargeAmount);
}
}
boolean isRateCharge = false;
if (!chargeId.equals(Short.valueOf(AccountConstants.MISC_FEES)) && !chargeId.equals(Short.valueOf(AccountConstants.MISC_PENALTY))) {
if (isPenaltyType) {
PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
if (penalty instanceof RatePenaltyBO) {
isRateCharge = true;
}
} else {
FeeBO fee = feeDao.findById(chargeId);
if (fee.getFeeType().equals(RateAmountFlag.RATE)) {
isRateCharge = true;
}
}
}
Double chargeAmount = null;
if (!isRateCharge) {
chargeAmount = sumCharge(idsAndValues);
} else {
chargeAmount = Double.valueOf(idsAndValueAsTreeMap.firstEntry().getValue());
BigDecimal chargeAmountBig = new BigDecimal(chargeAmount);
membersAmount = membersAmount.multiply(chargeAmountBig);
int scale = Money.getInternalPrecision();
chargeAmountBig = membersAmount.divide(parentAmount, scale, RoundingMode.HALF_EVEN);
chargeAmount = chargeAmountBig.doubleValue();
}
parentAccount.updateDetails(userContext);
CustomerLevel customerLevel = null;
if (parentAccount.isCustomerAccount()) {
customerLevel = parentAccount.getCustomer().getLevel();
}
if (parentAccount.getPersonnel() != null) {
checkPermissionForApplyCharges(parentAccount.getType(), customerLevel, userContext, parentAccount.getOffice().getOfficeId(), parentAccount.getPersonnel().getPersonnelId());
} else {
checkPermissionForApplyCharges(parentAccount.getType(), customerLevel, userContext, parentAccount.getOffice().getOfficeId(), userContext.getId());
}
this.transactionHelper.startTransaction();
if (isPenaltyType && parentAccount instanceof LoanBO) {
PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
((LoanBO) parentAccount).addAccountPenalty(new AccountPenaltiesEntity(parentAccount, penalty, chargeAmount));
} else {
parentAccount.applyCharge(chargeId, chargeAmount);
}
this.transactionHelper.commitTransaction();
} catch (ServiceException e) {
this.transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} catch (ApplicationException e) {
this.transactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
}
}
use of org.mifos.framework.exceptions.ApplicationException in project head by mifos.
the class ReportsPersistence method createReportsDataSource.
public void createReportsDataSource(ReportsDataSource reportsDataSource) throws ApplicationException, SystemException {
Session session = null;
try {
session = StaticHibernateUtil.getSessionTL();
StaticHibernateUtil.startTransaction();
session.save(reportsDataSource);
session.flush();
StaticHibernateUtil.commitTransaction();
} catch (HibernateProcessException hpe) {
StaticHibernateUtil.rollbackTransaction();
throw new ApplicationException(hpe);
} catch (HibernateException e) {
StaticHibernateUtil.rollbackTransaction();
throw new ReportException(ReportsConstants.CREATE_FAILED_EXCEPTION, e);
} catch (Exception e) {
StaticHibernateUtil.rollbackTransaction();
throw new ReportException(ReportsConstants.CREATE_FAILED_EXCEPTION, e);
} finally {
StaticHibernateUtil.closeSession();
}
}
use of org.mifos.framework.exceptions.ApplicationException in project head by mifos.
the class ReportsPersistence method deleteReportsParamsMap.
/**
* Deletes a link between report and a parameter
*/
public void deleteReportsParamsMap(ReportsParamsMapValue reportsParamsMapValue) throws ApplicationException, SystemException {
Session session = null;
try {
session = StaticHibernateUtil.getSessionTL();
StaticHibernateUtil.startTransaction();
session.delete(reportsParamsMapValue);
session.flush();
StaticHibernateUtil.commitTransaction();
} catch (HibernateProcessException hpe) {
StaticHibernateUtil.rollbackTransaction();
throw new ApplicationException(hpe);
} catch (HibernateException e) {
StaticHibernateUtil.rollbackTransaction();
throw new ReportException(ReportsConstants.CREATE_FAILED_EXCEPTION, e);
} catch (Exception e) {
StaticHibernateUtil.rollbackTransaction();
throw new ReportException(ReportsConstants.CREATE_FAILED_EXCEPTION, e);
} finally {
StaticHibernateUtil.closeSession();
}
}
use of org.mifos.framework.exceptions.ApplicationException in project head by mifos.
the class ReportsPersistence method deleteReportParams.
public void deleteReportParams(ReportsParamsValue reportsParams) throws ApplicationException, SystemException {
Session session = null;
try {
session = StaticHibernateUtil.getSessionTL();
StaticHibernateUtil.startTransaction();
session.delete(reportsParams);
session.flush();
StaticHibernateUtil.commitTransaction();
} catch (HibernateProcessException hpe) {
StaticHibernateUtil.rollbackTransaction();
throw new ApplicationException(hpe);
} catch (HibernateException e) {
StaticHibernateUtil.rollbackTransaction();
throw new ReportException(ReportsConstants.CREATE_FAILED_EXCEPTION, e);
} catch (Exception e) {
StaticHibernateUtil.rollbackTransaction();
throw new ReportException(ReportsConstants.CREATE_FAILED_EXCEPTION, e);
} finally {
StaticHibernateUtil.closeSession();
}
}
Aggregations