Search in sources :

Example 1 with CONTENT_ROOT_PATH_ATTRIBUTE

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()));
    });
}
Also used : RestoreContentParams(com.enonic.xp.archive.RestoreContentParams) List(java.util.List) CONTENT_ROOT_PATH_ATTRIBUTE(com.enonic.xp.content.ContentConstants.CONTENT_ROOT_PATH_ATTRIBUTE) ContentPath(com.enonic.xp.content.ContentPath) Set(java.util.Set) Content(com.enonic.xp.content.Content) Context(com.enonic.xp.context.Context) ContextBuilder(com.enonic.xp.context.ContextBuilder) Collectors(java.util.stream.Collectors) Context(com.enonic.xp.context.Context) Content(com.enonic.xp.content.Content) ContentPath(com.enonic.xp.content.ContentPath)

Aggregations

RestoreContentParams (com.enonic.xp.archive.RestoreContentParams)1 Content (com.enonic.xp.content.Content)1 CONTENT_ROOT_PATH_ATTRIBUTE (com.enonic.xp.content.ContentConstants.CONTENT_ROOT_PATH_ATTRIBUTE)1 ContentPath (com.enonic.xp.content.ContentPath)1 Context (com.enonic.xp.context.Context)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1