use of org.mifos.framework.exceptions.ApplicationException in project head by mifos.
the class WebTierAccountServiceFacade method applyCharge.
@Override
public void applyCharge(Integer accountId, Short chargeId, Double chargeAmount, boolean isPenaltyType) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
try {
AccountBO account = new AccountBusinessService().getAccount(accountId);
if (account instanceof LoanBO && !account.isGroupLoanAccount()) {
List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(account.getAccountId());
if (individualLoans != null && individualLoans.size() > 0) {
for (LoanBO individual : individualLoans) {
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 {
FeeBO fee = this.feeDao.findById(chargeId);
if (fee instanceof RateFeeBO) {
individual.applyCharge(chargeId, chargeAmount);
} else {
Double radio = individual.getLoanAmount().getAmount().doubleValue() / ((LoanBO) account).getLoanAmount().getAmount().doubleValue();
individual.applyCharge(chargeId, chargeAmount * radio);
}
}
}
}
}
account.updateDetails(userContext);
CustomerLevel customerLevel = null;
if (account.isCustomerAccount()) {
customerLevel = account.getCustomer().getLevel();
}
if (account.getPersonnel() != null) {
checkPermissionForApplyCharges(account.getType(), customerLevel, userContext, account.getOffice().getOfficeId(), account.getPersonnel().getPersonnelId());
} else {
checkPermissionForApplyCharges(account.getType(), customerLevel, userContext, account.getOffice().getOfficeId(), userContext.getId());
}
this.transactionHelper.startTransaction();
if (isPenaltyType && account instanceof LoanBO) {
PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
((LoanBO) account).addAccountPenalty(new AccountPenaltiesEntity(account, penalty, chargeAmount));
} else {
account.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 CustomerServiceImpl method transferClientTo.
@Override
public void transferClientTo(ClientBO client, OfficeBO receivingBranch) {
try {
this.hibernateTransactionHelper.startTransaction();
this.hibernateTransactionHelper.beginAuditLoggingFor(client);
client.transferToBranch(receivingBranch);
if (client.getParentCustomer() != null) {
CustomerBO parent = client.getParentCustomer();
parent.incrementChildCount();
}
this.hibernateTransactionHelper.flushSession();
client.generateSearchId();
this.customerDao.save(client);
if (client.getParentCustomer() != null) {
this.customerDao.save(client.getParentCustomer());
}
this.hibernateTransactionHelper.commitTransaction();
} catch (ApplicationException e) {
this.hibernateTransactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
} catch (Exception e) {
this.hibernateTransactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
this.hibernateTransactionHelper.closeSession();
}
}
use of org.mifos.framework.exceptions.ApplicationException in project head by mifos.
the class CustomerServiceImpl method updateGroup.
@Override
public final void updateGroup(UserContext userContext, GroupUpdate groupUpdate) throws ApplicationException {
GroupBO group = customerDao.findGroupBySystemId(groupUpdate.getGlobalCustNum());
group.validateVersion(groupUpdate.getVersionNo());
group.setUserContext(userContext);
assembleCustomerPostionsFromDto(groupUpdate.getCustomerPositions(), group);
try {
hibernateTransactionHelper.startTransaction();
hibernateTransactionHelper.beginAuditLoggingFor(group);
group.updateTrainedDetails(groupUpdate);
group.setExternalId(groupUpdate.getExternalId());
Address address = null;
if (groupUpdate.getAddress() != null) {
address = new Address(groupUpdate.getAddress().getLine1(), groupUpdate.getAddress().getLine2(), groupUpdate.getAddress().getLine3(), groupUpdate.getAddress().getCity(), groupUpdate.getAddress().getState(), groupUpdate.getAddress().getCountry(), groupUpdate.getAddress().getZip(), groupUpdate.getAddress().getPhoneNumber());
}
group.updateAddress(address);
if (group.isNameDifferent(groupUpdate.getDisplayName())) {
customerDao.validateGroupNameIsNotTakenForOffice(groupUpdate.getDisplayName(), group.getOffice().getOfficeId());
group.setDisplayName(groupUpdate.getDisplayName());
}
updateLoanOfficerAndValidate(groupUpdate.getLoanOfficerId(), group);
customerDao.save(group);
hibernateTransactionHelper.commitTransaction();
} catch (ApplicationException e) {
hibernateTransactionHelper.rollbackTransaction();
throw 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 CustomerServiceImpl method transferClientTo.
@Override
public ClientBO transferClientTo(UserContext userContext, Integer groupId, String clientGlobalCustNum, Integer previousClientVersionNo) throws CustomerException {
ClientBO client = customerDao.findClientBySystemId(clientGlobalCustNum);
client.validateVersion(previousClientVersionNo);
client.validateIsSameGroup(groupId);
client.updateDetails(userContext);
GroupBO receivingGroup = (GroupBO) customerDao.findCustomerById(groupId);
client.validateReceivingGroup(receivingGroup);
client.validateForActiveAccounts();
client.validateForPeriodicFees();
if (client.getOfficeId() != receivingGroup.getOfficeId()) {
customerDao.checkPermissionforEditingClientOfficeMembership(client.getUserContext(), client);
}
CustomerBO oldParent = client.getParentCustomer();
try {
hibernateTransactionHelper.startTransaction();
hibernateTransactionHelper.beginAuditLoggingFor(client);
boolean regenerateSchedules = client.transferTo(receivingGroup);
if (oldParent != null) {
client.resetPositions(oldParent);
oldParent.updateDetails(client.getUserContext());
if (oldParent.getParentCustomer() != null) {
CustomerBO center = oldParent.getParentCustomer();
client.resetPositions(center);
center.setUserContext(client.getUserContext());
}
customerDao.save(oldParent);
}
receivingGroup.updateDetails(client.getUserContext());
customerDao.save(receivingGroup);
client.updateDetails(userContext);
customerDao.save(client);
hibernateTransactionHelper.flushAndClearSession();
if (regenerateSchedules) {
client = customerDao.findClientBySystemId(clientGlobalCustNum);
CalendarEvent calendarEvents = holidayDao.findCalendarEventsForThisYearAndNext(client.getOfficeId());
handleChangeInMeetingSchedule(client, calendarEvents.getWorkingDays(), calendarEvents.getHolidays());
}
hibernateTransactionHelper.commitTransaction();
return client;
} catch (ApplicationException e) {
this.hibernateTransactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
} catch (Exception e) {
this.hibernateTransactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
this.hibernateTransactionHelper.closeSession();
}
}
use of org.mifos.framework.exceptions.ApplicationException in project head by mifos.
the class CustomerServiceImpl method updateClientPersonalInfo.
@Override
public final void updateClientPersonalInfo(UserContext userContext, ClientPersonalInfoUpdate personalInfo) throws CustomerException {
ClientBO client = (ClientBO) this.customerDao.findCustomerById(personalInfo.getCustomerId());
client.validateVersion(personalInfo.getOriginalClientVersionNumber());
client.updateDetails(userContext);
LocalDate currentDOB = new LocalDate(client.getDateOfBirth());
LocalDate newDOB = currentDOB;
try {
// updating Date of birth
// doesn''t sound normal but it can be required in certain cases
// see http://mifosforge.jira.com/browse/MIFOS-4368
newDOB = new LocalDate(DateUtils.getDateAsSentFromBrowser(personalInfo.getDateOfBirth()));
} catch (InvalidDateException e) {
throw new MifosRuntimeException(e);
}
if (!currentDOB.isEqual(newDOB)) {
customerDao.validateClientForDuplicateNameOrGovtId(personalInfo.getClientDisplayName(), newDOB.toDateMidnight().toDate(), null);
}
try {
hibernateTransactionHelper.startTransaction();
hibernateTransactionHelper.beginAuditLoggingFor(client);
client.updatePersonalInfo(personalInfo);
clientPhotoService.update(personalInfo.getCustomerId().longValue(), personalInfo.getPicture());
customerDao.save(client);
hibernateTransactionHelper.commitTransaction();
} catch (ApplicationException e) {
hibernateTransactionHelper.rollbackTransaction();
throw new CustomerException(e.getKey(), e);
} catch (Exception e) {
hibernateTransactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
hibernateTransactionHelper.commitTransaction();
}
}
Aggregations