use of org.mifos.service.BusinessRuleException in project head by mifos.
the class CustomerServiceImpl method createCenter.
@Override
public final void createCenter(CenterBO customer, MeetingBO meeting, List<AccountFeesEntity> accountFees) {
try {
customer.validate();
customer.validateMeetingAndFees(accountFees);
customerDao.validateCenterNameIsNotTakenForOffice(customer.getDisplayName(), customer.getOfficeId());
createCustomer(customer, meeting, accountFees);
} catch (CustomerException e) {
throw new BusinessRuleException(e.getKey(), new Object[] { customer.getDisplayName() });
}
}
use of org.mifos.service.BusinessRuleException in project head by mifos.
the class CustomerServiceImpl method transferGroupTo.
@Override
public final String transferGroupTo(GroupBO group, CenterBO receivingCenter) throws CustomerException {
group.validateReceivingCenter(receivingCenter);
group.validateNoActiveAccountsExist();
if (group.isDifferentBranch(receivingCenter.getOffice())) {
customerDao.validateGroupNameIsNotTakenForOffice(group.getDisplayName(), receivingCenter.getOfficeId());
}
CustomerBO oldParent = group.getParentCustomer();
try {
hibernateTransactionHelper.startTransaction();
hibernateTransactionHelper.beginAuditLoggingFor(group);
boolean regenerateSchedules = group.transferTo(receivingCenter);
if (oldParent != null) {
oldParent.updateDetails(group.getUserContext());
customerDao.save(oldParent);
}
receivingCenter.updateDetails(group.getUserContext());
customerDao.save(receivingCenter);
group.updateDetails(group.getUserContext());
customerDao.save(group);
Set<CustomerBO> clients = group.getChildren();
for (CustomerBO client : clients) {
client.setUserContext(group.getUserContext());
((ClientBO) client).handleGroupTransfer();
client.setUpdateDetails();
customerDao.save(client);
}
hibernateTransactionHelper.flushSession();
GroupBO groupInitialised = group;
if (regenerateSchedules) {
CalendarEvent calendarEvents = holidayDao.findCalendarEventsForThisYearAndNext(group.getOfficeId());
groupInitialised = customerDao.findGroupBySystemId(group.getGlobalCustNum());
handleChangeInMeetingSchedule(groupInitialised, calendarEvents.getWorkingDays(), calendarEvents.getHolidays());
}
hibernateTransactionHelper.commitTransaction();
return groupInitialised.getGlobalCustNum();
} 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.service.BusinessRuleException in project head by mifos.
the class CustomerServiceImpl method updateClientStatus.
@Override
public final void updateClientStatus(ClientBO client, CustomerStatus oldStatus, CustomerStatus newStatus, CustomerStatusFlag customerStatusFlag, CustomerNoteEntity customerNote) throws CustomerException {
PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(client.getUserContext().getId());
handeClientChangeOfStatus(client, newStatus);
CustomerStatusFlagEntity customerStatusFlagEntity = populateCustomerStatusFlag(customerStatusFlag);
try {
hibernateTransactionHelper.startTransaction();
hibernateTransactionHelper.beginAuditLoggingFor(client);
client.clearCustomerFlagsIfApplicable(oldStatus, newStatus);
client.updateCustomerStatus(newStatus);
changeStatus(client, oldStatus, newStatus);
if (customerStatusFlagEntity != null) {
client.addCustomerFlag(customerStatusFlagEntity);
}
client.addCustomerNotes(customerNote);
this.handleChangeOfClientStatusToClosedOrCancelled(client, customerStatusFlag, customerNote, loggedInUser);
customerDao.save(client);
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.service.BusinessRuleException in project head by mifos.
the class OfficeHierarchyServiceImpl method updateApplicationLabels.
@Override
public void updateApplicationLabels(List<OfficeLevelEntity> changedOfficeLabels, List<LookUpEntity> lookupEntities, List<GracePeriodTypeEntity> gracePeriods, List<LookUpValueEntity> accountStatuses) {
try {
transactionHelper.startTransaction();
for (OfficeLevelEntity entity : changedOfficeLabels) {
officeDao.save(entity);
LookUpValueEntity lookupValue = entity.getLookUpValue();
String messageText = lookupValue.getMessageText();
if (StringUtils.isBlank(messageText)) {
messageText = ApplicationContextProvider.getBean(MessageLookup.class).lookup(lookupValue.getPropertiesKey());
}
ApplicationContextProvider.getBean(MessageLookup.class).updateLookupValueInCache(entity.getLookUpValue().getLookUpName(), messageText);
}
for (GracePeriodTypeEntity entity : gracePeriods) {
applicationConfigurationDao.save(entity);
LookUpValueEntity lookupValue = entity.getLookUpValue();
String messageText = lookupValue.getMessageText();
if (StringUtils.isBlank(messageText)) {
messageText = ApplicationContextProvider.getBean(MessageLookup.class).lookup(lookupValue.getPropertiesKey());
}
ApplicationContextProvider.getBean(MessageLookup.class).updateLookupValueInCache(entity.getLookUpValue().getLookUpName(), messageText);
}
for (LookUpEntity entity : lookupEntities) {
applicationConfigurationDao.save(entity);
ApplicationContextProvider.getBean(MessageLookup.class).updateLookupValueInCache(entity.getEntityType(), entity.findLabel());
}
for (LookUpValueEntity entity : accountStatuses) {
applicationConfigurationDao.save(entity);
}
transactionHelper.commitTransaction();
if (!accountStatuses.isEmpty()) {
MenuRepository.getInstance().removeMenuForAllLocale();
}
} catch (BusinessRuleException e) {
transactionHelper.rollbackTransaction();
throw e;
} catch (Exception e) {
transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
transactionHelper.closeSession();
}
}
use of org.mifos.service.BusinessRuleException in project head by mifos.
the class OfficeServiceFacadeWebTier method updateOffice.
@Override
public boolean updateOffice(Short officeId, Integer versionNum, OfficeUpdateRequest officeUpdateRequest) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
try {
boolean isParentOfficeChanged = false;
OfficeBO office = officeDao.findOfficeById(officeId);
office.validateVersion(versionNum);
OfficeBO parentOffice = null;
if (officeUpdateRequest.getParentOfficeId() != null) {
parentOffice = officeDao.findOfficeById(officeUpdateRequest.getParentOfficeId());
if (office.isDifferentParentOffice(parentOffice)) {
holidayDao.validateNoExtraFutureHolidaysApplicableOnParentOffice(office.getParentOffice().getOfficeId(), officeUpdateRequest.getParentOfficeId());
}
}
if (office.isNameDifferent(officeUpdateRequest.getOfficeName())) {
officeDao.validateOfficeNameIsNotTaken(officeUpdateRequest.getOfficeName());
}
if (office.isShortNameDifferent(officeUpdateRequest.getShortName())) {
officeDao.validateOfficeShortNameIsNotTaken(officeUpdateRequest.getShortName());
}
OfficeStatus newStatus = OfficeStatus.getOfficeStatus(officeUpdateRequest.getNewStatus());
if (!office.isStatusDifferent(newStatus)) {
if (OfficeStatus.INACTIVE.equals(officeUpdateRequest.getNewStatus())) {
officeDao.validateNoActiveChildrenExist(office.getOfficeId());
officeDao.validateNoActivePeronnelExist(office.getOfficeId());
}
if (parentOffice != null) {
if (parentOffice.isInActive()) {
throw new OfficeException(OfficeConstants.KEYPARENTNOTACTIVE);
}
}
}
StaticHibernateUtil.startTransaction();
office.update(userContext, officeUpdateRequest, parentOffice);
StaticHibernateUtil.commitTransaction();
return isParentOfficeChanged;
} catch (OfficeException e1) {
throw new BusinessRuleException(e1.getKey(), e1);
} catch (ApplicationException e) {
StaticHibernateUtil.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
} catch (Exception e) {
StaticHibernateUtil.rollbackTransaction();
throw new MifosRuntimeException(e.getMessage(), e);
} finally {
StaticHibernateUtil.closeSession();
}
}
Aggregations