Search in sources :

Example 1 with Time

use of org.motechproject.commons.date.model.Time in project motech by motech.

the class CronJobSimpleExpressionBuilderTest method shouldBuildValidCronExpressionWithDayRepeat.

@Test
public void shouldBuildValidCronExpressionWithDayRepeat() {
    String expression = new CronJobSimpleExpressionBuilder(new Time(10, 25)).withRepeatIntervalInDays(7).build();
    assertEquals("0 25 10 */7 * ?", expression);
}
Also used : Time(org.motechproject.commons.date.model.Time) Test(org.junit.Test)

Example 2 with Time

use of org.motechproject.commons.date.model.Time in project motech by motech.

the class TestEventListener method shouldScheduleDayOfWeekJob.

@Test
public void shouldScheduleDayOfWeekJob() throws SchedulerException {
    try {
        fakeNow(newDateTime(2020, 7, 15, 10, 0, 0));
        Map<String, Object> params = new HashMap<>();
        params.put(MotechSchedulerService.JOB_ID_KEY, "job_id");
        schedulerService.scheduleDayOfWeekJob(new DayOfWeekSchedulableJob(new MotechEvent("test_event", params), // friday
        newDateTime(2020, 7, 10), newDateTime(2020, 7, 22), asList(DayOfWeek.Monday, DayOfWeek.Thursday), new Time(10, 10), false));
        List<DateTime> fireTimes = getFireTimes("test_event-job_id");
        assertEquals(asList(newDateTime(2020, 7, 13, 10, 10, 0), newDateTime(2020, 7, 16, 10, 10, 0), newDateTime(2020, 7, 20, 10, 10, 0)), fireTimes);
    } finally {
        stopFakingTime();
    }
}
Also used : HashMap(java.util.HashMap) DayOfWeekSchedulableJob(org.motechproject.scheduler.contract.DayOfWeekSchedulableJob) DateUtil.newDateTime(org.motechproject.commons.date.util.DateUtil.newDateTime) Time(org.motechproject.commons.date.model.Time) DateTime(org.joda.time.DateTime) TimeFaker.stopFakingTime(org.motechproject.testing.utils.TimeFaker.stopFakingTime) MotechEvent(org.motechproject.event.MotechEvent) DateUtil.newDateTime(org.motechproject.commons.date.util.DateUtil.newDateTime) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 3 with Time

use of org.motechproject.commons.date.model.Time in project motech by motech.

the class MotechSchedulerDatabaseServiceImplBundleIT method addTestJobs.

private void addTestJobs() {
    Map<String, Object> params = new HashMap<>();
    params.put(MotechSchedulerService.JOB_ID_KEY, "job_id1");
    // this job should be active
    schedulerService.scheduleDayOfWeekJob(new DayOfWeekSchedulableJob(new MotechEvent("test_event_1", params), new DateTime(CURRENT_YEAR - 1, 3, 10, 0, 0), new DateTime(CURRENT_YEAR + 2, 3, 22, 0, 0), Arrays.asList(DayOfWeek.Monday, DayOfWeek.Thursday), new Time(10, 10), false));
    params = new HashMap<>();
    params.put(MotechSchedulerService.JOB_ID_KEY, "job_id2");
    schedulerService.scheduleDayOfWeekJob(new DayOfWeekSchedulableJob(new MotechEvent("test_event_2", params), new DateTime(CURRENT_YEAR + 1, 7, 10, 0, 0), new DateTime(CURRENT_YEAR + 3, 7, 22, 0, 0), Arrays.asList(DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday), new Time(10, 10), false));
    params = new HashMap<>();
    params.put(MotechSchedulerService.JOB_ID_KEY, "job_id3");
    schedulerService.scheduleDayOfWeekJob(new DayOfWeekSchedulableJob(new MotechEvent("test_event_3", params), new DateTime(CURRENT_YEAR + 4, 7, 10, 0, 0), new DateTime(CURRENT_YEAR + 5, 7, 22, 0, 0), Arrays.asList(DayOfWeek.Monday, DayOfWeek.Thursday), new Time(10, 10), false));
    params = new HashMap<>();
    params.put(MotechSchedulerService.JOB_ID_KEY, "job_id4");
    schedulerService.scheduleJob(new CronSchedulableJob(new MotechEvent("test_event_4", params), "0 0 12 * * ?"));
    params = new HashMap<>();
    params.put(MotechSchedulerService.JOB_ID_KEY, "job_id5");
    schedulerService.scheduleRunOnceJob(new RunOnceSchedulableJob(new MotechEvent("test_event_5", params), newDateTime(CURRENT_YEAR + 6, 7, 15, 12, 0, 0)));
    params = new HashMap<>();
    params.put(MotechSchedulerService.JOB_ID_KEY, "job_id6");
    schedulerService.scheduleRepeatingJob(new RepeatingSchedulableJob(new MotechEvent("test_event_6", params), DateTimeConstants.SECONDS_PER_DAY, newDateTime(CURRENT_YEAR + 4, 7, 15, 12, 0, 0), newDateTime(CURRENT_YEAR + 4, 7, 18, 12, 0, 0), false));
}
Also used : RepeatingSchedulableJob(org.motechproject.scheduler.contract.RepeatingSchedulableJob) CronSchedulableJob(org.motechproject.scheduler.contract.CronSchedulableJob) HashMap(java.util.HashMap) DayOfWeekSchedulableJob(org.motechproject.scheduler.contract.DayOfWeekSchedulableJob) DateUtil.newDateTime(org.motechproject.commons.date.util.DateUtil.newDateTime) Time(org.motechproject.commons.date.model.Time) DateTime(org.joda.time.DateTime) TimeFaker.stopFakingTime(org.motechproject.testing.utils.TimeFaker.stopFakingTime) MotechEvent(org.motechproject.event.MotechEvent) DateUtil.newDateTime(org.motechproject.commons.date.util.DateUtil.newDateTime) DateTime(org.joda.time.DateTime) RunOnceSchedulableJob(org.motechproject.scheduler.contract.RunOnceSchedulableJob)

Example 4 with Time

use of org.motechproject.commons.date.model.Time in project motech by motech.

the class JavassistBuilder method createInitializerForThirdPartyPackages.

private static CtField.Initializer createInitializerForThirdPartyPackages(String typeClass, Object defaultValue) {
    switch(typeClass) {
        case "org.motechproject.commons.date.model.Time":
            Time time = (Time) defaultValue;
            return createSimpleInitializer(typeClass, '"' + time.timeStr() + '"');
        case "org.joda.time.DateTime":
            DateTime dateTime = (DateTime) defaultValue;
            // explicit long
            return createSimpleInitializer(typeClass, dateTime.getMillis() + "l");
        case "org.joda.time.LocalDate":
            LocalDate localDate = (LocalDate) defaultValue;
            String initStr = String.format("%d, %d, %d", localDate.getYear(), localDate.getMonthOfYear(), localDate.getDayOfMonth());
            return createSimpleInitializer(typeClass, initStr);
        default:
            return null;
    }
}
Also used : Time(org.motechproject.commons.date.model.Time) DateTime(org.joda.time.DateTime) LocalDateTime(java.time.LocalDateTime) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) LocalDateTime(java.time.LocalDateTime)

Example 5 with Time

use of org.motechproject.commons.date.model.Time in project motech by motech.

the class MdsBundleIT method verifyCsvImport.

private void verifyCsvImport() throws Exception {
    getLogger().info("Verifying CSV Import");
    CsvImportExportService csvImportExportService = ServiceRetriever.getService(bundleContext, CsvImportExportService.class);
    try (InputStream in = new ClassPathResource("csv/import.csv").getInputStream()) {
        Reader reader = new InputStreamReader(in);
        CsvImportResults results = csvImportExportService.importCsv(FOO_CLASS, reader, "import.csv", false);
        assertNotNull(results);
        assertEquals(2, results.totalNumberOfImportedInstances());
        assertEquals(2, results.newInstanceCount());
        assertEquals(0, results.updatedInstanceCount());
    }
    assertEquals(7, service.count());
    // get the imported instances through a lookup
    QueryParams queryParams = new QueryParams(new Order("someTime", Order.Direction.DESC));
    List list = (List) MethodUtils.invokeExactMethod(service, "matchesOperator", new Object[] { "fromCsv", queryParams });
    assertNotNull(list);
    assertEquals(2, list.size());
    assertInstance(list.get(0), false, "fromCsv2", "Capital CSV", Collections.emptyList(), null, new LocalDate(2012, 10, 14), null, new Period(2, 0, 0, 0, 0, 0, 0, 0), null, new DateTime(2014, 12, 2, 16, 13, 40, 0, DateTimeZone.UTC).toDate(), null, new Time(20, 20), null, null, null, null);
    assertInstance(list.get(1), true, "fromCsv1", "Capital CSV", new ArrayList(asList("one", "two")), new DateTime(2014, 12, 2, 13, 10, 40, 0, DateTimeZone.UTC).withZone(DateTimeZone.getDefault()), new LocalDate(2012, 10, 15), null, new Period(1, 0, 0, 0, 0, 0, 0, 0), null, new DateTime(2014, 12, 2, 13, 13, 40, 0, DateTimeZone.UTC).toDate(), null, new Time(10, 30), null, null, null, null);
}
Also used : Order(org.motechproject.mds.util.Order) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) Period(org.joda.time.Period) Time(org.motechproject.commons.date.model.Time) LocalDateTime(java.time.LocalDateTime) DateTime(org.joda.time.DateTime) LocalDate(org.joda.time.LocalDate) ClassPathResource(org.springframework.core.io.ClassPathResource) LocalDateTime(java.time.LocalDateTime) DateTime(org.joda.time.DateTime) CsvImportResults(org.motechproject.mds.dto.CsvImportResults) CsvImportExportService(org.motechproject.mds.service.CsvImportExportService) QueryParams(org.motechproject.mds.query.QueryParams) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList)

Aggregations

Time (org.motechproject.commons.date.model.Time)16 DateTime (org.joda.time.DateTime)12 Test (org.junit.Test)10 LocalDateTime (java.time.LocalDateTime)6 LocalDate (org.joda.time.LocalDate)6 MotechEvent (org.motechproject.event.MotechEvent)5 Date (java.util.Date)4 DateUtil.newDateTime (org.motechproject.commons.date.util.DateUtil.newDateTime)4 DayOfWeekSchedulableJob (org.motechproject.scheduler.contract.DayOfWeekSchedulableJob)4 ZonedDateTime (java.time.ZonedDateTime)3 ArrayList (java.util.ArrayList)3 Arrays.asList (java.util.Arrays.asList)3 Collections.singletonList (java.util.Collections.singletonList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 TimeFaker.stopFakingTime (org.motechproject.testing.utils.TimeFaker.stopFakingTime)3 DayOfWeek (org.motechproject.commons.date.model.DayOfWeek)2 CronSchedulableJob (org.motechproject.scheduler.contract.CronSchedulableJob)2 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1