Search in sources :

Example 6 with CronCalendar

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);
}
Also used : CronCalendar(com.enonic.xp.scheduler.CronCalendar) OneTimeCalendar(com.enonic.xp.scheduler.OneTimeCalendar) PropertySet(com.enonic.xp.data.PropertySet)

Example 7 with CronCalendar

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);
}
Also used : CronCalendar(com.enonic.xp.scheduler.CronCalendar) OneTimeCalendar(com.enonic.xp.scheduler.OneTimeCalendar) PropertySet(com.enonic.xp.data.PropertySet)

Example 8 with CronCalendar

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);
}
Also used : CronCalendar(com.enonic.xp.scheduler.CronCalendar) OneTimeCalendar(com.enonic.xp.scheduler.OneTimeCalendar) PropertySet(com.enonic.xp.data.PropertySet)

Example 9 with CronCalendar

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());
}
Also used : CreateScheduledJobParams(com.enonic.xp.scheduler.CreateScheduledJobParams) CronCalendar(com.enonic.xp.scheduler.CronCalendar) ScheduledJobName(com.enonic.xp.scheduler.ScheduledJobName) PropertyTree(com.enonic.xp.data.PropertyTree) Instant(java.time.Instant) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) DescriptorKey(com.enonic.xp.page.DescriptorKey) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 10 with CronCalendar

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());
}
Also used : CronCalendar(com.enonic.xp.scheduler.CronCalendar) PropertyTree(com.enonic.xp.data.PropertyTree) DescriptorKey(com.enonic.xp.page.DescriptorKey) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Aggregations

CronCalendar (com.enonic.xp.scheduler.CronCalendar)14 PropertyTree (com.enonic.xp.data.PropertyTree)9 Test (org.junit.jupiter.api.Test)9 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)7 ScheduledJobName (com.enonic.xp.scheduler.ScheduledJobName)6 DescriptorKey (com.enonic.xp.page.DescriptorKey)5 PropertySet (com.enonic.xp.data.PropertySet)4 CreateScheduledJobParams (com.enonic.xp.scheduler.CreateScheduledJobParams)4 OneTimeCalendar (com.enonic.xp.scheduler.OneTimeCalendar)4 ScheduledJob (com.enonic.xp.scheduler.ScheduledJob)4 Context (com.enonic.xp.context.Context)1 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)1 Node (com.enonic.xp.node.Node)1 PrincipalKey (com.enonic.xp.security.PrincipalKey)1 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 TimeZone (java.util.TimeZone)1