use of org.mifos.framework.util.DateTimeService in project head by mifos.
the class LegacyAccountDaoIntegrationTest method testGetActiveCustomerAndSavingsAccountIdsForGenerateMeetingTaskShouldReturnThreeCustomerAccountsAndOneSavingsAccount.
@Test
public void testGetActiveCustomerAndSavingsAccountIdsForGenerateMeetingTaskShouldReturnThreeCustomerAccountsAndOneSavingsAccount() throws Exception {
// Superclass creates a center, a group, and a client that start meeting today
// They should have 10 current or future meeting dates
// Set time ahead 7 weeks to force regenerating customer schedules.
savingsBO = new SavingsTestHelper().createSavingsAccount(createSavingsOffering("qqqqq"), group, AccountState.SAVINGS_ACTIVE, TestUtils.makeUser());
new DateTimeService().setCurrentDateTime(new DateTime().plusWeeks(7));
List<Integer> accountIds = legacyAccountDao.getActiveCustomerAndSavingsAccountIdsForGenerateMeetingTask();
assertThat(accountIds.size(), is(4));
assertThat(accountIds.contains(center.getCustomerAccount().getAccountId()), is(true));
assertThat(accountIds.contains(group.getCustomerAccount().getAccountId()), is(true));
assertThat(accountIds.contains(client.getCustomerAccount().getAccountId()), is(true));
assertThat(accountIds.contains(savingsBO.getAccountId()), is(true));
}
use of org.mifos.framework.util.DateTimeService in project head by mifos.
the class SavingsTestHelper method createSavingsOffering.
public SavingsOfferingBO createSavingsOffering(String offeringName, InterestCalcType interestCalcType, SavingsType savingsType) {
MeetingBO meetingIntCalc = TestObjectFactory.createMeeting(TestObjectFactory.getTypicalMeeting());
MeetingBO meetingIntPost = TestObjectFactory.createMeeting(TestObjectFactory.getTypicalMeeting());
return TestObjectFactory.createSavingsProduct(offeringName, ApplicableTo.GROUPS, new DateTimeService().getCurrentJavaDateTime(), PrdStatus.SAVINGS_ACTIVE, 300.0, RecommendedAmountUnit.PER_INDIVIDUAL, 24.0, 200.0, 200.0, savingsType, interestCalcType, meetingIntCalc, meetingIntPost);
}
use of org.mifos.framework.util.DateTimeService in project head by mifos.
the class WebTierAccountServiceFacadeTest method shouldNotAdjustBackdatedPaymentMadeOnAccountIfNotAllowed.
@Test
public void shouldNotAdjustBackdatedPaymentMadeOnAccountIfNotAllowed() throws ServiceException, AccountException, PersistenceException {
String globalAccountNum = "123";
String adjustmentNote = "note";
Short personnelId = Short.valueOf("1");
PersonnelBO personnelBO = mock(PersonnelBO.class);
Date paymentDate = TestUtils.getDate(10, 10, 2010);
new DateTimeService().setCurrentDateTime(TestUtils.getDateTime(11, 10, 2010));
AccountPaymentEntity lastPmntToBeAdjusted = mock(AccountPaymentEntity.class);
Short recordOfficeId = new Short("1");
Short recordLoanOfficer = new Short("1");
PersonnelBO loanOfficer = mock(PersonnelBO.class);
when(loanBO.getPersonnel()).thenReturn(loanOfficer);
when(loanBO.getUserContext()).thenReturn(userContext);
when(loanOfficer.getPersonnelId()).thenReturn(recordOfficeId);
when(loanBO.getOfficeId()).thenReturn(recordOfficeId);
when(loanBO.getLastPmntToBeAdjusted()).thenReturn(lastPmntToBeAdjusted);
when(lastPmntToBeAdjusted.getPaymentDate()).thenReturn(paymentDate);
when(accountBusinessService.findBySystemId(globalAccountNum)).thenReturn(loanBO);
when(personnelPersistence.findPersonnelById(personnelId)).thenReturn(personnelBO);
doThrow(new ServiceException(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED)).when(accountBusinessService).checkPermissionForAdjustmentOnBackDatedPayments(paymentDate, userContext, recordOfficeId, recordLoanOfficer);
try {
accountServiceFacade.applyAdjustment(globalAccountNum, adjustmentNote, personnelId);
} catch (MifosRuntimeException e) {
assertThat((ServiceException) e.getCause(), CoreMatchers.any(ServiceException.class));
assertThat(((ServiceException) e.getCause()).getKey(), is(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED));
}
verify(accountBusinessService, atLeastOnce()).findBySystemId(globalAccountNum);
verify(lastPmntToBeAdjusted).getPaymentDate();
verify(accountBusinessService).checkPermissionForAdjustmentOnBackDatedPayments(paymentDate, userContext, recordOfficeId, recordLoanOfficer);
verify(personnelPersistence, never()).findPersonnelById(personnelId);
verify(loanBO, never()).adjustLastPayment(anyString(), Matchers.<PersonnelBO>anyObject());
verify(legacyAccountDao, never()).createOrUpdate(loanBO);
verify(loanBO).setUserContext(userContext);
verify(transactionHelper, never()).startTransaction();
verify(transactionHelper, never()).commitTransaction();
verify(transactionHelper).rollbackTransaction();
}
use of org.mifos.framework.util.DateTimeService in project head by mifos.
the class WebTierAccountServiceFacadeTest method shouldAdjustBackdatedPaymentMadeOnAccountIfAllowed.
@Test
public void shouldAdjustBackdatedPaymentMadeOnAccountIfAllowed() throws ServiceException, AccountException, PersistenceException {
String globalAccountNum = "123";
String adjustmentNote = "note";
Short personnelId = Short.valueOf("1");
PersonnelBO personnelBO = mock(PersonnelBO.class);
PersonnelBO loanOfficer = mock(PersonnelBO.class);
Date paymentDate = TestUtils.getDate(10, 10, 2010);
new DateTimeService().setCurrentDateTime(TestUtils.getDateTime(11, 10, 2010));
Short recordOfficeId = new Short("1");
Short recordLoanOfficer = new Short("1");
Integer paymentId = 1;
AccountPaymentEntity lastPmntToBeAdjusted = mock(AccountPaymentEntity.class);
when(loanBO.getLastPmntToBeAdjusted()).thenReturn(lastPmntToBeAdjusted);
when(loanBO.getOfficeId()).thenReturn(recordOfficeId);
when(loanBO.getPersonnel()).thenReturn(loanOfficer);
when(loanBO.getUserContext()).thenReturn(userContext);
when(loanBO.findPaymentById(paymentId)).thenReturn(lastPmntToBeAdjusted);
when(loanOfficer.getPersonnelId()).thenReturn(recordOfficeId);
when(lastPmntToBeAdjusted.getPaymentDate()).thenReturn(paymentDate);
when(lastPmntToBeAdjusted.getPaymentId()).thenReturn(paymentId);
when(accountBusinessService.findBySystemId(globalAccountNum)).thenReturn(loanBO);
when(personnelPersistence.findPersonnelById(personnelId)).thenReturn(personnelBO);
accountServiceFacade.applyAdjustment(globalAccountNum, adjustmentNote, personnelId);
verify(accountBusinessService, atLeastOnce()).findBySystemId(globalAccountNum);
verify(personnelPersistence).findPersonnelById(personnelId);
verify(loanBO).adjustLastPayment(adjustmentNote, personnelBO);
verify(loanBO, atLeastOnce()).setUserContext(userContext);
verify(legacyAccountDao).createOrUpdate(loanBO);
verify(transactionHelper).startTransaction();
verify(transactionHelper).commitTransaction();
verify(accountBusinessService).checkPermissionForAdjustmentOnBackDatedPayments(paymentDate, userContext, recordOfficeId, recordLoanOfficer);
verify(lastPmntToBeAdjusted, times(2)).getPaymentDate();
}
use of org.mifos.framework.util.DateTimeService in project head by mifos.
the class GenerateMeetingsForCustomerAndSavingsHelper method execute.
@Override
public void execute(@SuppressWarnings("unused") final long timeInMillis) throws BatchJobException {
workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
officeCurrentAndFutureHolidays = new HashMap<Short, List<Holiday>>();
long taskStartTime = new DateTimeService().getCurrentDateTime().getMillis();
List<Integer> customerAndSavingsAccountIds = findActiveCustomerAndSavingsAccountIdsThatRequiredMeetingsToBeGenerated();
int accountCount = customerAndSavingsAccountIds.size();
if (accountCount == 0) {
return;
}
List<String> errorList = new ArrayList<String>();
int currentRecordNumber = 0;
int outputIntervalForBatchJobs = GeneralConfig.getOutputIntervalForBatchJobs();
int batchSize = GeneralConfig.getBatchSizeForBatchJobs();
// jpw - hardcoded recordCommittingSize to 500 because now only accounts that need more schedules are returned
int recordCommittingSize = 500;
infoLogBatchParameters(accountCount, outputIntervalForBatchJobs, batchSize, recordCommittingSize);
long startTime = new DateTimeService().getCurrentDateTime().getMillis();
Integer currentAccountId = null;
int updatedRecordCount = 0;
try {
StaticHibernateUtil.getSessionTL();
StaticHibernateUtil.startTransaction();
for (Integer accountId : customerAndSavingsAccountIds) {
currentRecordNumber++;
currentAccountId = accountId;
AccountBO accountBO = legacyAccountDao.getAccount(accountId);
List<Holiday> currentAndFutureHolidays = getOfficeCurrentAndFutureHolidays(accountBO.getOffice().getOfficeId());
ScheduledDateGeneration scheduleGenerationStrategy = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, currentAndFutureHolidays);
if (accountBO instanceof CustomerAccountBO) {
((CustomerAccountBO) accountBO).generateNextSetOfMeetingDates(scheduleGenerationStrategy);
updatedRecordCount++;
} else if (accountBO instanceof SavingsBO) {
((SavingsBO) accountBO).generateNextSetOfMeetingDates(workingDays, currentAndFutureHolidays);
updatedRecordCount++;
}
if (currentRecordNumber % batchSize == 0) {
StaticHibernateUtil.flushAndClearSession();
getLogger().debug("completed HibernateUtil.flushAndClearSession()");
}
if (updatedRecordCount > 0) {
if (updatedRecordCount % recordCommittingSize == 0) {
StaticHibernateUtil.commitTransaction();
StaticHibernateUtil.getSessionTL();
StaticHibernateUtil.startTransaction();
}
}
if (currentRecordNumber % outputIntervalForBatchJobs == 0) {
long time = System.currentTimeMillis();
String message = "" + currentRecordNumber + " processed, " + (accountCount - currentRecordNumber) + " remaining, " + updatedRecordCount + " updated, batch time: " + (time - startTime) + " ms";
logMessage(message);
startTime = time;
}
}
StaticHibernateUtil.commitTransaction();
long time = System.currentTimeMillis();
String message = "" + currentRecordNumber + " processed, " + (accountCount - currentRecordNumber) + " remaining, " + updatedRecordCount + " updated, batch time: " + (time - startTime) + " ms";
logMessage(message);
} catch (Exception e) {
logMessage("account " + currentAccountId.intValue() + " exception " + e.getMessage());
StaticHibernateUtil.rollbackTransaction();
errorList.add(currentAccountId.toString());
getLogger().error("Unable to generate schedules for account with ID " + currentAccountId, e);
} finally {
StaticHibernateUtil.closeSession();
}
if (errorList.size() > 0) {
throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
}
logMessage("GenerateMeetingsForCustomerAndSavings ran in " + (new DateTimeService().getCurrentDateTime().getMillis() - taskStartTime));
}
Aggregations