Search in sources :

Example 51 with GroupBO

use of org.mifos.customers.group.business.GroupBO in project head by mifos.

the class CustomerServiceImpl method updateCustomerStatus.

@Override
public final void updateCustomerStatus(UserContext userContext, CustomerStatusUpdate customerStatusUpdate) throws CustomerException {
    CustomerBO customer = this.customerDao.findCustomerById(customerStatusUpdate.getCustomerId());
    customer.validateVersion(customerStatusUpdate.getVersionNum());
    customer.updateDetails(userContext);
    checkPermission(customer, userContext, customerStatusUpdate.getNewStatus(), customerStatusUpdate.getCustomerStatusFlag());
    Short oldStatusId = customer.getCustomerStatus().getId();
    CustomerStatus oldStatus = CustomerStatus.fromInt(oldStatusId);
    PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
    CustomerNoteEntity customerNote = new CustomerNoteEntity(customerStatusUpdate.getNotes(), new Date(), loggedInUser, customer);
    if (customer.isGroup()) {
        GroupBO group = (GroupBO) customer;
        updateGroupStatus(group, oldStatus, customerStatusUpdate.getNewStatus(), customerStatusUpdate.getCustomerStatusFlag(), customerNote);
    } else if (customer.isClient()) {
        ClientBO client = (ClientBO) customer;
        updateClientStatus(client, oldStatus, customerStatusUpdate.getNewStatus(), customerStatusUpdate.getCustomerStatusFlag(), customerNote);
    } else {
        CenterBO center = (CenterBO) customer;
        updateCenterStatus(center, customerStatusUpdate.getNewStatus(), customerStatusUpdate.getCustomerStatusFlag(), customerNote);
    }
}
Also used : CustomerNoteEntity(org.mifos.customers.business.CustomerNoteEntity) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) CustomerStatus(org.mifos.customers.util.helpers.CustomerStatus) ClientBO(org.mifos.customers.client.business.ClientBO) CustomerBO(org.mifos.customers.business.CustomerBO) GroupBO(org.mifos.customers.group.business.GroupBO) CenterBO(org.mifos.customers.center.business.CenterBO) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 52 with GroupBO

use of org.mifos.customers.group.business.GroupBO in project head by mifos.

the class GroupPersistence method findBySystemId.

@SuppressWarnings("unchecked")
public GroupBO findBySystemId(String globalCustNum) throws PersistenceException {
    Map<String, String> queryParameters = new HashMap<String, String>();
    GroupBO group = null;
    queryParameters.put("globalCustNum", globalCustNum);
    List<GroupBO> queryResult = executeNamedQuery(NamedQueryConstants.GET_GROUP_BY_SYSTEMID, queryParameters);
    if (null != queryResult && queryResult.size() > 0) {
        group = queryResult.get(0);
    }
    return group;
}
Also used : HashMap(java.util.HashMap) GroupBO(org.mifos.customers.group.business.GroupBO)

Example 53 with GroupBO

use of org.mifos.customers.group.business.GroupBO 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();
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) ClientBO(org.mifos.customers.client.business.ClientBO) GroupBO(org.mifos.customers.group.business.GroupBO) CustomerBO(org.mifos.customers.business.CustomerBO) CalendarEvent(org.mifos.calendar.CalendarEvent) 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 54 with GroupBO

use of org.mifos.customers.group.business.GroupBO in project head by mifos.

the class CenterServiceFacadeWebTier method initializeGroupStates.

@Override
public void initializeGroupStates(String groupGlobalNum) {
    GroupBO group = this.customerDao.findGroupBySystemId(groupGlobalNum);
    try {
        List<ListElement> savingsStatesList = new ArrayList<ListElement>();
        AccountStateMachines.getInstance().initializeGroupStates();
        List<CustomerStatusEntity> statusList = AccountStateMachines.getInstance().getGroupStatusList(group.getCustomerStatus());
        for (CustomerStatusEntity customerState : statusList) {
            savingsStatesList.add(new ListElement(customerState.getId().intValue(), customerState.getName()));
        }
    } catch (StatesInitializationException e) {
        throw new MifosRuntimeException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) ListElement(org.mifos.dto.screen.ListElement) GroupBO(org.mifos.customers.group.business.GroupBO) StatesInitializationException(org.mifos.framework.exceptions.StatesInitializationException) CustomerStatusEntity(org.mifos.customers.business.CustomerStatusEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 55 with GroupBO

use of org.mifos.customers.group.business.GroupBO in project head by mifos.

the class GroupCustAction method manage.

@TransactionDemarcate(joinToken = true)
public ActionForward manage(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    GroupCustActionForm actionForm = (GroupCustActionForm) form;
    actionForm.cleanForm();
    // FIXME - store group identifier (id, globalCustNum) instead of entire business object
    GroupBO group = (GroupBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
    group = this.customerDao.findGroupBySystemId(group.getGlobalCustNum());
    logger.debug("Entering GroupCustAction manage method and customer id: " + group.getGlobalCustNum());
    CenterDto groupDto = this.groupServiceFacade.retrieveGroupDetailsForUpdate(group.getGlobalCustNum());
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, group, request);
    SessionUtils.setCollectionAttribute(CustomerConstants.LOAN_OFFICER_LIST, groupDto.getActiveLoanOfficersForBranch(), request);
    SessionUtils.setAttribute(GroupConstants.CENTER_HIERARCHY_EXIST, groupDto.isCenterHierarchyExists(), request);
    SessionUtils.setCollectionAttribute(CustomerConstants.CUSTOM_FIELDS_LIST, new ArrayList<CustomFieldDto>(), request);
    SessionUtils.setCollectionAttribute(CustomerConstants.POSITIONS, groupDto.getCustomerPositionViews(), request);
    SessionUtils.setCollectionAttribute(CustomerConstants.CLIENT_LIST, groupDto.getClientList(), request);
    actionForm.setLoanOfficerId(String.valueOf(group.getLoanOfficerId()));
    actionForm.setDisplayName(group.getDisplayName());
    actionForm.setCustomerId(group.getCustomerId().toString());
    actionForm.setGlobalCustNum(group.getGlobalCustNum());
    actionForm.setExternalId(group.getExternalId());
    actionForm.setAddress(group.getAddress());
    actionForm.setCustomerPositions(groupDto.getCustomerPositionViews());
    actionForm.setCustomFields(new ArrayList<CustomFieldDto>());
    if (group.isTrained()) {
        actionForm.setTrained(GroupConstants.TRAINED);
    } else {
        actionForm.setTrained(GroupConstants.NOT_TRAINED);
    }
    if (group.getTrainedDate() != null) {
        actionForm.setTrainedDate(DateUtils.getUserLocaleDate(getUserContext(request).getPreferredLocale(), group.getTrainedDate().toString()));
    }
    logger.debug("Exiting GroupCustAction manage method ");
    return mapping.findForward(ActionForwards.manage_success.toString());
}
Also used : CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) GroupBO(org.mifos.customers.group.business.GroupBO) CenterDto(org.mifos.dto.domain.CenterDto) GroupCustActionForm(org.mifos.customers.group.struts.actionforms.GroupCustActionForm) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

GroupBO (org.mifos.customers.group.business.GroupBO)84 Test (org.junit.Test)56 CenterBO (org.mifos.customers.center.business.CenterBO)45 GroupBuilder (org.mifos.domain.builders.GroupBuilder)42 CenterBuilder (org.mifos.domain.builders.CenterBuilder)36 CustomerException (org.mifos.customers.exceptions.CustomerException)23 ClientBO (org.mifos.customers.client.business.ClientBO)22 ArrayList (java.util.ArrayList)16 OfficeBO (org.mifos.customers.office.business.OfficeBO)16 MeetingBO (org.mifos.application.meeting.business.MeetingBO)15 ClientBuilder (org.mifos.domain.builders.ClientBuilder)15 DateTime (org.joda.time.DateTime)14 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)12 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)11 CustomerAccountBO (org.mifos.customers.business.CustomerAccountBO)11 UserContext (org.mifos.security.util.UserContext)11 LocalDate (org.joda.time.LocalDate)10 MifosRuntimeException (org.mifos.core.MifosRuntimeException)10 ApplicationException (org.mifos.framework.exceptions.ApplicationException)10 Date (java.util.Date)9