use of com.enonic.xp.scheduler.OneTimeCalendar 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.OneTimeCalendar 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.OneTimeCalendar 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.OneTimeCalendar in project xp by enonic.
the class SchedulerServiceImplTest method createOneTimeJob.
@Test
void createOneTimeJob() throws Exception {
final ScheduledJobName name = ScheduledJobName.from("test");
final DescriptorKey descriptor = DescriptorKey.from(ApplicationKey.from("com.enonic.app.features"), "landing");
final ScheduleCalendar calendar = calendarService.oneTime(Instant.parse("2021-02-25T10:44:33.170079900Z"));
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("2021-02-25T10:44:33.170079900Z", ((OneTimeCalendar) scheduledJob.getCalendar()).getValue().toString());
assertEquals(ScheduleCalendarType.ONE_TIME, scheduledJob.getCalendar().getType());
assertEquals("user:system:repo-test-user", scheduledJob.getCreator().toString());
assertEquals("user:system:repo-test-user", scheduledJob.getModifier().toString());
assertTrue(now.isBefore(scheduledJob.getModifiedTime()));
assertTrue(now.isBefore(scheduledJob.getCreatedTime()));
}
use of com.enonic.xp.scheduler.OneTimeCalendar in project xp by enonic.
the class SchedulerServiceImplTest method modify.
@Test
void modify() throws Exception {
final ScheduledJobName name = ScheduledJobName.from("test");
adminContext().callWith(() -> schedulerService.create(CreateScheduledJobParams.create().name(name).descriptor(DescriptorKey.from(ApplicationKey.from("com.enonic.app.test"), "task1")).calendar(calendarService.cron("* * * * *", TimeZone.getTimeZone("GMT+5:30"))).config(new PropertyTree()).build()));
final Instant now = Instant.now();
Thread.sleep(100);
final User user = User.create().key(PrincipalKey.ofUser(IdProviderKey.system(), "user1")).displayName("User 1").email("user1@enonic.com").login("user1").build();
final Context adminContext = adminContext();
final Context userAdminContext = ContextBuilder.from(adminContext).authInfo(AuthenticationInfo.copyOf(adminContext.getAuthInfo()).user(user).build()).build();
final ScheduledJob modifiedJob = userAdminContext.callWith(() -> schedulerService.modify(ModifyScheduledJobParams.create().name(name).editor(edit -> {
edit.enabled = true;
edit.description = "new description";
edit.descriptor = DescriptorKey.from(ApplicationKey.from("com.enonic.app.test"), "task2");
edit.config.addString("string", "value");
edit.user = PrincipalKey.from("user:provider:user");
edit.calendar = calendarService.oneTime(Instant.parse("2021-02-25T10:44:33.170079900Z"));
}).build()));
assertEquals(name, modifiedJob.getName());
assertEquals(DescriptorKey.from(ApplicationKey.from("com.enonic.app.test"), "task2"), modifiedJob.getDescriptor());
assertEquals("new description", modifiedJob.getDescription());
assertEquals("2021-02-25T10:44:33.170079900Z", ((OneTimeCalendar) modifiedJob.getCalendar()).getValue().toString());
assertEquals(ScheduleCalendarType.ONE_TIME, modifiedJob.getCalendar().getType());
assertEquals("value", modifiedJob.getConfig().getString("string"));
assertEquals(PrincipalKey.from("user:provider:user"), modifiedJob.getUser());
assertEquals(PrincipalKey.from("user:system:repo-test-user"), modifiedJob.getCreator());
assertEquals(PrincipalKey.from("user:system:user1"), modifiedJob.getModifier());
assertEquals(user.getKey(), modifiedJob.getModifier());
assertTrue(now.isBefore(modifiedJob.getModifiedTime()));
assertTrue(Instant.now().isAfter(modifiedJob.getModifiedTime()));
assertTrue(Instant.now().isAfter(modifiedJob.getCreatedTime()));
}
Aggregations