Search in sources :

Example 61 with CustomerException

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

the class CustomerServiceImpl method updateCustomerMeetingSchedule.

@Override
public void updateCustomerMeetingSchedule(MeetingBO updatedMeeting, CustomerBO customer) {
    try {
        customer.validateIsTopOfHierarchy();
        customerDao.checkPermissionForEditMeetingSchedule(updatedMeeting.getUserContext(), customer);
        CalendarEvent calendarEvents = holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
        this.hibernateTransactionHelper.startTransaction();
        boolean scheduleUpdateRequired = false;
        CustomerMeetingEntity meetingEntity = customer.getCustomerMeeting();
        if (meetingEntity != null) {
            MeetingBO meeting = customer.getCustomerMeetingValue();
            scheduleUpdateRequired = updateMeeting(meeting, updatedMeeting);
        } else {
            CustomerMeetingEntity newMeetingEntity = customer.createCustomerMeeting(updatedMeeting);
            customer.setCustomerMeeting(newMeetingEntity);
        }
        customerDao.save(customer);
        if (scheduleUpdateRequired) {
            handleChangeInMeetingSchedule(customer, calendarEvents.getWorkingDays(), calendarEvents.getHolidays());
        }
        this.hibernateTransactionHelper.commitTransaction();
    } catch (CustomerException e) {
        this.hibernateTransactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } catch (AccountException e) {
        this.hibernateTransactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    } finally {
        this.hibernateTransactionHelper.closeSession();
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) BusinessRuleException(org.mifos.service.BusinessRuleException) CustomerMeetingEntity(org.mifos.customers.business.CustomerMeetingEntity) AccountException(org.mifos.accounts.exceptions.AccountException) MeetingBO(org.mifos.application.meeting.business.MeetingBO) CalendarEvent(org.mifos.calendar.CalendarEvent)

Example 62 with CustomerException

use of org.mifos.customers.exceptions.CustomerException 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 63 with CustomerException

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

the class CustomerServiceImpl method updateClientPersonalInfo.

@Override
public final void updateClientPersonalInfo(UserContext userContext, ClientPersonalInfoUpdate personalInfo) throws CustomerException {
    ClientBO client = (ClientBO) this.customerDao.findCustomerById(personalInfo.getCustomerId());
    client.validateVersion(personalInfo.getOriginalClientVersionNumber());
    client.updateDetails(userContext);
    LocalDate currentDOB = new LocalDate(client.getDateOfBirth());
    LocalDate newDOB = currentDOB;
    try {
        // updating Date of birth
        // doesn''t sound normal but it can be required in certain cases
        // see http://mifosforge.jira.com/browse/MIFOS-4368
        newDOB = new LocalDate(DateUtils.getDateAsSentFromBrowser(personalInfo.getDateOfBirth()));
    } catch (InvalidDateException e) {
        throw new MifosRuntimeException(e);
    }
    if (!currentDOB.isEqual(newDOB)) {
        customerDao.validateClientForDuplicateNameOrGovtId(personalInfo.getClientDisplayName(), newDOB.toDateMidnight().toDate(), null);
    }
    try {
        hibernateTransactionHelper.startTransaction();
        hibernateTransactionHelper.beginAuditLoggingFor(client);
        client.updatePersonalInfo(personalInfo);
        clientPhotoService.update(personalInfo.getCustomerId().longValue(), personalInfo.getPicture());
        customerDao.save(client);
        hibernateTransactionHelper.commitTransaction();
    } catch (ApplicationException e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new CustomerException(e.getKey(), e);
    } catch (Exception e) {
        hibernateTransactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        hibernateTransactionHelper.commitTransaction();
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) ClientBO(org.mifos.customers.client.business.ClientBO) LocalDate(org.joda.time.LocalDate) 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 64 with CustomerException

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

the class CenterPersistence method saveCenter.

/**
     * @deprecated use {@link CustomerDao#save(org.mifos.customers.business.CustomerBO)}.
     */
@Deprecated
public void saveCenter(CenterBO center) throws CustomerException {
    try {
        createOrUpdate(center);
        center.generateGlobalCustomerNumber();
        createOrUpdate(center);
    } catch (PersistenceException e) {
        throw new CustomerException(CustomerConstants.CREATE_FAILED_EXCEPTION, e);
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) PersistenceException(org.mifos.framework.exceptions.PersistenceException)

Example 65 with CustomerException

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

the class CustomerDaoHibernate method validateCenterNameIsNotTakenForOffice.

@SuppressWarnings("unchecked")
@Override
public void validateCenterNameIsNotTakenForOffice(String displayName, Short officeId) throws CustomerException {
    if (StringUtils.isBlank(displayName)) {
        throw new CustomerException(CustomerConstants.INVALID_NAME, new Object[] { displayName });
    }
    Map<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put(CustomerConstants.DISPLAY_NAME, displayName);
    queryParameters.put(CustomerConstants.OFFICE_ID, officeId);
    List queryResult = this.genericDao.executeNamedQuery("Customer.getCenterCount", queryParameters);
    if (Integer.valueOf(queryResult.get(0).toString()) > 0) {
        throw new CustomerException(CustomerConstants.ERRORS_DUPLICATE_CUSTOMER, new Object[] { displayName });
    }
}
Also used : CustomerException(org.mifos.customers.exceptions.CustomerException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List)

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