use of com.enonic.xp.content.ContentConstants.CONTENT_ROOT_PATH_ATTRIBUTE 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()));
});
}
Aggregations