Search in sources :

Example 6 with NodeIds

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

the class DuplicateNodeCommandTest method reference_to_child_in_other_parent_within_duplicate_root.

@Test
public void reference_to_child_in_other_parent_within_duplicate_root() throws Exception {
    final PropertyTree data = new PropertyTree();
    data.addReference("refTo1_2_1", Reference.from("a1_2_1"));
    final Node a1 = createNode(NodePath.ROOT, "a1");
    createNode(CreateNodeParams.create().setNodeId(NodeId.from("a1_1")).name("a1_1").parent(a1.path()).data(data).build());
    final Node a1_2 = createNode(a1.path(), "a1_2");
    createNode(a1_2.path(), "a1_2_1");
    final Node a1Duplicate = duplicateNode(a1).getNode();
    final NodeIds children = findChildren(a1Duplicate).getNodeIds();
    assertEquals(2, children.getSize());
    assertDuplicatedTree(a1.path(), a1, a1Duplicate);
}
Also used : NodeIds(com.enonic.xp.node.NodeIds) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Example 7 with NodeIds

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

the class UnpublishContentCommand method recursiveUnpublish.

private void recursiveUnpublish(final NodeId nodeId, boolean includeChildren, final ContentIds.Builder contentsBuilder) {
    if (includeChildren) {
        final FindNodesByParentResult result = this.nodeService.findByParent(FindNodesByParentParams.create().parentId(nodeId).build());
        result.getNodeIds().forEach((id) -> recursiveUnpublish(id, true, contentsBuilder));
    }
    final NodeIds nodes = this.nodeService.deleteById(nodeId);
    if (nodes != null && nodes.isNotEmpty()) {
        if (params.getPublishContentListener() != null) {
            params.getPublishContentListener().contentPushed(1);
        }
        contentsBuilder.add(ContentId.from(nodes.first().toString()));
    }
}
Also used : NodeIds(com.enonic.xp.node.NodeIds) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult)

Example 8 with NodeIds

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

the class SetPublishInfoCommand method execute.

public void execute() {
    final NodeIds nodeIdsToUpdate = findNodesWithoutPublishFirstAndFrom(nodeIds);
    if (nodeIdsToUpdate.getSize() == 0) {
        return;
    }
    final Instant now = Instant.now();
    final Instant publishFrom = contentPublishInfo.getFrom() == null ? now : contentPublishInfo.getFrom();
    final Instant publishTo = contentPublishInfo.getTo();
    for (final NodeId id : nodeIdsToUpdate) {
        this.nodeService.update(UpdateNodeParams.create().editor(toBeEdited -> {
            PropertySet publishInfo = toBeEdited.data.getSet(ContentPropertyNames.PUBLISH_INFO);
            if (publishInfo == null) {
                publishInfo = toBeEdited.data.addSet(ContentPropertyNames.PUBLISH_INFO);
            }
            if (publishInfo.getInstant(ContentPropertyNames.PUBLISH_FIRST) == null) {
                final Instant publishFromPropertyValue = publishInfo.getInstant(ContentPropertyNames.PUBLISH_FROM);
                if (publishFromPropertyValue == null) {
                    publishInfo.setInstant(ContentPropertyNames.PUBLISH_FIRST, publishFrom);
                } else {
                    // TODO Special case for Enonic XP 6.7 and 6.8 contents. Remove after 7.0
                    publishInfo.setInstant(ContentPropertyNames.PUBLISH_FIRST, publishFromPropertyValue);
                }
            }
            if (publishInfo.getInstant(ContentPropertyNames.PUBLISH_FROM) == null) {
                publishInfo.setInstant(ContentPropertyNames.PUBLISH_FROM, publishFrom);
                if (publishTo == null) {
                    if (publishInfo.hasProperty(ContentPropertyNames.PUBLISH_TO)) {
                        publishInfo.removeProperty(ContentPropertyNames.PUBLISH_TO);
                    }
                } else {
                    publishInfo.setInstant(ContentPropertyNames.PUBLISH_TO, publishTo);
                }
            }
        }).id(id).build());
        if (publishContentListener != null) {
            publishContentListener.contentPushed(1);
        }
    }
    this.nodeService.refresh(RefreshMode.ALL);
}
Also used : RefreshMode(com.enonic.xp.node.RefreshMode) IdFilter(com.enonic.xp.query.filter.IdFilter) ContentIndexPath(com.enonic.xp.content.ContentIndexPath) ContentPropertyNames(com.enonic.xp.content.ContentPropertyNames) PropertySet(com.enonic.xp.data.PropertySet) ExistsFilter(com.enonic.xp.query.filter.ExistsFilter) ContentPublishInfo(com.enonic.xp.content.ContentPublishInfo) Instant(java.time.Instant) NodeId(com.enonic.xp.node.NodeId) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) PushContentListener(com.enonic.xp.content.PushContentListener) BooleanFilter(com.enonic.xp.query.filter.BooleanFilter) NodeQuery(com.enonic.xp.node.NodeQuery) NodeIds(com.enonic.xp.node.NodeIds) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeIds(com.enonic.xp.node.NodeIds) Instant(java.time.Instant) NodeId(com.enonic.xp.node.NodeId) PropertySet(com.enonic.xp.data.PropertySet)

Example 9 with NodeIds

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

the class ContentNodeHelperTest method toContentIds.

@Test
public void toContentIds() {
    final NodeIds nodeIds = NodeIds.from("e1f57280-d672-4cd8-b674-98e26e5b69ae", "45d67001-7f2b-4093-99ae-639be9fdd1f6");
    final ContentIds contentIds = ContentNodeHelper.toContentIds(nodeIds);
    assertEquals(ContentIds.from("e1f57280-d672-4cd8-b674-98e26e5b69ae", "45d67001-7f2b-4093-99ae-639be9fdd1f6"), contentIds);
}
Also used : NodeIds(com.enonic.xp.node.NodeIds) ContentIds(com.enonic.xp.content.ContentIds) Test(org.junit.jupiter.api.Test)

Example 10 with NodeIds

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

the class AbstractDeleteNodeCommand method deleteNodeWithChildren.

NodeBranchEntries deleteNodeWithChildren(final Node node, final Context context, final DeleteNodeListener deleteNodeListener) {
    if (node.isRoot() && !allowDeleteRootNode) {
        throw new OperationNotPermittedException("Not allowed to delete root-node");
    }
    doRefresh();
    final NodeBranchEntries nodesToBeDeleted = newResolveNodesToDelete(node);
    final NodeIds nodeIds = NodeIds.from(nodesToBeDeleted.getKeys());
    final boolean allHasPermissions = NodesHasPermissionResolver.create(this).nodeIds(nodeIds).permission(Permission.DELETE).build().execute();
    if (!allHasPermissions) {
        throw new NodeAccessException(context.getAuthInfo().getUser(), node.path(), Permission.DELETE);
    }
    for (final List<NodeId> keysBatch : Iterables.partition(nodeIds, BATCH_SIZE)) {
        this.nodeStorageService.delete(NodeIds.from(keysBatch), InternalContext.from(context));
        if (deleteNodeListener != null) {
            deleteNodeListener.nodesDeleted(keysBatch.size());
        }
    }
    doRefresh();
    return nodesToBeDeleted;
}
Also used : NodeBranchEntries(com.enonic.xp.node.NodeBranchEntries) NodeAccessException(com.enonic.xp.node.NodeAccessException) NodeIds(com.enonic.xp.node.NodeIds) NodeId(com.enonic.xp.node.NodeId) OperationNotPermittedException(com.enonic.xp.node.OperationNotPermittedException)

Aggregations

NodeIds (com.enonic.xp.node.NodeIds)37 Node (com.enonic.xp.node.Node)12 NodeId (com.enonic.xp.node.NodeId)11 Test (org.junit.jupiter.api.Test)11 NodePath (com.enonic.xp.node.NodePath)6 Collectors (java.util.stream.Collectors)5 CompareStatus (com.enonic.xp.content.CompareStatus)4 ContentIds (com.enonic.xp.content.ContentIds)4 ContextAccessor (com.enonic.xp.context.ContextAccessor)4 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)4 NodeComparison (com.enonic.xp.node.NodeComparison)4 NodeComparisons (com.enonic.xp.node.NodeComparisons)4 NodeQuery (com.enonic.xp.node.NodeQuery)4 Branch (com.enonic.xp.branch.Branch)3 ContentId (com.enonic.xp.content.ContentId)3 DeleteContentsResult (com.enonic.xp.content.DeleteContentsResult)3 Context (com.enonic.xp.context.Context)3 ContentNotFoundException (com.enonic.xp.content.ContentNotFoundException)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 DeleteIssueCommentResult (com.enonic.xp.issue.DeleteIssueCommentResult)2