コード例 #1
0
  @Override
  public ScheduledServiceWeeklyResource getTaskScheduled() {
    if (scheduledTask == null) {
      scheduledTask = new ScheduledServiceWeeklyResource();
      scheduledTask.setEnabled(true);
      scheduledTask.setId(null);
      scheduledTask.setName("taskWeekly");
      scheduledTask.setSchedule("weekly");
      // A future date
      Date startDate = DateUtils.addDays(new Date(), 10);
      startDate = DateUtils.round(startDate, Calendar.DAY_OF_MONTH);
      scheduledTask.setStartDate(String.valueOf(startDate.getTime()));
      scheduledTask.setRecurringTime("03:30");
      scheduledTask.setRecurringDay(Arrays.asList(new String[] {"monday", "wednesday", "friday"}));

      scheduledTask.setTypeId(UpdateIndexTaskDescriptor.ID);

      ScheduledServicePropertyResource prop = new ScheduledServicePropertyResource();
      prop.setKey("repositoryOrGroupId");
      prop.setValue("all_repo");
      scheduledTask.addProperty(prop);
    }
    return scheduledTask;
  }
コード例 #2
0
  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;
  }
コード例 #3
0
 @Override
 public void updateTask(ScheduledServiceWeeklyResource scheduledTask) {
   scheduledTask.setRecurringTime("00:00");
 }