Search in sources :

Example 11 with DateTimeService

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));
}
Also used : DateTimeService(org.mifos.framework.util.DateTimeService) SavingsTestHelper(org.mifos.accounts.savings.util.helpers.SavingsTestHelper) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 12 with DateTimeService

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);
}
Also used : MeetingBO(org.mifos.application.meeting.business.MeetingBO) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 13 with DateTimeService

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();
}
Also used : ServiceException(org.mifos.framework.exceptions.ServiceException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Matchers.anyString(org.mockito.Matchers.anyString) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.util.Date) MifosRuntimeException(org.mifos.core.MifosRuntimeException) Test(org.junit.Test)

Example 14 with DateTimeService

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();
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) Matchers.anyString(org.mockito.Matchers.anyString) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.util.Date) Test(org.junit.Test)

Example 15 with DateTimeService

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));
}
Also used : CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) ArrayList(java.util.ArrayList) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) AccountBO(org.mifos.accounts.business.AccountBO) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration) ScheduledDateGeneration(org.mifos.schedule.ScheduledDateGeneration) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) Holiday(org.mifos.application.holiday.business.Holiday) ArrayList(java.util.ArrayList) List(java.util.List) DateTimeService(org.mifos.framework.util.DateTimeService) FiscalCalendarRules(org.mifos.config.FiscalCalendarRules) HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration)

Aggregations

DateTimeService (org.mifos.framework.util.DateTimeService)99 Test (org.junit.Test)24 Date (java.util.Date)21 Money (org.mifos.framework.util.helpers.Money)20 DateTime (org.joda.time.DateTime)19 PersistenceException (org.mifos.framework.exceptions.PersistenceException)19 MeetingBO (org.mifos.application.meeting.business.MeetingBO)16 MifosRuntimeException (org.mifos.core.MifosRuntimeException)16 LocalDate (org.joda.time.LocalDate)15 AccountException (org.mifos.accounts.exceptions.AccountException)14 LoanBO (org.mifos.accounts.loan.business.LoanBO)14 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)14 ArrayList (java.util.ArrayList)13 CustomerBO (org.mifos.customers.business.CustomerBO)10 CustomerException (org.mifos.customers.exceptions.CustomerException)10 UserContext (org.mifos.security.util.UserContext)10 BusinessRuleException (org.mifos.service.BusinessRuleException)9 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)8 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)8 ApplicationException (org.mifos.framework.exceptions.ApplicationException)8