use of org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence in project pentaho-platform by pentaho.
the class SchedulerResourceUtilTest method testConvertScheduleRequestToJobTrigger_CronString.
@Test
public void testConvertScheduleRequestToJobTrigger_CronString() throws Exception {
cron = new CronJobTrigger();
cron.setCronString("0 45 16 ? * 2#4,2L,6#4,6L *");
cron.setDuration(200000);
cron.setStartTime(now);
cron.setUiPassParam("param");
cron.setEndTime(now);
when(scheduleRequest.getCronJobTrigger()).thenReturn(cron);
IJobTrigger trigger = SchedulerResourceUtil.convertScheduleRequestToJobTrigger(scheduleRequest, scheduler);
assertTrue(trigger instanceof ComplexJobTrigger);
ComplexJobTrigger trig = (ComplexJobTrigger) trigger;
assertEquals(now, trig.getStartTime());
assertEquals(now, trig.getEndTime());
assertEquals(200000, trig.getDuration());
assertEquals("param", trig.getUiPassParam());
List<ITimeRecurrence> recurrences = trig.getDayOfWeekRecurrences().getRecurrences();
assertEquals(4, recurrences.size());
QualifiedDayOfWeek rec = (QualifiedDayOfWeek) recurrences.get(0);
assertEquals("MON", rec.getDayOfWeek().toString());
assertEquals("FOURTH", rec.getQualifier().toString());
rec = (QualifiedDayOfWeek) recurrences.get(1);
assertEquals("MON", rec.getDayOfWeek().toString());
assertEquals("LAST", rec.getQualifier().toString());
rec = (QualifiedDayOfWeek) recurrences.get(2);
assertEquals("FRI", rec.getDayOfWeek().toString());
assertEquals("FOURTH", rec.getQualifier().toString());
rec = (QualifiedDayOfWeek) recurrences.get(3);
assertEquals("FRI", rec.getDayOfWeek().toString());
assertEquals("LAST", rec.getQualifier().toString());
}
use of org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence in project pentaho-platform by pentaho.
the class SchedulerResourceUtilTest method testConvertScheduleRequestToJobTrigger_ComplexJobTrigger_daysOfWeek.
@Test
public void testConvertScheduleRequestToJobTrigger_ComplexJobTrigger_daysOfWeek() throws Exception {
complex.setDaysOfWeek(new int[] { 1, 5 });
when(scheduleRequest.getComplexJobTrigger()).thenReturn(complex);
IJobTrigger trigger = SchedulerResourceUtil.convertScheduleRequestToJobTrigger(scheduleRequest, scheduler);
assertNotNull(trigger);
assertTrue(trigger instanceof ComplexJobTrigger);
ComplexJobTrigger trig = (ComplexJobTrigger) trigger;
List<ITimeRecurrence> recurrences = trig.getDayOfWeekRecurrences().getRecurrences();
assertEquals(2, recurrences.size());
RecurrenceList rec = (RecurrenceList) recurrences.get(0);
assertEquals(2, rec.getValues().get(0).intValue());
rec = (RecurrenceList) recurrences.get(1);
assertEquals(6, rec.getValues().get(0).intValue());
}
use of org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence in project pentaho-platform by pentaho.
the class SchedulerResourceUtilTest method testConvertScheduleRequestToJobTrigger_ComplexJobTrigger_monthsOfYear.
@Test
public void testConvertScheduleRequestToJobTrigger_ComplexJobTrigger_monthsOfYear() throws Exception {
complex.setMonthsOfYear(new int[] { 1, 8 });
when(scheduleRequest.getComplexJobTrigger()).thenReturn(complex);
IJobTrigger trigger = SchedulerResourceUtil.convertScheduleRequestToJobTrigger(scheduleRequest, scheduler);
assertNotNull(trigger);
assertTrue(trigger instanceof ComplexJobTrigger);
ComplexJobTrigger trig = (ComplexJobTrigger) trigger;
List<ITimeRecurrence> recurrences = trig.getMonthlyRecurrences().getRecurrences();
assertEquals(2, recurrences.size());
RecurrenceList rec = (RecurrenceList) recurrences.get(0);
assertEquals(2, rec.getValues().get(0).intValue());
rec = (RecurrenceList) recurrences.get(1);
assertEquals(9, rec.getValues().get(0).intValue());
}
use of org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence in project pentaho-platform by pentaho.
the class QuartzScheduler method parseDayOfWeekRecurrences.
private static List<ITimeRecurrence> parseDayOfWeekRecurrences(String cronExpression) {
List<ITimeRecurrence> dayOfWeekRecurrence = new ArrayList<ITimeRecurrence>();
// $NON-NLS-1$
String delims = "[ ]+";
String[] tokens = cronExpression.split(delims);
if (tokens.length >= 6) {
String dayOfWeekTokens = tokens[5];
// $NON-NLS-1$
tokens = dayOfWeekTokens.split(",");
if ((tokens.length > 1) || !(tokens[0].equals("*") || tokens[0].equals("?"))) {
// $NON-NLS-1$ //$NON-NLS-2$
RecurrenceList dayOfWeekList = null;
for (String token : tokens) {
if (listPattern.matcher(token).matches()) {
if (dayOfWeekList == null) {
dayOfWeekList = new RecurrenceList();
}
dayOfWeekList.getValues().add(Integer.parseInt(token));
} else {
if (dayOfWeekList != null) {
dayOfWeekRecurrence.add(dayOfWeekList);
dayOfWeekList = null;
}
if (sequencePattern.matcher(token).matches()) {
// $NON-NLS-1$
String[] days = token.split("-");
dayOfWeekRecurrence.add(new SequentialRecurrence(Integer.parseInt(days[0]), Integer.parseInt(days[1])));
} else if (intervalPattern.matcher(token).matches()) {
// $NON-NLS-1$
String[] days = token.split("/");
dayOfWeekRecurrence.add(new IncrementalRecurrence(Integer.parseInt(days[0]), Integer.parseInt(days[1])));
} else if (qualifiedDayPattern.matcher(token).matches()) {
// $NON-NLS-1$
String[] days = token.split("#");
dayOfWeekRecurrence.add(new QualifiedDayOfWeek(Integer.parseInt(days[1]), Integer.parseInt(days[0])));
} else if (lastDayPattern.matcher(token).matches()) {
DayOfWeek dayOfWeek = DayOfWeek.values()[(Integer.parseInt(token.substring(0, token.length() - 1)) - 1) % 7];
dayOfWeekRecurrence.add(new QualifiedDayOfWeek(DayOfWeekQualifier.LAST, dayOfWeek));
} else if (dayOfWeekRangePattern.matcher(token).matches()) {
// $NON-NLS-1$
String[] days = token.split("-");
int start = DayOfWeek.valueOf(days[0]).ordinal();
int finish = DayOfWeek.valueOf(days[1]).ordinal();
dayOfWeekRecurrence.add(new SequentialRecurrence(start, finish));
} else {
dayOfWeekList = new RecurrenceList();
dayOfWeekList.getValues().add(DayOfWeek.valueOf(token).ordinal());
dayOfWeekRecurrence.add(dayOfWeekList);
dayOfWeekList = null;
// } else {
// throw new IllegalArgumentException(Messages.getInstance().getErrorString(
// "ComplexJobTrigger.ERROR_0001_InvalidCronExpression")); //$NON-NLS-1$
}
}
}
if (dayOfWeekList != null) {
dayOfWeekRecurrence.add(dayOfWeekList);
}
}
} else {
throw new IllegalArgumentException(Messages.getInstance().getErrorString(// $NON-NLS-1$
"ComplexJobTrigger.ERROR_0001_InvalidCronExpression"));
}
return dayOfWeekRecurrence;
}
use of org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence in project pentaho-platform by pentaho.
the class SchedulerResourceUtilTest method testConvertScheduleRequestToJobTrigger_ComplexJobTrigger_years.
@Test
public void testConvertScheduleRequestToJobTrigger_ComplexJobTrigger_years() throws Exception {
complex.setYears(new int[] { 2016, 2020 });
when(scheduleRequest.getComplexJobTrigger()).thenReturn(complex);
IJobTrigger trigger = SchedulerResourceUtil.convertScheduleRequestToJobTrigger(scheduleRequest, scheduler);
assertNotNull(trigger);
assertTrue(trigger instanceof ComplexJobTrigger);
ComplexJobTrigger trig = (ComplexJobTrigger) trigger;
List<ITimeRecurrence> recurrences = trig.getYearlyRecurrences().getRecurrences();
assertEquals(2, recurrences.size());
RecurrenceList rec = (RecurrenceList) recurrences.get(0);
assertEquals(2016, rec.getValues().get(0).intValue());
rec = (RecurrenceList) recurrences.get(1);
assertEquals(2020, rec.getValues().get(0).intValue());
}
Aggregations