Package org.sonatype.nexus.rest.model

Examples of org.sonatype.nexus.rest.model.ScheduledServiceOnceResource


  @Test
  public void createTask()
      throws IOException
  {

    final ScheduledServiceOnceResource task = new ScheduledServiceOnceResource();
    task.setName("name");
    task.setSchedule("once");
    task.setTypeId(EmptyTrashTaskDescriptor.ID);
    ScheduledServicePropertyResource property = new ScheduledServicePropertyResource();
    property.setKey(EmptyTrashTaskDescriptor.OLDER_THAN_FIELD_ID);
    task.setProperties(Lists.newArrayList(property));

    Calendar cal = Calendar.getInstance();

    // simulating client timezone here: calculate offset from current timezone

    // client is tz+2 -> 3 hours ahead for local tz is one hour ahead for client tz
    cal.add(Calendar.HOUR_OF_DAY, 3);
    task.setStartTime(new SimpleDateFormat("HH:mm").format(cal.getTime()));

    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    // client is tz+2 -> midnight for client happens 2 hours before servers midnight
    cal.add(Calendar.HOUR_OF_DAY, -2);
    task.setStartDate(String.valueOf(cal.getTimeInMillis()));

    log.debug("request dates:\nmidnight: {}\ntime offset: {}", cal.getTime(), task.getStartTime());

    assertThat(TaskScheduleUtil.create(task), NexusRequestMatchers.hasStatusCode(201));
  }
View Full Code Here


      Status status = TaskScheduleUtil.update(taskManual);
      Assert.assertTrue(status.isSuccess());

    }
    else {
      ScheduledServiceOnceResource updatedTask = new ScheduledServiceOnceResource();
      updatedTask.setId(task.getId());
      updatedTask.setName(scheduledTask.getName());
      updatedTask.setEnabled(task.isEnabled());
      updatedTask.setTypeId(scheduledTask.getTypeId());
      updatedTask.setProperties(scheduledTask.getProperties());
      updatedTask.setSchedule("once");
      Date startDate = DateUtils.addDays(new Date(), 10);
      startDate = DateUtils.round(startDate, Calendar.DAY_OF_MONTH);
      updatedTask.setStartDate(String.valueOf(startDate.getTime()));
      updatedTask.setStartTime("03:30");

      Status status = TaskScheduleUtil.update(updatedTask);
      Assert.assertTrue(status.isSuccess());
    }
View Full Code Here

  private static ScheduledServiceOnceResource scheduledTask;

  @Override
  public ScheduledServiceOnceResource getTaskScheduled() {
    if (scheduledTask == null) {
      scheduledTask = new ScheduledServiceOnceResource();
      scheduledTask.setEnabled(true);
      scheduledTask.setId(null);
      scheduledTask.setName("taskOnce");
      scheduledTask.setSchedule("once");
      // A future date
View Full Code Here

      }
      else if (SCHEDULE_TYPE_MANUAL.equals(schedule)) {
        return new ScheduledServiceBaseResource();
      }
      else if (SCHEDULE_TYPE_ONCE.equals(schedule)) {
        return new ScheduledServiceOnceResource();
      }
      else if (SCHEDULE_TYPE_HOURLY.equals(schedule)) {
        return new ScheduledServiceHourlyResource();
      }
      else if (SCHEDULE_TYPE_DAILY.equals(schedule)) {
View Full Code Here

    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());
View Full Code Here

  }

  @Test
  public void testScheduledServiceOnceResource() {
    ScheduledServiceOnceResource resource = new ScheduledServiceOnceResource();
    resource.setStartDate("StartDate");
    resource.setStartTime("StartTime");
    resource.setId("Id");
    resource.setSchedule("once");
    resource.setTypeId("TypeId");
    resource.setAlertEmail("foo@bar.org");
    resource.setName("Name");
    resource.setEnabled(true);

    ScheduledServicePropertyResource prop1 = new ScheduledServicePropertyResource();
    prop1.setKey("id1");
    prop1.setValue("value1");
    resource.addProperty(prop1);

    ScheduledServicePropertyResource prop2 = new ScheduledServicePropertyResource();
    prop2.setKey("id2");
    prop2.setValue("value2");
    resource.addProperty(prop2);

    ScheduledServiceResourceResponse resourceResponse = new ScheduledServiceResourceResponse();
    resourceResponse.setData(resource);

    this.marshalUnmarchalThenCompare(resourceResponse);
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.rest.model.ScheduledServiceOnceResource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.