Search in sources :

Example 11 with CustomerException

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();
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) CustomerDto(org.mifos.dto.domain.CustomerDto) CustomerStatusFlagEntity(org.mifos.customers.business.CustomerStatusFlagEntity) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerException(org.mifos.customers.exceptions.CustomerException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountException(org.mifos.accounts.exceptions.AccountException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 12 with CustomerException

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);
            }
        }
    }
}
Also used : CustomerHierarchyEntity(org.mifos.customers.business.CustomerHierarchyEntity) CustomerException(org.mifos.customers.exceptions.CustomerException) SavingsPersistence(org.mifos.accounts.savings.persistence.SavingsPersistence) ClientBO(org.mifos.customers.client.business.ClientBO) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ArrayList(java.util.ArrayList) CalendarEvent(org.mifos.calendar.CalendarEvent) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) ClientInitialSavingsOfferingEntity(org.mifos.customers.client.business.ClientInitialSavingsOfferingEntity) DateTime(org.joda.time.DateTime) AccountException(org.mifos.accounts.exceptions.AccountException) DateMidnight(org.joda.time.DateMidnight) SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 13 with CustomerException

use of org.mifos.customers.exceptions.CustomerException in project head by mifos.

the class CustomerServiceImpl method updateGroupStatus.

@Override
public final void updateGroupStatus(GroupBO group, CustomerStatus oldStatus, CustomerStatus newStatus, CustomerStatusFlag customerStatusFlag, CustomerNoteEntity customerNote) throws CustomerException {
    validateChangeOfStatusForGroup(group, oldStatus, newStatus);
    CustomerStatusFlagEntity customerStatusFlagEntity = populateCustomerStatusFlag(customerStatusFlag);
    try {
        hibernateTransactionHelper.startTransaction();
        hibernateTransactionHelper.beginAuditLoggingFor(group);
        if (group.isActiveForFirstTime(oldStatus.getValue(), newStatus.getValue())) {
            group.setCustomerActivationDate(new DateTime().toDate());
            group.updateCustomerHierarchy();
            CalendarEvent applicableCalendarEvents = this.holidayDao.findCalendarEventsForThisYearAndNext(group.getOfficeId());
            group.regenerateCustomerFeeSchedule(applicableCalendarEvents);
        }
        Set<CustomerBO> groupChildren = group.getChildren();
        if (oldStatus.isGroupPending() && newStatus.isGroupCancelled() && groupChildren != null) {
            for (CustomerBO child : groupChildren) {
                ClientBO client = (ClientBO) child;
                if (client.isPending()) {
                    client.setUserContext(group.getUserContext());
                    hibernateTransactionHelper.beginAuditLoggingFor(client);
                    client.updateCustomerStatus(CustomerStatus.CLIENT_PARTIAL);
                    customerDao.save(client);
                }
            }
        }
        group.updateCustomerStatus(newStatus, customerNote, customerStatusFlagEntity);
        customerDao.save(group);
        hibernateTransactionHelper.commitTransaction();
    } catch (Exception e) {
        this.hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        this.hibernateTransactionHelper.closeSession();
    }
}
Also used : ClientBO(org.mifos.customers.client.business.ClientBO) CustomerStatusFlagEntity(org.mifos.customers.business.CustomerStatusFlagEntity) CalendarEvent(org.mifos.calendar.CalendarEvent) CustomerBO(org.mifos.customers.business.CustomerBO) DateTime(org.joda.time.DateTime) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerException(org.mifos.customers.exceptions.CustomerException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) AccountException(org.mifos.accounts.exceptions.AccountException) MeetingException(org.mifos.application.meeting.exceptions.MeetingException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 14 with CustomerException

use of org.mifos.customers.exceptions.CustomerException in project head by mifos.

the class ClientBO method handleAttendance.

// when this method is called from Bulk Entry preview persist will be false
public void handleAttendance(final Date meetingDate, final Short attendance, final boolean persist) throws CustomerException {
    ClientAttendanceBO clientAttendance = getClientAttendanceForMeeting(meetingDate);
    if (clientAttendance == null) {
        clientAttendance = new ClientAttendanceBO();
        clientAttendance.setMeetingDate(meetingDate);
        addClientAttendance(clientAttendance);
    }
    clientAttendance.setAttendance(attendance);
    if (persist) {
        try {
            getCustomerPersistence().createOrUpdate(this);
        } catch (PersistenceException e) {
            throw new CustomerException(e);
        }
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) PersistenceException(org.mifos.framework.exceptions.PersistenceException)

Example 15 with CustomerException

use of org.mifos.customers.exceptions.CustomerException in project head by mifos.

the class LegacyClientDao method saveClient.

public void saveClient(final ClientBO clientBO) throws CustomerException {
    CustomerPersistence customerPersistence = new CustomerPersistence();
    customerPersistence.saveCustomer(clientBO);
    try {
        if (clientBO.getParentCustomer() != null) {
            customerPersistence.createOrUpdate(clientBO.getParentCustomer());
        }
        // seems fishy... why do savings accounts need updating here?
        new SavingsPersistence().persistSavingAccounts(clientBO);
    } catch (PersistenceException pe) {
        throw new CustomerException(CustomerConstants.CREATE_FAILED_EXCEPTION, pe);
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) SavingsPersistence(org.mifos.accounts.savings.persistence.SavingsPersistence) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence)

Aggregations

CustomerException (org.mifos.customers.exceptions.CustomerException)103 Test (org.junit.Test)52 UserContext (org.mifos.security.util.UserContext)29 ClientBO (org.mifos.customers.client.business.ClientBO)23 GroupBuilder (org.mifos.domain.builders.GroupBuilder)21 PersistenceException (org.mifos.framework.exceptions.PersistenceException)21 BusinessRuleException (org.mifos.service.BusinessRuleException)21 CenterBO (org.mifos.customers.center.business.CenterBO)20 GroupBO (org.mifos.customers.group.business.GroupBO)20 AccountException (org.mifos.accounts.exceptions.AccountException)18 CenterBuilder (org.mifos.domain.builders.CenterBuilder)18 ArrayList (java.util.ArrayList)17 MifosRuntimeException (org.mifos.core.MifosRuntimeException)14 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)13 ClientNameDetailDto (org.mifos.dto.screen.ClientNameDetailDto)13 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)12 MeetingBO (org.mifos.application.meeting.business.MeetingBO)12 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)12 MifosUser (org.mifos.security.MifosUser)11 DateTime (org.joda.time.DateTime)10