Search in sources :

Example 1 with CronCalendar

use of com.enonic.xp.scheduler.CronCalendar in project xp by enonic.

the class BaseScheduledJobHandlerTest method mockCronCalendar.

protected void mockCronCalendar() {
    Mockito.when(calendarService.cron(Mockito.anyString(), Mockito.isA(TimeZone.class))).thenAnswer(invocation -> {
        final CronCalendar cron = Mockito.mock(CronCalendar.class);
        Mockito.when(cron.getType()).thenReturn(ScheduleCalendarType.CRON);
        Mockito.when(cron.getCronValue()).thenReturn(invocation.getArgument(0));
        Mockito.when(cron.getTimeZone()).thenReturn(invocation.getArgument(1));
        return cron;
    });
}
Also used : TimeZone(java.util.TimeZone) CronCalendar(com.enonic.xp.scheduler.CronCalendar)

Example 2 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 3 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 4 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 5 with CronCalendar

use of com.enonic.xp.scheduler.CronCalendar in project xp by enonic.

the class SchedulerServiceActivatorTest method mockNode.

private void mockNode(final CreateScheduledJobParams params) {
    final PropertyTree jobData = new PropertyTree();
    final PropertySet calendar = new PropertySet();
    calendar.addString(ScheduledJobPropertyNames.CALENDAR_TYPE, params.getCalendar().getType().name());
    calendar.addString(ScheduledJobPropertyNames.CALENDAR_VALUE, ((CronCalendar) params.getCalendar()).getCronValue());
    calendar.addString(ScheduledJobPropertyNames.CALENDAR_TIMEZONE, ((CronCalendar) params.getCalendar()).getTimeZone().getID());
    jobData.addString(ScheduledJobPropertyNames.DESCRIPTOR, params.getDescriptor().toString());
    jobData.addBoolean(ScheduledJobPropertyNames.ENABLED, params.isEnabled());
    jobData.addSet(ScheduledJobPropertyNames.CALENDAR, calendar);
    jobData.addSet(ScheduledJobPropertyNames.CONFIG, params.getConfig().getRoot().copy(jobData));
    jobData.setString(ScheduledJobPropertyNames.CREATOR, "user:system:creator");
    jobData.setString(ScheduledJobPropertyNames.MODIFIER, "user:system:creator");
    jobData.setString(ScheduledJobPropertyNames.CREATED_TIME, "2016-11-02T10:36:00Z");
    jobData.setString(ScheduledJobPropertyNames.MODIFIED_TIME, "2016-11-02T10:36:00Z");
    final Node job = Node.create().id(NodeId.from("abc")).name(params.getName().getValue()).parentPath(NodePath.ROOT).data(jobData).build();
    when(nodeService.create(isA(CreateNodeParams.class))).thenReturn(job);
}
Also used : CronCalendar(com.enonic.xp.scheduler.CronCalendar) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) PropertySet(com.enonic.xp.data.PropertySet) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

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