return null;
}
}
private Schedule translateFrom(CScheduleConfig modelSchedule, Date nextRun) {
Schedule schedule = null;
Date startDate = null;
Date endDate = null;
if (modelSchedule.getStartDate() > 0) {
startDate = new Date(modelSchedule.getStartDate());
}
if (modelSchedule.getEndDate() > 0) {
endDate = new Date(modelSchedule.getEndDate());
}
if (CScheduleConfig.TYPE_ADVANCED.equals(modelSchedule.getType())) {
try {
schedule = new CronSchedule(modelSchedule.getCronCommand());
}
catch (ParseException e) {
// this will not happen, since it was persisted, hence already submitted
}
}
else if (CScheduleConfig.TYPE_MONTHLY.equals(modelSchedule.getType())) {
Set<Integer> daysToRun = new HashSet<Integer>();
for (Iterator iter = modelSchedule.getDaysOfMonth().iterator(); iter.hasNext(); ) {
String day = (String) iter.next();
try {
daysToRun.add(Integer.valueOf(day));
}
catch (NumberFormatException nfe) {
log.error("Invalid day being added to monthly schedule - " + day + " - skipping.");
}
}
schedule = new MonthlySchedule(startDate, endDate, daysToRun);
}
else if (CScheduleConfig.TYPE_WEEKLY.equals(modelSchedule.getType())) {
Set<Integer> daysToRun = new HashSet<Integer>();
for (Iterator iter = modelSchedule.getDaysOfWeek().iterator(); iter.hasNext(); ) {
String day = (String) iter.next();
try {
daysToRun.add(Integer.valueOf(day));
}
catch (NumberFormatException nfe) {
log.error("Invalid day being added to weekly schedule - " + day + " - skipping.");
}
}
schedule = new WeeklySchedule(startDate, endDate, daysToRun);
}
else if (CScheduleConfig.TYPE_DAILY.equals(modelSchedule.getType())) {
schedule = new DailySchedule(startDate, endDate);
}
else if (CScheduleConfig.TYPE_HOURLY.equals(modelSchedule.getType())) {
schedule = new HourlySchedule(startDate, endDate);
}
else if (CScheduleConfig.TYPE_ONCE.equals(modelSchedule.getType())) {
schedule = new OnceSchedule(startDate);
}
else if (CScheduleConfig.TYPE_RUN_NOW.equals(modelSchedule.getType())) {
schedule = new RunNowSchedule();
}
else if (CScheduleConfig.TYPE_MANUAL.equals(modelSchedule.getType())) {
schedule = new ManualRunSchedule();
}
else {
throw new IllegalArgumentException("Unknown Schedule type: " + modelSchedule.getClass().getName());
}
if (nextRun != null) {
Date resetFrom = nextRun;
// NEXUS-4465: Cron schedule will add 1 second to given time to calculate next scheduled time
// so we subtract it in case that next schedule is actually a valid time to run
if (schedule instanceof CronSchedule) {
resetFrom = new Date(resetFrom.getTime() - 1000);
}
schedule.getIterator().resetFrom(resetFrom);
}
return schedule;
}