Search in sources :

Example 6 with NodeId

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

the class CompareContentCommand method execute.

public CompareContentResult execute() {
    final NodeId nodeId = NodeId.from(contentId.toString());
    final NodeComparison compareResult = this.nodeService.compare(nodeId, this.target);
    return CompareResultTranslator.translate(compareResult);
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) NodeId(com.enonic.xp.node.NodeId)

Example 7 with NodeId

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

the class DeleteContentCommand method doDeleteContent.

private DeleteContentsResult doDeleteContent(NodeId nodeToDelete) {
    final CompareStatus rootNodeStatus = getCompareStatus(nodeToDelete);
    final DeleteContentsResult.Builder result = DeleteContentsResult.create();
    if (rootNodeStatus == CompareStatus.NEW) {
        // Root node is new, just delete all children
        final NodeIds nodes = this.nodeService.deleteById(nodeToDelete, this);
        result.addDeleted(ContentIds.from(nodes.getAsStrings()));
    } else if (this.params.isDeleteOnline()) {
        deleteNodeInDraftAndMaster(nodeToDelete, result);
    } else {
        this.nodeService.setNodeState(SetNodeStateParams.create().nodeId(nodeToDelete).nodeState(NodeState.PENDING_DELETE).build());
        result.addPending(ContentId.from(nodeToDelete.toString()));
        this.nodesDeleted(1);
        final NodeIds children = getDirectChildren(nodeToDelete);
        for (final NodeId child : children) {
            final DeleteContentsResult childDeleteResult = this.doDeleteContent(child);
            result.addDeleted(childDeleteResult.getDeletedContents());
            result.addPending(childDeleteResult.getPendingContents());
        }
    }
    return result.build();
}
Also used : NodeIds(com.enonic.xp.node.NodeIds) CompareStatus(com.enonic.xp.content.CompareStatus) NodeId(com.enonic.xp.node.NodeId) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult)

Example 8 with NodeId

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

the class DuplicateContentCommand method doExecute.

private DuplicateContentsResult doExecute() {
    final NodeId sourceNodeId = NodeId.from(params.getContentId());
    final Node sourceNode = nodeService.getById(sourceNodeId);
    if (sourceNode == null) {
        throw new IllegalArgumentException(String.format("Content with id [%s] not found", params.getContentId()));
    }
    final DuplicateNodeParams duplicateNodeParams = DuplicateNodeParams.create().duplicateListener(this).nodeId(sourceNodeId).dataProcessor(new DuplicateContentProcessor()).includeChildren(params.getIncludeChildren()).build();
    final Node duplicatedNode = nodeService.duplicate(duplicateNodeParams);
    final Content duplicatedContent = translator.fromNode(duplicatedNode, true);
    final ContentIds childrenIds = params.getIncludeChildren() ? getAllChildren(duplicatedContent) : ContentIds.empty();
    return DuplicateContentsResult.create().setSourceContentPath(ContentNodeHelper.translateNodePathToContentPath(sourceNode.path())).setContentName(duplicatedContent.getDisplayName()).addDuplicated(duplicatedContent.getId()).addDuplicated(childrenIds).build();
}
Also used : DuplicateNodeParams(com.enonic.xp.node.DuplicateNodeParams) Content(com.enonic.xp.content.Content) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) ContentIds(com.enonic.xp.content.ContentIds)

Example 9 with NodeId

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

the class FindContentByParentCommand method setNodePathOrIdAsIdentifier.

private void setNodePathOrIdAsIdentifier(final FindNodesByParentParams.Builder findNodesParam) {
    if (params.getParentPath() == null && params.getParentId() == null) {
        final NodePath parentPath = ContentNodeHelper.getContentRoot();
        findNodesParam.parentPath(parentPath);
    } else if (params.getParentPath() != null) {
        final NodePath parentPath = ContentNodeHelper.translateContentPathToNodePath(params.getParentPath());
        findNodesParam.parentPath(parentPath);
    } else {
        final NodeId parentId = NodeId.from(params.getParentId().toString());
        findNodesParam.parentId(parentId);
    }
}
Also used : NodeId(com.enonic.xp.node.NodeId) NodePath(com.enonic.xp.node.NodePath)

Example 10 with NodeId

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

the class FindContentIdsByParentCommand method setNodePathOrIdAsIdentifier.

private void setNodePathOrIdAsIdentifier(final FindNodesByParentParams.Builder findNodesParam) {
    if (params.getParentPath() == null && params.getParentId() == null) {
        final NodePath parentPath = ContentNodeHelper.getContentRoot();
        findNodesParam.parentPath(parentPath);
    } else if (params.getParentPath() != null) {
        final NodePath parentPath = ContentNodeHelper.translateContentPathToNodePath(params.getParentPath());
        findNodesParam.parentPath(parentPath);
    } else {
        final NodeId parentId = NodeId.from(params.getParentId().toString());
        findNodesParam.parentId(parentId);
    }
}
Also used : NodeId(com.enonic.xp.node.NodeId) NodePath(com.enonic.xp.node.NodePath)

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