Search in sources :

Example 11 with CalendarEvent

use of org.mifos.calendar.CalendarEvent 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 12 with CalendarEvent

use of org.mifos.calendar.CalendarEvent 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 13 with CalendarEvent

use of org.mifos.calendar.CalendarEvent in project head by mifos.

the class CenterCreationTest method createsCenterWithCustomerAccount.

@Test
public void createsCenterWithCustomerAccount() throws Exception {
    // setup
    OfficeBO withOffice = new OfficeBO(new Short("1"), "testOffice", new Integer("1"), new Short("1"));
    CenterBO center = new CenterBuilder().withLoanOfficer(anyLoanOfficer()).with(withOffice).build();
    center.setCustomerDao(customerDao);
    List<AccountFeesEntity> accountFees = new ArrayList<AccountFeesEntity>();
    // stub
    CalendarEvent upcomingCalendarEvents = new CalendarEventBuilder().build();
    when(holidayDao.findCalendarEventsForThisYearAndNext((short) 1)).thenReturn(upcomingCalendarEvents);
    when(customerAccountFactory.create(center, accountFees, meeting, upcomingCalendarEvents)).thenReturn(customerAccount);
    when(customerAccount.getType()).thenReturn(AccountTypes.CUSTOMER_ACCOUNT);
    // exercise test
    customerService.createCenter(center, meeting, accountFees);
    // verification
    assertThat(center.getCustomerAccount(), is(customerAccount));
}
Also used : OfficeBO(org.mifos.customers.office.business.OfficeBO) ArrayList(java.util.ArrayList) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) CalendarEvent(org.mifos.calendar.CalendarEvent) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) CalendarEventBuilder(org.mifos.domain.builders.CalendarEventBuilder) Test(org.junit.Test)

Example 14 with CalendarEvent

use of org.mifos.calendar.CalendarEvent in project head by mifos.

the class CenterCreationTest method rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs.

@Test(expected = MifosRuntimeException.class)
public void rollsbackTransactionClosesSessionAndThrowsRuntimeExceptionWhenExceptionOccurs() throws Exception {
    // setup
    CenterBO center = new CenterBuilder().withLoanOfficer(anyLoanOfficer()).build();
    List<AccountFeesEntity> accountFees = new ArrayList<AccountFeesEntity>();
    // stub
    CalendarEvent upcomingCalendarEvents = new CalendarEventBuilder().build();
    when(holidayDao.findCalendarEventsForThisYearAndNext((short) 1)).thenReturn(upcomingCalendarEvents);
    when(customerAccountFactory.create(center, accountFees, meeting, upcomingCalendarEvents)).thenReturn(customerAccount);
    when(customerAccount.getType()).thenReturn(AccountTypes.CUSTOMER_ACCOUNT);
    // stub
    doThrow(new RuntimeException()).when(customerDao).save(center);
    // exercise test
    customerService.createCenter(center, meeting, accountFees);
    // verification
    verify(hibernateTransaction).rollbackTransaction();
    verify(hibernateTransaction).closeSession();
}
Also used : MifosRuntimeException(org.mifos.core.MifosRuntimeException) ArrayList(java.util.ArrayList) CenterBO(org.mifos.customers.center.business.CenterBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) CalendarEvent(org.mifos.calendar.CalendarEvent) AccountFeesEntity(org.mifos.accounts.business.AccountFeesEntity) CalendarEventBuilder(org.mifos.domain.builders.CalendarEventBuilder) Test(org.junit.Test)

Example 15 with CalendarEvent

use of org.mifos.calendar.CalendarEvent in project head by mifos.

the class SavingsAccountBuilder method buildJointSavingsAccount.

public SavingsBO buildJointSavingsAccount() {
    CalendarEvent calendarEvents = new CalendarEvent(workingDays, holidays);
    SavingsAccountActivationDetail derivedActivationDetails = SavingsBO.determineAccountActivationDetails(customer, savingsProduct, recommendedAmount, accountState, calendarEvents, jointAccountMembers);
    return buildAccount(derivedActivationDetails);
}
Also used : SavingsAccountActivationDetail(org.mifos.accounts.savings.business.SavingsAccountActivationDetail) CalendarEvent(org.mifos.calendar.CalendarEvent)

Aggregations

CalendarEvent (org.mifos.calendar.CalendarEvent)18 AccountException (org.mifos.accounts.exceptions.AccountException)9 MifosRuntimeException (org.mifos.core.MifosRuntimeException)8 CustomerException (org.mifos.customers.exceptions.CustomerException)8 ArrayList (java.util.ArrayList)7 CustomerBO (org.mifos.customers.business.CustomerBO)7 PersistenceException (org.mifos.framework.exceptions.PersistenceException)7 BusinessRuleException (org.mifos.service.BusinessRuleException)7 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)6 DateTime (org.joda.time.DateTime)5 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)5 ClientBO (org.mifos.customers.client.business.ClientBO)5 LocalDate (org.joda.time.LocalDate)4 Test (org.junit.Test)4 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)4 MeetingBO (org.mifos.application.meeting.business.MeetingBO)4 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)4 CenterBO (org.mifos.customers.center.business.CenterBO)4 CalendarEventBuilder (org.mifos.domain.builders.CalendarEventBuilder)4 CenterBuilder (org.mifos.domain.builders.CenterBuilder)4