Search in sources :

Example 16 with FindNodesByParentResult

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

the class MoveNodeCommandTest method move_to_manually_ordered_parent.

@Test
public void move_to_manually_ordered_parent() throws Exception {
    final Node originalRoot = createNode(NodePath.ROOT, "a1");
    final Node a1_1 = createNode(originalRoot.path(), "a1_1");
    final Node a1_2 = createNode(originalRoot.path(), "a1_2");
    final Node newParent = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("a2").childOrder(ChildOrder.manualOrder()).build());
    final Node a2_1 = createNode(newParent.path(), "a2_1");
    final Node a2_2 = createNode(newParent.path(), "a2_2");
    doMoveNode(newParent.path(), a1_1.id());
    doMoveNode(newParent.path(), a1_2.id());
    final FindNodesByParentResult result = findByParent(FindNodesByParentParams.create().parentId(newParent.id()).build());
    final Iterator<NodeId> iterator = result.getNodeIds().iterator();
    assertEquals(a1_2.id(), iterator.next());
    assertEquals(a1_1.id(), iterator.next());
    assertEquals(a2_2.id(), iterator.next());
    assertEquals(a2_1.id(), iterator.next());
}
Also used : Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) Test(org.junit.jupiter.api.Test)

Example 17 with FindNodesByParentResult

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

the class NodeExporter method doExportChildNodes.

private void doExportChildNodes(final NodePath parentPath) {
    final Node parentNode = nodeService.getByPath(parentPath);
    final FindNodesByParentResult children = doExport(parentPath);
    final Nodes childNodes = this.nodeService.getByIds(children.getNodeIds());
    writeNodeOrderList(parentNode, childNodes);
}
Also used : Node(com.enonic.xp.node.Node) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) Nodes(com.enonic.xp.node.Nodes)

Example 18 with FindNodesByParentResult

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

the class NodeExporter method doExport.

private FindNodesByParentResult doExport(final NodePath nodePath) {
    final FindNodesByParentResult children = nodeService.findByParent(FindNodesByParentParams.create().parentPath(nodePath).build());
    final Nodes childNodes = this.nodeService.getByIds(children.getNodeIds());
    for (final Node child : childNodes) {
        try {
            exportNode(child);
        } catch (Exception e) {
            LOG.error(String.format("Failed to export node with path [%s]", child.path()), e);
            result.addError(new ExportError(e.toString()));
        }
    }
    return children;
}
Also used : Node(com.enonic.xp.node.Node) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) ExportError(com.enonic.xp.export.ExportError) Nodes(com.enonic.xp.node.Nodes)

Example 19 with FindNodesByParentResult

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

the class ArchiveContentCommand method updateProperties.

private Node updateProperties(final NodeId nodeId) {
    final FindNodesByParentResult childrenToArchive = nodeService.findByParent(FindNodesByParentParams.create().size(-1).recursive(true).parentId(nodeId).build());
    final Instant now = Instant.now();
    final String archivedBy = getCurrentUser().getKey().toString();
    childrenToArchive.getNodeIds().forEach(id -> nodeService.update(UpdateNodeParams.create().id(id).editor(toBeEdited -> {
        toBeEdited.data.setInstant(ARCHIVED_TIME, now);
        toBeEdited.data.setString(ARCHIVED_BY, archivedBy);
    }).build()));
    return nodeService.update(UpdateNodeParams.create().id(nodeId).editor(toBeEdited -> {
        toBeEdited.data.setString(ORIGINAL_PARENT_PATH, ContentNodeHelper.translateNodePathToContentPath(toBeEdited.source.parentPath()).toString());
        toBeEdited.data.setString(ORIGINAL_NAME, toBeEdited.source.name().toString());
        toBeEdited.data.setInstant(ARCHIVED_TIME, now);
        toBeEdited.data.setString(ARCHIVED_BY, archivedBy);
    }).build());
}
Also used : RefreshMode(com.enonic.xp.node.RefreshMode) MoveNodeException(com.enonic.xp.node.MoveNodeException) ContentConstants(com.enonic.xp.content.ContentConstants) Node(com.enonic.xp.node.Node) ORIGINAL_PARENT_PATH(com.enonic.xp.content.ContentPropertyNames.ORIGINAL_PARENT_PATH) ArchiveContentException(com.enonic.xp.archive.ArchiveContentException) ArchiveContentListener(com.enonic.xp.archive.ArchiveContentListener) ORIGINAL_NAME(com.enonic.xp.content.ContentPropertyNames.ORIGINAL_NAME) ArchiveContentsResult(com.enonic.xp.archive.ArchiveContentsResult) ContextAccessor(com.enonic.xp.context.ContextAccessor) EnumSet(java.util.EnumSet) User(com.enonic.xp.security.User) ContentAccessException(com.enonic.xp.content.ContentAccessException) ArchiveConstants(com.enonic.xp.archive.ArchiveConstants) ContentInheritType(com.enonic.xp.content.ContentInheritType) UnpublishContentParams(com.enonic.xp.content.UnpublishContentParams) NodePath(com.enonic.xp.node.NodePath) ARCHIVED_BY(com.enonic.xp.content.ContentPropertyNames.ARCHIVED_BY) Instant(java.time.Instant) ZoneId(java.time.ZoneId) NodeId(com.enonic.xp.node.NodeId) MoveNodeListener(com.enonic.xp.node.MoveNodeListener) RenameNodeParams(com.enonic.xp.node.RenameNodeParams) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) NodeName(com.enonic.xp.node.NodeName) ContentIds(com.enonic.xp.content.ContentIds) DateTimeFormatter(java.time.format.DateTimeFormatter) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) NodeAccessException(com.enonic.xp.node.NodeAccessException) Preconditions(com.google.common.base.Preconditions) ArchiveContentParams(com.enonic.xp.archive.ArchiveContentParams) Context(com.enonic.xp.context.Context) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) MoveNodeParams(com.enonic.xp.node.MoveNodeParams) ARCHIVED_TIME(com.enonic.xp.content.ContentPropertyNames.ARCHIVED_TIME) Instant(java.time.Instant) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult)

Example 20 with FindNodesByParentResult

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

the class AbstractArchiveCommand method commitNode.

protected void commitNode(final NodeId nodeId, final String message) {
    final NodeCommitEntry commitEntry = NodeCommitEntry.create().message(message).build();
    nodeService.refresh(RefreshMode.ALL);
    final FindNodesByParentResult movedTree = nodeService.findByParent(FindNodesByParentParams.create().size(-1).recursive(true).parentId(nodeId).build());
    nodeService.commit(commitEntry, NodeIds.create().addAll(movedTree.getNodeIds()).add(nodeId).build());
}
Also used : NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult)

Aggregations

FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)39 Node (com.enonic.xp.node.Node)28 Test (org.junit.jupiter.api.Test)17 NodeId (com.enonic.xp.node.NodeId)14 Nodes (com.enonic.xp.node.Nodes)9 FindNodesByParentParams (com.enonic.xp.node.FindNodesByParentParams)5 Context (com.enonic.xp.context.Context)3 ContextAccessor (com.enonic.xp.context.ContextAccessor)3 NodeBranchEntries (com.enonic.xp.node.NodeBranchEntries)3 RefreshMode (com.enonic.xp.node.RefreshMode)3 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)3 ArchiveConstants (com.enonic.xp.archive.ArchiveConstants)2 Branch (com.enonic.xp.branch.Branch)2 ContentAccessException (com.enonic.xp.content.ContentAccessException)2 ContentConstants (com.enonic.xp.content.ContentConstants)2 ContentIds (com.enonic.xp.content.ContentIds)2 ContentInheritType (com.enonic.xp.content.ContentInheritType)2 ARCHIVED_BY (com.enonic.xp.content.ContentPropertyNames.ARCHIVED_BY)2 ARCHIVED_TIME (com.enonic.xp.content.ContentPropertyNames.ARCHIVED_TIME)2 ORIGINAL_NAME (com.enonic.xp.content.ContentPropertyNames.ORIGINAL_NAME)2