use of org.mifos.framework.exceptions.ApplicationException in project head by mifos.
the class FeeServiceImpl method create.
@Override
public FeeBO create(FeeCreateRequest feeCreateRequest, UserContext userContext) throws ApplicationException {
FeeFrequencyTypeEntity feeFrequencyType = this.feeDao.findFeeFrequencyEntityByType(feeCreateRequest.getFeeFrequencyType());
CategoryTypeEntity feeCategoryType = this.feeDao.findFeeCategoryTypeEntityByType(feeCreateRequest.getCategoryType());
GLCodeEntity glCodeEntity = this.generalLedgerDao.findGlCodeById(feeCreateRequest.getGlCode());
FeeBO feeBO = null;
if (feeFrequencyType.isOneTime()) {
feeBO = createOneTimeFee(feeCreateRequest, feeFrequencyType, feeCategoryType, glCodeEntity, userContext);
} else {
feeBO = createPeriodicFee(feeCreateRequest, feeFrequencyType, feeCategoryType, glCodeEntity, userContext);
}
try {
hibernateTransactionHelper.startTransaction();
this.feeDao.save(feeBO);
hibernateTransactionHelper.commitTransaction();
} catch (Exception e) {
hibernateTransactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
hibernateTransactionHelper.closeSession();
}
return feeBO;
}
use of org.mifos.framework.exceptions.ApplicationException in project head by mifos.
the class FeeServiceImpl method update.
@Override
public void update(FeeUpdateRequest feeUpdateRequest, UserContext userContext) throws ApplicationException {
FeeBO feeBo = this.feeDao.findById(feeUpdateRequest.getFeeId());
feeBo.updateDetails(userContext);
FeeChangeType feeChangeType;
FeeStatus feeStatus = null;
if (feeUpdateRequest.getFeeStatusValue() != null) {
feeStatus = FeeStatus.getFeeStatus(feeUpdateRequest.getFeeStatusValue());
}
FeeStatusEntity feeStatusEntity = new FeeStatusEntity(feeStatus);
if (feeBo.getFeeType().equals(RateAmountFlag.AMOUNT)) {
AmountFeeBO amountFee = ((AmountFeeBO) feeBo);
feeChangeType = amountFee.calculateNewFeeChangeType(new Money(getCurrency(feeUpdateRequest.getCurrencyId()), feeUpdateRequest.getAmount()), feeStatusEntity);
amountFee.setFeeAmount(new Money(getCurrency(feeUpdateRequest.getCurrencyId()), feeUpdateRequest.getAmount()));
} else {
RateFeeBO rateFee = ((RateFeeBO) feeBo);
feeChangeType = rateFee.calculateNewFeeChangeType(feeUpdateRequest.getRateValue(), feeStatusEntity);
rateFee.setRate(feeUpdateRequest.getRateValue());
}
try {
hibernateTransactionHelper.startTransaction();
feeBo.updateStatus(feeStatus);
feeBo.updateFeeChangeType(feeChangeType);
this.feeDao.save(feeBo);
hibernateTransactionHelper.commitTransaction();
} catch (ApplicationException e) {
hibernateTransactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
} catch (Exception e) {
hibernateTransactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
hibernateTransactionHelper.closeSession();
}
}
use of org.mifos.framework.exceptions.ApplicationException in project head by mifos.
the class FeeServiceFacadeWebTier method createFee.
@Override
public String createFee(FeeCreateDto feeCreateDto) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
try {
FeeCategory feeCategory = (feeCreateDto.getCategoryType() != null) ? FeeCategory.getFeeCategory(feeCreateDto.getCategoryType()) : null;
FeeFrequencyType feeFrequencyType = (feeCreateDto.getFeeFrequencyType() != null) ? FeeFrequencyType.getFeeFrequencyType(feeCreateDto.getFeeFrequencyType()) : null;
FeePayment feePayment = (feeCreateDto.getFeePaymentType() != null) ? FeePayment.getFeePayment(feeCreateDto.getFeePaymentType()) : null;
FeeFormula feeFormula = (feeCreateDto.getFeeFormula() != null) ? FeeFormula.getFeeFormula(feeCreateDto.getFeeFormula()) : null;
RecurrenceType feeRecurrenceType = (feeCreateDto.getFeeRecurrenceType() != null) ? RecurrenceType.fromInt(feeCreateDto.getFeeRecurrenceType()) : null;
FeeCreateRequest feeCreateRequest = new FeeCreateRequest(feeCategory, feeFrequencyType, feeCreateDto.getGlCode(), feePayment, feeFormula, feeCreateDto.getFeeName(), feeCreateDto.isRateFee(), feeCreateDto.isCustomerDefaultFee(), feeCreateDto.getRate(), feeCreateDto.getCurrencyId(), feeCreateDto.getAmount(), feeRecurrenceType, feeCreateDto.getMonthRecurAfter(), feeCreateDto.getWeekRecurAfter());
FeeBO fee = this.feeService.create(feeCreateRequest, userContext);
return fee.getFeeId().toString();
} catch (ApplicationException e) {
throw new BusinessRuleException(e.getKey(), e);
}
}
use of org.mifos.framework.exceptions.ApplicationException in project head by mifos.
the class AccountStateMachines method retrieveNextPossibleCustomerStateForCenter.
private List<CustomerStatusEntity> retrieveNextPossibleCustomerStateForCenter(StateEntity customerStateEntityObj) throws ApplicationException {
logger.debug("In AccountStateMachines::retrieveNextPossibleCustomerStateForCenter()");
List<CustomerStatusEntity> stateEntityList = new ArrayList<CustomerStatusEntity>();
try {
List<StateEntity> stateList = statesMapForCenter.get(customerStateEntityObj);
if (null != stateList) {
for (StateEntity customerStateEntity : stateList) {
for (CustomerStatusEntity customerStatusEntry : customerStatusListForCenter) {
if (customerStatusEntry.sameId(customerStateEntity)) {
stateEntityList.add(customerStatusEntry);
break;
}
}
}
}
return stateEntityList;
} catch (Exception e) {
throw new StatesInitializationException(SavingsConstants.STATEINITIALIZATION_EXCEPTION, e);
}
}
use of org.mifos.framework.exceptions.ApplicationException in project head by mifos.
the class GroupServiceFacadeWebTier method transferGroupToBranch.
@Override
public CustomerDetailDto transferGroupToBranch(String globalCustNum, Short officeId, Integer previousGroupVersionNo) {
try {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
GroupBO group = this.customerDao.findGroupBySystemId(globalCustNum);
group.updateDetails(userContext);
checkVersionMismatch(previousGroupVersionNo, group.getVersionNo());
OfficeBO transferToOffice = this.officeDao.findOfficeById(officeId);
transferToOffice.setUserContext(userContext);
String groupGlobalCustNum = this.customerService.transferGroupTo(group, transferToOffice);
GroupBO transferedGroup = this.customerDao.findGroupBySystemId(groupGlobalCustNum);
return transferedGroup.toCustomerDetailDto();
} catch (ApplicationException e) {
throw new BusinessRuleException(e.getKey(), e);
}
}
Aggregations