Search in sources :

Example 1 with QualifiedDayOfMonth

use of org.pentaho.platform.scheduler2.recur.QualifiedDayOfMonth in project pentaho-platform by pentaho.

the class QuartzScheduler method parseRecurrence.

private static List<ITimeRecurrence> parseRecurrence(String cronExpression, int tokenIndex) {
    List<ITimeRecurrence> timeRecurrence = new ArrayList<ITimeRecurrence>();
    // $NON-NLS-1$
    String delims = "[ ]+";
    String[] tokens = cronExpression.split(delims);
    if (tokens.length > tokenIndex) {
        String timeTokens = tokens[tokenIndex];
        // $NON-NLS-1$
        tokens = timeTokens.split(",");
        if ((tokens.length > 1) || !(tokens[0].equals("*") || tokens[0].equals("?"))) {
            // $NON-NLS-1$ //$NON-NLS-2$
            RecurrenceList timeList = null;
            for (String token : tokens) {
                if (listPattern.matcher(token).matches()) {
                    if (timeList == null) {
                        timeList = new RecurrenceList();
                    }
                    timeList.getValues().add(Integer.parseInt(token));
                } else {
                    if (timeList != null) {
                        timeRecurrence.add(timeList);
                        timeList = null;
                    }
                    if (sequencePattern.matcher(token).matches()) {
                        // $NON-NLS-1$
                        String[] days = token.split("-");
                        timeRecurrence.add(new SequentialRecurrence(Integer.parseInt(days[0]), Integer.parseInt(days[1])));
                    } else if (intervalPattern.matcher(token).matches()) {
                        // $NON-NLS-1$
                        String[] days = token.split("/");
                        timeRecurrence.add(new IncrementalRecurrence(Integer.parseInt(days[0]), Integer.parseInt(days[1])));
                    } else if ("L".equalsIgnoreCase(token)) {
                        timeRecurrence.add(new QualifiedDayOfMonth());
                    } else {
                        throw new IllegalArgumentException(Messages.getInstance().getErrorString(// $NON-NLS-1$
                        "ComplexJobTrigger.ERROR_0001_InvalidCronExpression"));
                    }
                }
            }
            if (timeList != null) {
                timeRecurrence.add(timeList);
            }
        }
    } else {
        throw new IllegalArgumentException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "ComplexJobTrigger.ERROR_0001_InvalidCronExpression"));
    }
    return timeRecurrence;
}
Also used : ITimeRecurrence(org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence) QualifiedDayOfMonth(org.pentaho.platform.scheduler2.recur.QualifiedDayOfMonth) 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)

Aggregations

ArrayList (java.util.ArrayList)1 ITimeRecurrence (org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence)1 IncrementalRecurrence (org.pentaho.platform.scheduler2.recur.IncrementalRecurrence)1 QualifiedDayOfMonth (org.pentaho.platform.scheduler2.recur.QualifiedDayOfMonth)1 RecurrenceList (org.pentaho.platform.scheduler2.recur.RecurrenceList)1 SequentialRecurrence (org.pentaho.platform.scheduler2.recur.SequentialRecurrence)1