use of com.enonic.xp.content.Content in project xp by enonic.
the class MovedEventSyncCommand method doMove.
private void doMove(final List<ContentToSync> contents) {
final Set<ContentPath> paths = contents.stream().map(content -> content.getSourceContent().getPath()).collect(Collectors.toSet());
final List<ContentToSync> rootsToSync = contents.stream().filter(content -> !paths.contains(content.getSourceContent().getParentPath())).collect(Collectors.toList());
rootsToSync.forEach(content -> {
if (isToSync(content.getTargetContent())) {
content.getTargetContext().runWith(() -> {
final Content sourceParent = content.getSourceContext().callWith(() -> contentService.getByPath(content.getSourceContent().getParentPath()));
final Content sourceRoot = content.getSourceContext().callWith(() -> contentService.getByPath(ContentPath.ROOT));
final ContentPath targetParentPath = contentService.contentExists(sourceParent.getId()) ? contentService.getById(sourceParent.getId()).getPath() : sourceRoot.getId().equals(sourceParent.getId()) ? ContentPath.ROOT : null;
if (targetParentPath == null) {
return;
}
if (!targetParentPath.equals(content.getTargetContent().getParentPath())) {
final ContentPath newPath = buildNewPath(targetParentPath, content.getTargetContent().getName());
if (!Objects.equals(newPath.getName(), content.getTargetContent().getPath().getName())) {
contentService.rename(RenameContentParams.create().contentId(content.getTargetContent().getId()).newName(ContentName.from(newPath.getName())).build());
}
contentService.move(MoveContentParams.create().contentId(content.getTargetContent().getId()).parentContentPath(targetParentPath).stopInherit(false).build());
}
});
}
});
}
use of com.enonic.xp.content.Content in project xp by enonic.
the class ReprocessContentCommand method revertModifiedTime.
private Content revertModifiedTime(final Content content, final Instant modifiedTime) {
final UpdateNodeParams update = UpdateNodeParams.create().id(NodeId.from(content.getId())).editor((node) -> node.data.getRoot().setInstant(MODIFIED_TIME, modifiedTime)).build();
this.nodeService.update(update);
return this.getContent(content.getId());
}
use of com.enonic.xp.content.Content in project xp by enonic.
the class ReprocessContentCommand method execute.
Content execute() {
final Content source = this.getContent(params.getContentId());
if (!source.getType().isDescendantOfMedia()) {
return source;
}
final Content reprocessed = reprocessMedia((Media) source);
return revertModifiedTime(reprocessed, source.getModifiedTime());
}
use of com.enonic.xp.content.Content in project xp by enonic.
the class MovedEventSyncRestorer method execute.
protected void execute() {
final List<ContentToSync> contentToSync = contents.stream().filter(content -> isToSyncContent(content.getTargetContent())).collect(Collectors.toList());
getRoots(contentToSync).forEach(content -> {
final Content sourceParent = content.getSourceContext().callWith(() -> contentService.getByPath(content.getSourceContent().getParentPath()));
final Context targetContextToRestore = ContextBuilder.from(content.getTargetContext()).attribute(CONTENT_ROOT_PATH_ATTRIBUTE, content.getSourceContext().getAttribute(CONTENT_ROOT_PATH_ATTRIBUTE)).build();
final ContentPath targetParentPath = targetContextToRestore.callWith(() -> contentService.contentExists(sourceParent.getId()) ? contentService.getById(sourceParent.getId()).getPath() : ContentPath.ROOT);
content.getTargetContext().runWith(() -> contentService.restore(RestoreContentParams.create().contentId(content.getTargetContent().getId()).path(targetParentPath).stopInherit(false).build()));
});
}
use of com.enonic.xp.content.Content in project xp by enonic.
the class ParentContentSynchronizer method cleanDeletedContents.
private void cleanDeletedContents(final ContentToSync contentToSync) {
contentToSync.getTargetContext().runWith(() -> {
final Queue<Content> queue = new ArrayDeque<>(Set.of(contentToSync.getTargetContent()));
while (queue.size() > 0) {
final Content currentContent = queue.poll();
createEventCommand(createEventCommandParams(List.of(ContentToSync.create().targetContent(currentContent).sourceContext(contentToSync.getSourceContext()).targetContext(contentToSync.getTargetContext()).build())), ContentSyncEventType.DELETED).sync();
if (currentContent.hasChildren()) {
final FindContentByParentResult result = contentService.findByParent(FindContentByParentParams.create().parentId(currentContent.getId()).recursive(false).childOrder(currentContent.getChildOrder()).size(-1).build());
for (final Content content : result.getContents()) {
queue.offer(content);
}
}
}
});
}
Aggregations