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;
});
}
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 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);
}
Aggregations