Search in sources :

Example 1 with CustomerStatusFlagEntity

use of org.mifos.customers.business.CustomerStatusFlagEntity 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();
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) 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 2 with CustomerStatusFlagEntity

use of org.mifos.customers.business.CustomerStatusFlagEntity 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 3 with CustomerStatusFlagEntity

use of org.mifos.customers.business.CustomerStatusFlagEntity 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 4 with CustomerStatusFlagEntity

use of org.mifos.customers.business.CustomerStatusFlagEntity in project head by mifos.

the class ApplicationConfigurationDaoHibernate method findAllCustomerStatuses.

@SuppressWarnings("unchecked")
@Override
public List<CustomerStatusEntity> findAllCustomerStatuses() {
    Map<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put("LEVEL_ID", CustomerLevel.CLIENT.getValue());
    List<CustomerStatusEntity> queryResult = (List<CustomerStatusEntity>) this.genericDao.executeNamedQuery(NamedQueryConstants.GET_CUSTOMER_STATUS_LIST, queryParameters);
    for (CustomerStatusEntity customerStatus : queryResult) {
        for (CustomerStatusFlagEntity customerStatusFlagEntity : customerStatus.getFlagSet()) {
            Hibernate.initialize(customerStatusFlagEntity);
            Hibernate.initialize(customerStatusFlagEntity.getNames());
        }
        Hibernate.initialize(customerStatus.getLookUpValue());
    }
    return queryResult;
}
Also used : HashMap(java.util.HashMap) CustomerStatusFlagEntity(org.mifos.customers.business.CustomerStatusFlagEntity) ArrayList(java.util.ArrayList) List(java.util.List) CustomerStatusEntity(org.mifos.customers.business.CustomerStatusEntity)

Example 5 with CustomerStatusFlagEntity

use of org.mifos.customers.business.CustomerStatusFlagEntity in project head by mifos.

the class EditCustomerStatusAction method loadStatus.

@TransactionDemarcate(joinToken = true)
public ActionForward loadStatus(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    logger.debug("In EditCustomerStatusAction:load()");
    EditCustomerStatusActionForm editCustomerStatusActionForm = (EditCustomerStatusActionForm) form;
    editCustomerStatusActionForm.clear();
    UserContext userContext = getUserContext(request);
    Integer customerId = editCustomerStatusActionForm.getCustomerIdValue();
    CustomerBO customer = this.customerDao.findCustomerById(customerId);
    customer.setUserContext(userContext);
    SessionUtils.removeAttribute(Constants.BUSINESS_KEY, request);
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, customer, request);
    List<CustomerStatusEntity> statusList = new ArrayList<CustomerStatusEntity>();
    switch(customer.getLevel()) {
        case CENTER:
            this.centerServiceFacade.initializeCenterStates(customer.getGlobalCustNum());
            statusList = AccountStateMachines.getInstance().getCenterStatusList(customer.getCustomerStatus());
            editCustomerStatusActionForm.setInput("center");
            break;
        case GROUP:
            this.centerServiceFacade.initializeGroupStates(customer.getGlobalCustNum());
            statusList = AccountStateMachines.getInstance().getGroupStatusList(customer.getCustomerStatus());
            editCustomerStatusActionForm.setInput("group");
            break;
        case CLIENT:
            this.centerServiceFacade.initializeClientStates(customer.getGlobalCustNum());
            statusList = AccountStateMachines.getInstance().getClientStatusList(customer.getCustomerStatus());
            editCustomerStatusActionForm.setInput("client");
            break;
        default:
            break;
    }
    ;
    for (CustomerStatusEntity customerStatusEntity : statusList) {
        for (CustomerStatusFlagEntity flag : customerStatusEntity.getFlagSet()) {
            String statusMessageText = ApplicationContextProvider.getBean(MessageLookup.class).lookup(flag.getLookUpValue().getPropertiesKey());
            flag.setStatusFlagMessageText(statusMessageText);
        }
    }
    editCustomerStatusActionForm.setLevelId(customer.getCustomerLevel().getId().toString());
    editCustomerStatusActionForm.setCurrentStatusId(customer.getCustomerStatus().getId().toString());
    editCustomerStatusActionForm.setGlobalAccountNum(customer.getGlobalCustNum());
    editCustomerStatusActionForm.setCustomerName(customer.getDisplayName());
    SessionUtils.setCollectionAttribute(SavingsConstants.STATUS_LIST, statusList, request);
    return mapping.findForward(ActionForwards.loadStatus_success.toString());
}
Also used : EditCustomerStatusActionForm(org.mifos.customers.struts.actionforms.EditCustomerStatusActionForm) UserContext(org.mifos.security.util.UserContext) MessageLookup(org.mifos.application.master.MessageLookup) ArrayList(java.util.ArrayList) CustomerBO(org.mifos.customers.business.CustomerBO) CustomerStatusFlagEntity(org.mifos.customers.business.CustomerStatusFlagEntity) CustomerStatusEntity(org.mifos.customers.business.CustomerStatusEntity) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

CustomerStatusFlagEntity (org.mifos.customers.business.CustomerStatusFlagEntity)6 AccountException (org.mifos.accounts.exceptions.AccountException)3 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)3 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)3 MifosRuntimeException (org.mifos.core.MifosRuntimeException)3 CustomerStatusEntity (org.mifos.customers.business.CustomerStatusEntity)3 CustomerException (org.mifos.customers.exceptions.CustomerException)3 ApplicationException (org.mifos.framework.exceptions.ApplicationException)3 PersistenceException (org.mifos.framework.exceptions.PersistenceException)3 BusinessRuleException (org.mifos.service.BusinessRuleException)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 CustomerBO (org.mifos.customers.business.CustomerBO)2 List (java.util.List)1 DateTime (org.joda.time.DateTime)1 MessageLookup (org.mifos.application.master.MessageLookup)1 CalendarEvent (org.mifos.calendar.CalendarEvent)1 ClientBO (org.mifos.customers.client.business.ClientBO)1 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)1 EditCustomerStatusActionForm (org.mifos.customers.struts.actionforms.EditCustomerStatusActionForm)1