use of org.pentaho.platform.scheduler2.recur.QualifiedDayOfWeek.DayOfWeek 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.scheduler2.recur.QualifiedDayOfWeek.DayOfWeek in project pentaho-platform by pentaho.
the class SchedulerResourceUtil method convertScheduleRequestToJobTrigger.
public static IJobTrigger convertScheduleRequestToJobTrigger(JobScheduleRequest scheduleRequest, IScheduler scheduler) throws SchedulerException, UnifiedRepositoryException {
// Used to determine if created by a RunInBackgroundCommand
boolean runInBackground = scheduleRequest.getSimpleJobTrigger() == null && scheduleRequest.getComplexJobTrigger() == null && scheduleRequest.getCronJobTrigger() == null;
// add 10 seconds to the RIB to ensure execution (see PPP-3264)
IJobTrigger jobTrigger = runInBackground ? new SimpleJobTrigger(new Date(System.currentTimeMillis() + 10000), null, 0, 0) : scheduleRequest.getSimpleJobTrigger();
if (scheduleRequest.getSimpleJobTrigger() != null) {
SimpleJobTrigger simpleJobTrigger = scheduleRequest.getSimpleJobTrigger();
if (simpleJobTrigger.getStartTime() == null) {
simpleJobTrigger.setStartTime(new Date());
}
jobTrigger = simpleJobTrigger;
} else if (scheduleRequest.getComplexJobTrigger() != null) {
ComplexJobTriggerProxy proxyTrigger = scheduleRequest.getComplexJobTrigger();
ComplexJobTrigger complexJobTrigger = new ComplexJobTrigger();
complexJobTrigger.setStartTime(proxyTrigger.getStartTime());
complexJobTrigger.setEndTime(proxyTrigger.getEndTime());
complexJobTrigger.setDuration(scheduleRequest.getDuration());
if (proxyTrigger.getDaysOfWeek().length > 0) {
if (proxyTrigger.getWeeksOfMonth().length > 0) {
for (int dayOfWeek : proxyTrigger.getDaysOfWeek()) {
for (int weekOfMonth : proxyTrigger.getWeeksOfMonth()) {
QualifiedDayOfWeek qualifiedDayOfWeek = new QualifiedDayOfWeek();
qualifiedDayOfWeek.setDayOfWeek(DayOfWeek.values()[dayOfWeek]);
if (weekOfMonth == JobScheduleRequest.LAST_WEEK_OF_MONTH) {
qualifiedDayOfWeek.setQualifier(DayOfWeekQualifier.LAST);
} else {
qualifiedDayOfWeek.setQualifier(DayOfWeekQualifier.values()[weekOfMonth]);
}
complexJobTrigger.addDayOfWeekRecurrence(qualifiedDayOfWeek);
}
}
} else {
for (int dayOfWeek : proxyTrigger.getDaysOfWeek()) {
complexJobTrigger.addDayOfWeekRecurrence(dayOfWeek + 1);
}
}
} else if (proxyTrigger.getDaysOfMonth().length > 0) {
for (int dayOfMonth : proxyTrigger.getDaysOfMonth()) {
complexJobTrigger.addDayOfMonthRecurrence(dayOfMonth);
}
}
for (int month : proxyTrigger.getMonthsOfYear()) {
complexJobTrigger.addMonthlyRecurrence(month + 1);
}
for (int year : proxyTrigger.getYears()) {
complexJobTrigger.addYearlyRecurrence(year);
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(complexJobTrigger.getStartTime());
complexJobTrigger.setHourlyRecurrence(calendar.get(Calendar.HOUR_OF_DAY));
complexJobTrigger.setMinuteRecurrence(calendar.get(Calendar.MINUTE));
complexJobTrigger.setUiPassParam(scheduleRequest.getComplexJobTrigger().getUiPassParam());
jobTrigger = complexJobTrigger;
} else if (scheduleRequest.getCronJobTrigger() != null) {
if (scheduler instanceof QuartzScheduler) {
String cronString = scheduleRequest.getCronJobTrigger().getCronString();
// $NON-NLS-1$
String delims = "[ ]+";
String[] tokens = cronString.split(delims);
if (tokens.length < 7) {
cronString += " *";
}
ComplexJobTrigger complexJobTrigger = QuartzScheduler.createComplexTrigger(cronString);
complexJobTrigger.setStartTime(scheduleRequest.getCronJobTrigger().getStartTime());
complexJobTrigger.setEndTime(scheduleRequest.getCronJobTrigger().getEndTime());
complexJobTrigger.setDuration(scheduleRequest.getCronJobTrigger().getDuration());
complexJobTrigger.setUiPassParam(scheduleRequest.getCronJobTrigger().getUiPassParam());
jobTrigger = complexJobTrigger;
} else {
throw new IllegalArgumentException();
}
}
return jobTrigger;
}
Aggregations