Search in sources :

Example 6 with Content

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());
                }
            });
        }
    });
}
Also used : CONTENT_ROOT_PATH_ATTRIBUTE(com.enonic.xp.content.ContentConstants.CONTENT_ROOT_PATH_ATTRIBUTE) ContentPath(com.enonic.xp.content.ContentPath) ArchiveConstants(com.enonic.xp.archive.ArchiveConstants) ContentInheritType(com.enonic.xp.content.ContentInheritType) Set(java.util.Set) Content(com.enonic.xp.content.Content) Collectors(java.util.stream.Collectors) ContentName(com.enonic.xp.content.ContentName) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) RenameContentParams(com.enonic.xp.content.RenameContentParams) MoveContentParams(com.enonic.xp.content.MoveContentParams) Preconditions(com.google.common.base.Preconditions) Content(com.enonic.xp.content.Content) ContentPath(com.enonic.xp.content.ContentPath)

Example 7 with Content

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());
}
Also used : PartDescriptorService(com.enonic.xp.region.PartDescriptorService) Media(com.enonic.xp.content.Media) UpdateMediaParams(com.enonic.xp.content.UpdateMediaParams) Content(com.enonic.xp.content.Content) Attachment(com.enonic.xp.attachment.Attachment) LayoutDescriptorService(com.enonic.xp.region.LayoutDescriptorService) Instant(java.time.Instant) NodeId(com.enonic.xp.node.NodeId) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) ContentId(com.enonic.xp.content.ContentId) PageDescriptorService(com.enonic.xp.page.PageDescriptorService) ReprocessContentParams(com.enonic.xp.content.ReprocessContentParams) MediaInfoService(com.enonic.xp.media.MediaInfoService) ContentDataSerializer(com.enonic.xp.core.impl.content.serializer.ContentDataSerializer) MODIFIED_TIME(com.enonic.xp.content.ContentPropertyNames.MODIFIED_TIME) ByteSource(com.google.common.io.ByteSource) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams)

Example 8 with Content

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());
}
Also used : Content(com.enonic.xp.content.Content)

Example 9 with Content

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

Example 10 with Content

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);
                }
            }
        }
    });
}
Also used : FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) Content(com.enonic.xp.content.Content) ArrayDeque(java.util.ArrayDeque)

Aggregations

Content (com.enonic.xp.content.Content)563 Test (org.junit.jupiter.api.Test)435 PropertyTree (com.enonic.xp.data.PropertyTree)131 CreateContentParams (com.enonic.xp.content.CreateContentParams)57 ContentId (com.enonic.xp.content.ContentId)50 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)48 ContentPath (com.enonic.xp.content.ContentPath)47 ValidationErrors (com.enonic.xp.content.ValidationErrors)47 Site (com.enonic.xp.site.Site)43 PropertySet (com.enonic.xp.data.PropertySet)31 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)27 Page (com.enonic.xp.page.Page)26 Contents (com.enonic.xp.content.Contents)25 Node (com.enonic.xp.node.Node)25 ContentIds (com.enonic.xp.content.ContentIds)24 ContentQuery (com.enonic.xp.content.ContentQuery)24 FindContentByParentParams (com.enonic.xp.content.FindContentByParentParams)24 FindContentByParentResult (com.enonic.xp.content.FindContentByParentResult)23 DataValidationError (com.enonic.xp.content.DataValidationError)21 ContentType (com.enonic.xp.schema.content.ContentType)20