use of com.enonic.xp.scheduler.CronCalendar in project xp by enonic.
the class ScheduleAuditLogSupportImpl method addCalendar.
private void addCalendar(final PropertySet targetSet, final ScheduleCalendar calendar) {
final PropertySet calendarSet = new PropertySet();
switch(calendar.getType()) {
case CRON:
final CronCalendar cronCalendar = ((CronCalendar) calendar);
calendarSet.setString(ScheduledJobPropertyNames.CALENDAR_VALUE, cronCalendar.getCronValue());
calendarSet.setString(ScheduledJobPropertyNames.CALENDAR_TIMEZONE, cronCalendar.getTimeZone().getID());
calendarSet.setString(ScheduledJobPropertyNames.CALENDAR_TYPE, ScheduleCalendarType.CRON.name());
break;
case ONE_TIME:
final OneTimeCalendar oneTimeCalendar = ((OneTimeCalendar) calendar);
calendarSet.setString(ScheduledJobPropertyNames.CALENDAR_VALUE, oneTimeCalendar.getValue().toString());
calendarSet.setString(ScheduledJobPropertyNames.CALENDAR_TYPE, ScheduleCalendarType.ONE_TIME.name());
break;
default:
throw new IllegalStateException(String.format("invalid calendar type: '%s'", calendar.getType()));
}
targetSet.setSet(ScheduledJobPropertyNames.CALENDAR, calendarSet);
}
use of com.enonic.xp.scheduler.CronCalendar in project xp by enonic.
the class SchedulerSerializer method addCalendar.
private static void addCalendar(final CreateScheduledJobParams params, final PropertySet data) {
final PropertySet calendarSet = new PropertySet();
switch(params.getCalendar().getType()) {
case CRON:
final CronCalendar cronCalendar = ((CronCalendar) params.getCalendar());
calendarSet.setString(ScheduledJobPropertyNames.CALENDAR_VALUE, cronCalendar.getCronValue());
calendarSet.setString(ScheduledJobPropertyNames.CALENDAR_TIMEZONE, cronCalendar.getTimeZone().getID());
calendarSet.setString(ScheduledJobPropertyNames.CALENDAR_TYPE, ScheduleCalendarType.CRON.name());
break;
case ONE_TIME:
final OneTimeCalendar oneTimeCalendar = ((OneTimeCalendar) params.getCalendar());
calendarSet.setString(ScheduledJobPropertyNames.CALENDAR_VALUE, oneTimeCalendar.getValue().toString());
calendarSet.setString(ScheduledJobPropertyNames.CALENDAR_TYPE, ScheduleCalendarType.ONE_TIME.name());
break;
default:
throw new IllegalStateException(String.format("invalid calendar type: '%s'", params.getCalendar().getType()));
}
data.setSet(ScheduledJobPropertyNames.CALENDAR, calendarSet);
}
use of com.enonic.xp.scheduler.CronCalendar in project xp by enonic.
the class SchedulerSerializer method addCalendar.
private static void addCalendar(final ScheduledJob modifiedJob, final PropertySet data) {
final PropertySet calendarSet = new PropertySet();
switch(modifiedJob.getCalendar().getType()) {
case CRON:
final CronCalendar cronCalendar = ((CronCalendar) modifiedJob.getCalendar());
calendarSet.setString(ScheduledJobPropertyNames.CALENDAR_VALUE, cronCalendar.getCronValue());
calendarSet.setString(ScheduledJobPropertyNames.CALENDAR_TIMEZONE, cronCalendar.getTimeZone().getID());
calendarSet.setString(ScheduledJobPropertyNames.CALENDAR_TYPE, ScheduleCalendarType.CRON.name());
break;
case ONE_TIME:
final OneTimeCalendar oneTimeCalendar = ((OneTimeCalendar) modifiedJob.getCalendar());
calendarSet.setString(ScheduledJobPropertyNames.CALENDAR_VALUE, oneTimeCalendar.getValue().toString());
calendarSet.setString(ScheduledJobPropertyNames.CALENDAR_TYPE, ScheduleCalendarType.ONE_TIME.name());
break;
default:
throw new IllegalStateException(String.format("invalid calendar type: '%s'", modifiedJob.getCalendar().getType()));
}
data.setSet(ScheduledJobPropertyNames.CALENDAR, calendarSet);
}
use of com.enonic.xp.scheduler.CronCalendar in project xp by enonic.
the class SchedulerServiceImplTest method create.
@Test
void create() throws Exception {
final ScheduledJobName name = ScheduledJobName.from("test");
final DescriptorKey descriptor = DescriptorKey.from(ApplicationKey.from("com.enonic.app.features"), "landing");
final CronCalendar calendar = calendarService.cron("* * * * *", TimeZone.getDefault());
final PropertyTree config = new PropertyTree();
config.addString("string", "value");
final PrincipalKey user = PrincipalKey.from("user:system:user");
final CreateScheduledJobParams params = CreateScheduledJobParams.create().name(name).descriptor(descriptor).calendar(calendar).config(config).description("description").enabled(true).user(user).build();
final Instant now = Instant.now();
Thread.sleep(100);
final ScheduledJob scheduledJob = adminContext().callWith(() -> schedulerService.create(params));
assertEquals(name, scheduledJob.getName());
assertEquals(descriptor, scheduledJob.getDescriptor());
assertEquals(calendar.getCronValue(), ((CronCalendar) scheduledJob.getCalendar()).getCronValue());
assertEquals(calendar.getTimeZone(), ((CronCalendar) scheduledJob.getCalendar()).getTimeZone());
assertEquals(config, scheduledJob.getConfig());
assertEquals("description", scheduledJob.getDescription());
assertEquals(user, scheduledJob.getUser());
assertEquals("user:system:repo-test-user", scheduledJob.getModifier().toString());
assertEquals("user:system:repo-test-user", scheduledJob.getCreator().toString());
assertTrue(now.isBefore(scheduledJob.getCreatedTime()));
assertTrue(now.isBefore(scheduledJob.getModifiedTime()));
assertTrue(scheduledJob.isEnabled());
}
use of com.enonic.xp.scheduler.CronCalendar in project xp by enonic.
the class SchedulerServiceImplTest method list.
@Test
void list() {
assertEquals(0, adminContext().callWith(() -> schedulerService.list()).size());
final DescriptorKey descriptor = DescriptorKey.from(ApplicationKey.from("com.enonic.app.features"), "landing");
final CronCalendar calendar = calendarService.cron("* * * * *", TimeZone.getDefault());
final PropertyTree config = new PropertyTree();
config.addString("string", "value");
adminContext().callWith(() -> schedulerService.create(CreateScheduledJobParams.create().name(ScheduledJobName.from("test1")).descriptor(descriptor).calendar(calendar).config(config).description("description").build()));
assertEquals(1, adminContext().callWith(() -> schedulerService.list()).size());
adminContext().callWith(() -> schedulerService.create(CreateScheduledJobParams.create().name(ScheduledJobName.from("test2")).descriptor(descriptor).calendar(calendar).config(config).description("description").build()));
assertEquals(2, adminContext().callWith(() -> schedulerService.list()).size());
}
Aggregations