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