use of com.enonic.xp.data.PropertySet in project xp by enonic.
the class SchedulerSerializer method toUpdateNodeData.
public static PropertyTree toUpdateNodeData(final ModifyScheduledJobParams params, final ScheduledJob original) {
final ScheduledJob modifiedJob = editScheduledJob(params.getEditor(), original);
final PropertyTree tree = new PropertyTree();
final PropertySet data = tree.getRoot();
data.ifNotNull().setString(ScheduledJobPropertyNames.DESCRIPTION, modifiedJob.getDescription());
data.setBoolean(ScheduledJobPropertyNames.ENABLED, modifiedJob.isEnabled());
addCalendar(modifiedJob, data);
if (modifiedJob.getDescriptor() != null) {
data.setString(ScheduledJobPropertyNames.DESCRIPTOR, modifiedJob.getDescriptor().toString());
}
if (modifiedJob.getConfig() != null) {
data.setSet(ScheduledJobPropertyNames.CONFIG, modifiedJob.getConfig().getRoot().copy(data.getTree()));
}
if (modifiedJob.getUser() != null) {
data.setString(ScheduledJobPropertyNames.USER, modifiedJob.getUser().toString());
}
if (modifiedJob.getCreator() != null) {
data.setString(ScheduledJobPropertyNames.CREATOR, modifiedJob.getCreator().toString());
}
if (modifiedJob.getCreatedTime() != null) {
data.setInstant(ScheduledJobPropertyNames.CREATED_TIME, modifiedJob.getCreatedTime());
}
data.setString(ScheduledJobPropertyNames.MODIFIER, getCurrentUser().getKey().toString());
data.setInstant(ScheduledJobPropertyNames.MODIFIED_TIME, Instant.now());
return tree;
}
use of com.enonic.xp.data.PropertySet 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.data.PropertySet 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.data.PropertySet in project xp by enonic.
the class ContentServiceImplTest_duplicate method data_removed_on_duplicate.
@Test
public void data_removed_on_duplicate() throws Exception {
final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("rootContent").parent(ContentPath.ROOT).type(ContentTypeName.folder()).permissions(AccessControlList.create().build()).build();
final Content content = this.contentService.create(createContentParams);
this.nodeService.update(UpdateNodeParams.create().id(NodeId.from(content.getId())).editor(toBeEdited -> {
toBeEdited.data.addSet(ContentPropertyNames.PUBLISH_INFO, new PropertySet());
toBeEdited.data.addString(ContentPropertyNames.ORIGIN_PROJECT, "some-project");
toBeEdited.data.addStrings(ContentPropertyNames.INHERIT, ContentInheritType.CONTENT.name(), ContentInheritType.NAME.name());
}).build());
final Content duplicateContent = doDuplicateContent(content);
assertNull(duplicateContent.getPublishInfo());
assertNull(duplicateContent.getOriginProject());
assertTrue(duplicateContent.getInherit().isEmpty());
}
use of com.enonic.xp.data.PropertySet in project xp by enonic.
the class ContentServiceImplTest_duplicate method audit_data.
@Test
public void audit_data() throws Exception {
final ArgumentCaptor<LogAuditLogParams> captor = ArgumentCaptor.forClass(LogAuditLogParams.class);
final Content rootContent = createContent(ContentPath.ROOT);
final Content childContent = createContent(rootContent.getPath());
final Content duplicatedContent = doDuplicateContent(rootContent);
Mockito.verify(auditLogService, Mockito.timeout(5000).atLeast(17)).log(captor.capture());
final PropertySet logResultSet = captor.getAllValues().stream().filter(log -> log.getType().equals("system.content.duplicate")).findFirst().get().getData().getSet("result");
final Iterable<String> ids = logResultSet.getStrings("duplicatedContents");
assertEquals(2, StreamSupport.stream(ids.spliterator(), false).count());
assertTrue(StreamSupport.stream(ids.spliterator(), false).anyMatch(id -> id.equals(duplicatedContent.getId().toString())));
}
Aggregations