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();
}
}
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();
}
}
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));
}
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();
}
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);
}
Aggregations