Search in sources :

Example 81 with NodeId

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

the class ApplyContentPermissionsCommand method execute.

ApplyContentPermissionsResult execute() {
    final NodeId nodeId = NodeId.from(params.getContentId().toString());
    final ApplyNodePermissionsParams applyNodePermissionsParams = ApplyNodePermissionsParams.create().nodeId(nodeId).permissions(params.getPermissions()).inheritPermissions(params.isInheritPermissions()).overwriteChildPermissions(params.isOverwriteChildPermissions()).applyPermissionsListener(params.getListener()).build();
    final ApplyNodePermissionsResult result = nodeService.applyPermissions(applyNodePermissionsParams);
    return ApplyContentPermissionsResult.create().setSucceedContents(ContentNodeHelper.translateNodePathsToContentPaths(result.getSucceedNodes().getPaths())).setSkippedContents(ContentNodeHelper.translateNodePathsToContentPaths(result.getSkippedNodes().getPaths())).build();
}
Also used : ApplyNodePermissionsParams(com.enonic.xp.node.ApplyNodePermissionsParams) NodeId(com.enonic.xp.node.NodeId) ApplyNodePermissionsResult(com.enonic.xp.node.ApplyNodePermissionsResult)

Example 82 with NodeId

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

the class DeleteContentCommand method deleteNodeInDraftAndMaster.

private void deleteNodeInDraftAndMaster(final NodeId nodeToDelete, final DeleteContentsResult.Builder result) {
    final Context draftContext = ContextAccessor.current();
    final Context masterContext = ContextBuilder.from(draftContext).branch(ContentConstants.BRANCH_MASTER).build();
    final Node draftRootNode = nodeService.getById(nodeToDelete);
    final NodeIds draftNodes = deleteNodeInContext(nodeToDelete, draftContext);
    final NodeIds masterNodes = deleteNodeInContext(nodeToDelete, masterContext);
    result.addDeleted(ContentIds.from(draftNodes.getAsStrings()));
    result.addUnpublished(ContentIds.from(masterNodes.getAsStrings()));
    final NodeIds masterIdsByDraftPath = masterContext.callWith(() -> this.nodeService.findByParent(FindNodesByParentParams.create().parentPath(draftRootNode.path()).recursive(true).build()).getNodeIds());
    Stream.concat(masterIdsByDraftPath.stream(), draftNodes.stream()).filter(id -> !masterNodes.contains(id)).forEach(id -> {
        deleteNodeInContext(id, masterContext);
        result.addUnpublished(ContentId.from(id.toString()));
    });
}
Also used : Context(com.enonic.xp.context.Context) RefreshMode(com.enonic.xp.node.RefreshMode) ContentConstants(com.enonic.xp.content.ContentConstants) Node(com.enonic.xp.node.Node) NodeComparison(com.enonic.xp.node.NodeComparison) Branch(com.enonic.xp.branch.Branch) DeleteContentParams(com.enonic.xp.content.DeleteContentParams) ContentId(com.enonic.xp.content.ContentId) ContextAccessor(com.enonic.xp.context.ContextAccessor) ContextBuilder(com.enonic.xp.context.ContextBuilder) ContentAccessException(com.enonic.xp.content.ContentAccessException) NodePath(com.enonic.xp.node.NodePath) ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) NodeId(com.enonic.xp.node.NodeId) SetNodeStateParams(com.enonic.xp.node.SetNodeStateParams) Stream(java.util.stream.Stream) NodeState(com.enonic.xp.node.NodeState) ContentIds(com.enonic.xp.content.ContentIds) DeleteNodeListener(com.enonic.xp.node.DeleteNodeListener) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) NodeAccessException(com.enonic.xp.node.NodeAccessException) Preconditions(com.google.common.base.Preconditions) Context(com.enonic.xp.context.Context) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult) NodeIds(com.enonic.xp.node.NodeIds) CompareStatus(com.enonic.xp.content.CompareStatus) NodeIds(com.enonic.xp.node.NodeIds) Node(com.enonic.xp.node.Node)

Example 83 with NodeId

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

the class GetContentByIdAndVersionIdCommand method execute.

public Content execute() {
    final NodeId nodeId = NodeId.from(contentId.toString());
    final NodeVersionId nodeVersionId = NodeVersionId.from(versionId.toString());
    try {
        return getContentByIdAndVersionId(nodeId, nodeVersionId);
    } catch (NodeNotFoundException e) {
        throw createContentNotFoundException();
    }
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) NodeVersionId(com.enonic.xp.node.NodeVersionId) NodeId(com.enonic.xp.node.NodeId)

Example 84 with NodeId

use of com.enonic.xp.node.NodeId 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 85 with NodeId

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

the class ResolveContentsToBePublishedCommand method getWorkResult.

private ResolveSyncWorkResult getWorkResult(final ContentId contentId) {
    final NodeIds nodeIds = excludedContentIds != null ? NodeIds.from(excludedContentIds.stream().map(id -> NodeId.from(id.toString())).collect(Collectors.toList())) : NodeIds.empty();
    final boolean includeChildren = excludeChildrenIds == null || !this.excludeChildrenIds.contains(contentId);
    return nodeService.resolveSyncWork(SyncWorkResolverParams.create().includeChildren(includeChildren).includeDependencies(this.includeDependencies).nodeId(NodeId.from(contentId.toString())).excludedNodeIds(nodeIds).branch(this.target).statusesToStopDependenciesSearch(Set.of(CompareStatus.EQUAL)).build());
}
Also used : ContentId(com.enonic.xp.content.ContentId) ResolveSyncWorkResult(com.enonic.xp.node.ResolveSyncWorkResult) ContentIds(com.enonic.xp.content.ContentIds) Set(java.util.Set) Preconditions(com.google.common.base.Preconditions) Collectors(java.util.stream.Collectors) Branch(com.enonic.xp.branch.Branch) NodeIds(com.enonic.xp.node.NodeIds) CompareContentResults(com.enonic.xp.content.CompareContentResults) CompareStatus(com.enonic.xp.content.CompareStatus) NodeId(com.enonic.xp.node.NodeId) SyncWorkResolverParams(com.enonic.xp.node.SyncWorkResolverParams) NodeIds(com.enonic.xp.node.NodeIds)

Aggregations

NodeId (com.enonic.xp.node.NodeId)91 Node (com.enonic.xp.node.Node)44 Test (org.junit.jupiter.api.Test)36 NodePath (com.enonic.xp.node.NodePath)23 InternalContext (com.enonic.xp.repo.impl.InternalContext)18 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)15 NodeIds (com.enonic.xp.node.NodeIds)14 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)11 Context (com.enonic.xp.context.Context)10 PropertyTree (com.enonic.xp.data.PropertyTree)10 Branch (com.enonic.xp.branch.Branch)9 ContextAccessor (com.enonic.xp.context.ContextAccessor)9 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)9 NodeVersionId (com.enonic.xp.node.NodeVersionId)9 NodeVersionMetadata (com.enonic.xp.node.NodeVersionMetadata)8 RefreshMode (com.enonic.xp.node.RefreshMode)8 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)8 ContextBuilder (com.enonic.xp.context.ContextBuilder)6 Event (com.enonic.xp.event.Event)6 RenameNodeParams (com.enonic.xp.node.RenameNodeParams)6