Search in sources :

Example 46 with NodePath

use of com.enonic.xp.node.NodePath in project xp by enonic.

the class ContentServiceImpl method getRootPermissions.

@Override
public AccessControlList getRootPermissions() {
    final ContentPath rootContentPath = ContentPath.ROOT;
    final NodePath rootNodePath = ContentNodeHelper.translateContentPathToNodePath(rootContentPath);
    final Node rootNode = nodeService.getByPath(rootNodePath);
    return rootNode != null ? rootNode.getPermissions() : AccessControlList.empty();
}
Also used : Node(com.enonic.xp.node.Node) ContentPath(com.enonic.xp.content.ContentPath) NodePath(com.enonic.xp.node.NodePath)

Example 47 with NodePath

use of com.enonic.xp.node.NodePath in project xp by enonic.

the class DeleteContentCommand method doExecute.

private DeleteContentsResult doExecute() {
    this.nodeService.refresh(RefreshMode.ALL);
    final NodePath nodePath = ContentNodeHelper.translateContentPathToNodePath(this.params.getContentPath());
    final Node nodeToDelete = this.nodeService.getByPath(nodePath);
    if (nodeToDelete == null) {
        throw new ContentNotFoundException(this.params.getContentPath(), ContextAccessor.current().getBranch());
    }
    if (!params.isDeleteOnline()) {
        final NodeIds draftChildren = this.nodeService.findByParent(FindNodesByParentParams.create().parentId(nodeToDelete.id()).recursive(true).build()).getNodeIds();
        final boolean anyChildIsMovedIn = nodeService.compare(draftChildren, ContentConstants.BRANCH_MASTER).getComparisons().stream().anyMatch(nodeComparison -> {
            final boolean moved = CompareStatus.MOVED.equals(nodeComparison.getCompareStatus());
            return moved && !nodeComparison.getTargetPath().asAbsolute().toString().startsWith(nodePath.asAbsolute().toString());
        });
        if (anyChildIsMovedIn) {
            throw new RuntimeException(String.format("Cannot make content tree pending delete for [%s], at least one published child is moved in from outside.", nodeToDelete.id()));
        }
    }
    final DeleteContentsResult deletedContents = doDeleteContent(nodeToDelete.id());
    this.nodeService.refresh(RefreshMode.ALL);
    return deletedContents;
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) NodeIds(com.enonic.xp.node.NodeIds) Node(com.enonic.xp.node.Node) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult) NodePath(com.enonic.xp.node.NodePath)

Example 48 with NodePath

use of com.enonic.xp.node.NodePath in project xp by enonic.

the class GetContentByPathCommand method execute.

Content execute() {
    final NodePath nodePath = ContentNodeHelper.translateContentPathToNodePath(contentPath);
    final Node node = nodeService.getByPath(nodePath);
    if (node == null) {
        return null;
    }
    final Content content = translator.fromNode(node, true);
    return filter(content);
}
Also used : Content(com.enonic.xp.content.Content) Node(com.enonic.xp.node.Node) NodePath(com.enonic.xp.node.NodePath)

Example 49 with NodePath

use of com.enonic.xp.node.NodePath in project xp by enonic.

the class MoveContentCommand method doExecute.

private MoveContentsResult doExecute() {
    final ContentId contentId = params.getContentId();
    final Content sourceContent = getContent(contentId);
    final NodePath newParentPath = ContentNodeHelper.translateContentPathToNodePath(params.getParentContentPath());
    if (nodeService.nodeExists(NodePath.create(newParentPath, sourceContent.getName().toString()).build())) {
        throw new ContentAlreadyMovedException(String.format("Content with name [%s] is already a child of [%s]", sourceContent.getName(), params.getParentContentPath()), sourceContent.getPath());
    }
    validateParentChildRelations(params.getParentContentPath(), sourceContent.getType());
    final NodeId sourceNodeId = NodeId.from(contentId);
    final MoveNodeParams.Builder builder = MoveNodeParams.create().nodeId(sourceNodeId).parentNodePath(newParentPath).moveListener(this);
    if (params.stopInherit()) {
        builder.processor(new MoveContentProcessor());
    }
    final Node movedNode = nodeService.move(builder.build());
    final Content movedContent = translator.fromNode(movedNode, true);
    return MoveContentsResult.create().setContentName(movedContent.getDisplayName()).addMoved(movedContent.getId()).build();
}
Also used : MoveNodeParams(com.enonic.xp.node.MoveNodeParams) Content(com.enonic.xp.content.Content) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) ContentId(com.enonic.xp.content.ContentId) ContentAlreadyMovedException(com.enonic.xp.content.ContentAlreadyMovedException) NodePath(com.enonic.xp.node.NodePath)

Example 50 with NodePath

use of com.enonic.xp.node.NodePath in project xp by enonic.

the class ParentContentSynchronizer method doSyncWithChildren.

private void doSyncWithChildren(final Collection<ContentToSync> sourceContents) {
    final Queue<ContentToSync> queue = new ArrayDeque<>(sourceContents);
    final Map<NodePath, Context> targetContexts = !sourceContents.isEmpty() ? initContexts(ProjectName.from(sourceContents.stream().findAny().get().getTargetContext().getRepositoryId())) : Map.of();
    final List<ContentToSync> contentsToSync = sourceContents.stream().filter(sourceContent -> {
        final Content root = sourceContent.getSourceContext().callWith(() -> contentService.getByPath(ContentPath.ROOT));
        return !root.getId().equals(sourceContent.getSourceContent().getId());
    }).collect(Collectors.toList());
    if (!contentsToSync.isEmpty()) {
        this.doSync(contentsToSync);
    }
    while (queue.size() > 0) {
        final ContentToSync currentContentToSync = queue.poll();
        final FindContentByParentResult result = currentContentToSync.getSourceContext().callWith(() -> contentService.findByParent(FindContentByParentParams.create().parentId(currentContentToSync.getId()).recursive(false).childOrder(currentContentToSync.getSourceContent().getChildOrder()).size(-1).build()));
        if (result.getContents().isNotEmpty()) {
            final List<ContentToSync> childrenToSync = result.getContents().stream().map(content -> {
                final Context actualTargetContext = getActualContext(content.getId(), targetContexts.values());
                return ContentToSync.create().sourceContent(content).targetContent(actualTargetContext != null ? actualTargetContext.callWith(() -> contentService.getById(content.getId())) : null).sourceContext(currentContentToSync.getSourceContext()).targetContext(actualTargetContext != null ? actualTargetContext : currentContentToSync.getTargetContext()).build();
            }).collect(Collectors.toList());
            this.doSync(childrenToSync);
            for (final ContentToSync content : childrenToSync) {
                if (content.getSourceContent().hasChildren()) {
                    queue.offer(content);
                }
            }
        }
    }
    sourceContents.forEach(sourceContent -> {
        if (sourceContent.getTargetContent() != null) {
            cleanDeletedContents(sourceContent);
            return;
        }
        final Content root = sourceContent.getSourceContext().callWith(() -> contentService.getByPath(ContentPath.ROOT));
        if (root.getId().equals(sourceContent.getSourceContent().getId())) {
            cleanDeletedContents(ContentToSync.create(sourceContent).targetContent(sourceContent.getTargetContext().callWith(() -> contentService.getByPath(ContentPath.ROOT))).build());
        }
    });
}
Also used : Context(com.enonic.xp.context.Context) ContentService(com.enonic.xp.content.ContentService) ContentConstants(com.enonic.xp.content.ContentConstants) FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) CONTENT_ROOT_PATH_ATTRIBUTE(com.enonic.xp.content.ContentConstants.CONTENT_ROOT_PATH_ATTRIBUTE) Function(java.util.function.Function) LinkedHashMap(java.util.LinkedHashMap) ContentId(com.enonic.xp.content.ContentId) Component(org.osgi.service.component.annotations.Component) ImmutableList(com.google.common.collect.ImmutableList) FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) ContextAccessor(com.enonic.xp.context.ContextAccessor) MediaInfoService(com.enonic.xp.media.MediaInfoService) Map(java.util.Map) ProjectName(com.enonic.xp.project.ProjectName) Activate(org.osgi.service.component.annotations.Activate) ContextBuilder(com.enonic.xp.context.ContextBuilder) User(com.enonic.xp.security.User) ContentPath(com.enonic.xp.content.ContentPath) ArchiveConstants(com.enonic.xp.archive.ArchiveConstants) Collection(java.util.Collection) NodePath(com.enonic.xp.node.NodePath) Set(java.util.Set) Content(com.enonic.xp.content.Content) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Collectors(java.util.stream.Collectors) List(java.util.List) PrincipalKey(com.enonic.xp.security.PrincipalKey) BRANCH_DRAFT(com.enonic.xp.content.ContentConstants.BRANCH_DRAFT) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) Queue(java.util.Queue) ArrayDeque(java.util.ArrayDeque) Reference(org.osgi.service.component.annotations.Reference) FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) Content(com.enonic.xp.content.Content) ArrayDeque(java.util.ArrayDeque) NodePath(com.enonic.xp.node.NodePath)

Aggregations

NodePath (com.enonic.xp.node.NodePath)54 Node (com.enonic.xp.node.Node)27 Test (org.junit.jupiter.api.Test)20 NodeId (com.enonic.xp.node.NodeId)15 InternalContext (com.enonic.xp.repo.impl.InternalContext)12 Content (com.enonic.xp.content.Content)7 Event (com.enonic.xp.event.Event)7 NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)4 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)4 NodeVersionId (com.enonic.xp.node.NodeVersionId)4 ChildOrder (com.enonic.xp.index.ChildOrder)3 NodeIds (com.enonic.xp.node.NodeIds)3 NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)2 ContentId (com.enonic.xp.content.ContentId)2 ContentPath (com.enonic.xp.content.ContentPath)2 CreateContentParams (com.enonic.xp.content.CreateContentParams)2 Context (com.enonic.xp.context.Context)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 MoveNodeParams (com.enonic.xp.node.MoveNodeParams)2 NodeVersion (com.enonic.xp.node.NodeVersion)2