use of org.mifos.customers.exceptions.CustomerException 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.customers.exceptions.CustomerException 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.customers.exceptions.CustomerException 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.customers.exceptions.CustomerException in project head by mifos.
the class CustomerServiceImpl method updateCenterStatus.
@Override
public final void updateCenterStatus(CenterBO center, CustomerStatus newStatus, CustomerStatusFlag customerStatusFlag, CustomerNoteEntity customerNote) throws CustomerException {
if (newStatus.isCenterInActive()) {
center.validateChangeToInActive();
List<CustomerDto> clientsThatAreNotClosedOrCanceled = this.customerDao.findClientsThatAreNotCancelledOrClosed(center.getSearchId(), center.getOffice().getOfficeId());
List<CustomerDto> groupsThatAreNotClosedOrCancelled = this.customerDao.findGroupsThatAreNotCancelledOrClosed(center.getSearchId(), center.getOffice().getOfficeId());
if (clientsThatAreNotClosedOrCanceled.size() > 0 || groupsThatAreNotClosedOrCancelled.size() > 0) {
final String errorMessage = messageLookupHelper.lookupLabel(ConfigurationConstants.GROUP);
throw new CustomerException(CustomerConstants.ERROR_STATE_CHANGE_EXCEPTION, new Object[] { errorMessage });
}
} else if (newStatus.isCenterActive()) {
center.validateChangeToActive();
center.validateLoanOfficerIsActive();
}
CustomerStatusFlagEntity customerStatusFlagEntity = populateCustomerStatusFlag(customerStatusFlag);
try {
hibernateTransactionHelper.startTransaction();
hibernateTransactionHelper.beginAuditLoggingFor(center);
center.updateCustomerStatus(newStatus, customerNote, customerStatusFlagEntity);
customerDao.save(center);
hibernateTransactionHelper.commitTransaction();
} catch (Exception e) {
this.hibernateTransactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
this.hibernateTransactionHelper.closeSession();
}
}
use of org.mifos.customers.exceptions.CustomerException in project head by mifos.
the class CustomerServiceImpl method changeStatus.
private void changeStatus(CustomerBO customer, CustomerStatus oldStatus, CustomerStatus newStatus) throws CustomerException {
Short oldStatusId = oldStatus.getValue();
Short newStatusId = newStatus.getValue();
if (customer.isClient()) {
ClientBO client = (ClientBO) customer;
if (client.isActiveForFirstTime(oldStatusId, newStatusId)) {
if (client.getParentCustomer() != null) {
CustomerHierarchyEntity hierarchy = new CustomerHierarchyEntity(client, client.getParentCustomer());
client.addCustomerHierarchy(hierarchy);
}
CalendarEvent applicableCalendarEvents = holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
List<AccountFeesEntity> accountFees = new ArrayList<AccountFeesEntity>(customer.getCustomerAccount().getAccountFees());
client.getCustomerAccount().createSchedulesAndFeeSchedulesForFirstTimeActiveCustomer(customer, accountFees, customer.getCustomerMeetingValue(), applicableCalendarEvents, new DateMidnight().toDateTime());
client.setCustomerActivationDate(new DateTimeService().getCurrentJavaDateTime());
if (client.getOfferingsAssociatedInCreate() != null) {
for (ClientInitialSavingsOfferingEntity clientOffering : client.getOfferingsAssociatedInCreate()) {
try {
SavingsOfferingBO savingsOffering = savingsProductDao.findById(clientOffering.getSavingsOffering().getPrdOfferingId().intValue());
if (savingsOffering.isActive()) {
List<CustomFieldDto> customerFieldsForSavings = new ArrayList<CustomFieldDto>();
client.addAccount(new SavingsBO(client.getUserContext(), savingsOffering, client, AccountState.SAVINGS_ACTIVE, savingsOffering.getRecommendedAmount(), customerFieldsForSavings));
}
} catch (AccountException pe) {
throw new CustomerException(pe);
}
}
}
new SavingsPersistence().persistSavingAccounts(client);
try {
if (client.getParentCustomer() != null) {
List<SavingsBO> savingsList = new CustomerPersistence().retrieveSavingsAccountForCustomer(client.getParentCustomer().getCustomerId());
if (client.getParentCustomer().getParentCustomer() != null) {
savingsList.addAll(new CustomerPersistence().retrieveSavingsAccountForCustomer(client.getParentCustomer().getParentCustomer().getCustomerId()));
}
for (SavingsBO savings : savingsList) {
savings.setUserContext(client.getUserContext());
if (client.getCustomerMeeting().getMeeting() != null) {
if (!(savings.getCustomer().getLevel() == CustomerLevel.GROUP && savings.getRecommendedAmntUnit().getId().equals(RecommendedAmountUnit.COMPLETE_GROUP.getValue()))) {
DateTime today = new DateTime().toDateMidnight().toDateTime();
savings.generateDepositAccountActions(client, client.getCustomerMeeting().getMeeting(), applicableCalendarEvents.getWorkingDays(), applicableCalendarEvents.getHolidays(), today);
savings.update();
}
}
}
}
} catch (PersistenceException pe) {
throw new CustomerException(pe);
} catch (AccountException ae) {
throw new CustomerException(ae);
}
}
}
}
Aggregations