public NexusTask<?> getModelNexusTask(ScheduledServiceBaseResource model, Request request) throws IllegalArgumentException, ResourceException { String serviceType = model.getTypeId(); NexusTask<?> task = (NexusTask<?>) getNexusScheduler().createTaskInstance(serviceType); for (Iterator iter = model.getProperties().iterator(); iter.hasNext(); ) { ScheduledServicePropertyResource prop = (ScheduledServicePropertyResource) iter.next(); task.addParameter(prop.getKey(), prop.getValue()); } TaskUtils.setAlertEmail(task, model.getAlertEmail()); TaskUtils.setId(task, model.getId()); TaskUtils.setName(task, model.getName()); return task; }
protected List<ScheduledServicePropertyResource> formatServiceProperties( Map<String, String> map) { List<ScheduledServicePropertyResource> list = new ArrayList<ScheduledServicePropertyResource>(); for (String key : map.keySet()) { if (!TaskUtils.isPrivateProperty(key)) { ScheduledServicePropertyResource prop = new ScheduledServicePropertyResource(); prop.setKey(key); prop.setValue(map.get(key)); list.add(prop); } } return list; }
public <T> ScheduledServiceBaseResource getServiceRestModel(ScheduledTask<T> task) { ScheduledServiceBaseResource resource = null; if (RunNowSchedule.class.isAssignableFrom(task.getSchedule().getClass()) || ManualRunSchedule.class.isAssignableFrom(task.getSchedule().getClass())) { resource = new ScheduledServiceBaseResource(); } else if (OnceSchedule.class.isAssignableFrom(task.getSchedule().getClass())) { resource = new ScheduledServiceOnceResource(); OnceSchedule taskSchedule = (OnceSchedule) task.getSchedule(); ScheduledServiceOnceResource res = (ScheduledServiceOnceResource) resource; res.setStartDate(formatDate(taskSchedule.getStartDate())); res.setStartTime(formatTime(taskSchedule.getStartDate())); } else if (HourlySchedule.class.isAssignableFrom(task.getSchedule().getClass())) { resource = new ScheduledServiceHourlyResource(); HourlySchedule taskSchedule = (HourlySchedule) task.getSchedule(); ScheduledServiceHourlyResource res = (ScheduledServiceHourlyResource) resource; res.setStartDate(formatDate(taskSchedule.getStartDate())); res.setStartTime(formatTime(taskSchedule.getStartDate())); } else if (DailySchedule.class.isAssignableFrom(task.getSchedule().getClass())) { resource = new ScheduledServiceDailyResource(); DailySchedule taskSchedule = (DailySchedule) task.getSchedule(); ScheduledServiceDailyResource res = (ScheduledServiceDailyResource) resource; res.setStartDate(formatDate(taskSchedule.getStartDate())); res.setRecurringTime(formatTime(taskSchedule.getStartDate())); } else if (WeeklySchedule.class.isAssignableFrom(task.getSchedule().getClass())) { resource = new ScheduledServiceWeeklyResource(); WeeklySchedule taskSchedule = (WeeklySchedule) task.getSchedule(); ScheduledServiceWeeklyResource res = (ScheduledServiceWeeklyResource) resource; res.setStartDate(formatDate(taskSchedule.getStartDate())); res.setRecurringTime(formatTime(taskSchedule.getStartDate())); res.setRecurringDay(formatRecurringDayOfWeek(taskSchedule.getDaysToRun())); } else if (MonthlySchedule.class.isAssignableFrom(task.getSchedule().getClass())) { resource = new ScheduledServiceMonthlyResource(); MonthlySchedule taskSchedule = (MonthlySchedule) task.getSchedule(); ScheduledServiceMonthlyResource res = (ScheduledServiceMonthlyResource) resource; res.setStartDate(formatDate(taskSchedule.getStartDate())); res.setRecurringTime(formatTime(taskSchedule.getStartDate())); res.setRecurringDay(formatRecurringDayOfMonth(taskSchedule.getDaysToRun())); } else if (CronSchedule.class.isAssignableFrom(task.getSchedule().getClass())) { resource = new ScheduledServiceAdvancedResource(); CronSchedule taskSchedule = (CronSchedule) task.getSchedule(); ScheduledServiceAdvancedResource res = (ScheduledServiceAdvancedResource) resource; res.setCronCommand(taskSchedule.getCronString()); } if (resource != null) { resource.setId(task.getId()); resource.setEnabled(task.isEnabled()); resource.setName(task.getName()); resource.setSchedule(getScheduleShortName(task.getSchedule())); resource.setTypeId(task.getType()); resource.setProperties(formatServiceProperties(task.getTaskParams())); resource.setAlertEmail(TaskUtils.getAlertEmail(task)); } return resource; }