Search in sources :

Example 6 with ITimeRecurrence

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());
}
Also used : QualifiedDayOfWeek(org.pentaho.platform.scheduler2.recur.QualifiedDayOfWeek) ITimeRecurrence(org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) CronJobTrigger(org.pentaho.platform.api.scheduler2.CronJobTrigger) Test(org.junit.Test)

Example 7 with ITimeRecurrence

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());
}
Also used : ITimeRecurrence(org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) RecurrenceList(org.pentaho.platform.scheduler2.recur.RecurrenceList) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) Test(org.junit.Test)

Example 8 with ITimeRecurrence

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());
}
Also used : ITimeRecurrence(org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) RecurrenceList(org.pentaho.platform.scheduler2.recur.RecurrenceList) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) Test(org.junit.Test)

Example 9 with ITimeRecurrence

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;
}
Also used : QualifiedDayOfWeek(org.pentaho.platform.scheduler2.recur.QualifiedDayOfWeek) DayOfWeek(org.pentaho.platform.scheduler2.recur.QualifiedDayOfWeek.DayOfWeek) QualifiedDayOfWeek(org.pentaho.platform.scheduler2.recur.QualifiedDayOfWeek) ITimeRecurrence(org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence) IncrementalRecurrence(org.pentaho.platform.scheduler2.recur.IncrementalRecurrence) RecurrenceList(org.pentaho.platform.scheduler2.recur.RecurrenceList) ArrayList(java.util.ArrayList) SequentialRecurrence(org.pentaho.platform.scheduler2.recur.SequentialRecurrence)

Example 10 with ITimeRecurrence

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());
}
Also used : ITimeRecurrence(org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) RecurrenceList(org.pentaho.platform.scheduler2.recur.RecurrenceList) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) Test(org.junit.Test)

Aggregations

ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)13 Test (org.junit.Test)12 ITimeRecurrence (org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence)10 RecurrenceList (org.pentaho.platform.scheduler2.recur.RecurrenceList)8 IncrementalRecurrence (org.pentaho.platform.scheduler2.recur.IncrementalRecurrence)7 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)6 Calendar (java.util.Calendar)4 Job (org.pentaho.platform.api.scheduler2.Job)4 QualifiedDayOfWeek (org.pentaho.platform.scheduler2.recur.QualifiedDayOfWeek)4 SequentialRecurrence (org.pentaho.platform.scheduler2.recur.SequentialRecurrence)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Serializable (java.io.Serializable)1 Date (java.util.Date)1 CronJobTrigger (org.pentaho.platform.api.scheduler2.CronJobTrigger)1 QualifiedDayOfMonth (org.pentaho.platform.scheduler2.recur.QualifiedDayOfMonth)1 DayOfWeek (org.pentaho.platform.scheduler2.recur.QualifiedDayOfWeek.DayOfWeek)1 ListParamValue (org.pentaho.platform.scheduler2.ws.ListParamValue)1 MapParamValue (org.pentaho.platform.scheduler2.ws.MapParamValue)1 ParamValue (org.pentaho.platform.scheduler2.ws.ParamValue)1