Search in sources :

Example 36 with FindNodesByParentResult

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

the class FindNodesByParentCommandTest method size.

@Test
public void size() throws Exception {
    this.createDefaultRootNode();
    final Node createdNode = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("my-node").build());
    int size = 20;
    createChildren(createdNode, size);
    FindNodesByParentResult children = findByParent(FindNodesByParentParams.create().parentPath(createdNode.path()).size(9).build());
    assertEquals(9, children.getHits());
    children = findByParent(FindNodesByParentParams.create().parentPath(createdNode.path()).size(100).build());
    assertEquals(20, children.getHits());
}
Also used : Node(com.enonic.xp.node.Node) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) Test(org.junit.jupiter.api.Test)

Example 37 with FindNodesByParentResult

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

the class FindNodesByParentCommandTest method getChildren.

@Test
public void getChildren() throws Exception {
    this.createDefaultRootNode();
    final String nodeName = "my-node";
    final Node createdNode = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name(nodeName).build());
    createNode(CreateNodeParams.create().parent(createdNode.path()).name("my-child1").build());
    createNode(CreateNodeParams.create().parent(createdNode.path()).name("my-child2").build());
    refresh();
    final FindNodesByParentResult children = findByParent(FindNodesByParentParams.create().parentPath(createdNode.path()).build());
    assertEquals(2, children.getHits());
    assertEquals(2, children.getNodeIds().getSize());
}
Also used : Node(com.enonic.xp.node.Node) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) Test(org.junit.jupiter.api.Test)

Example 38 with FindNodesByParentResult

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

the class FindNodesByParentCommandTest method get_children_order.

@Test
public void get_children_order() throws Exception {
    this.createDefaultRootNode();
    final Node createdNode = createNode(CreateNodeParams.create().setNodeId(NodeId.from("parent")).name("my-node").parent(NodePath.ROOT).childOrder(ChildOrder.from(NodeIndexPath.NAME + " ASC")).build());
    final Node childNode_b_3 = createNode(CreateNodeParams.create().setNodeId(NodeId.from("childnode_b_3")).parent(createdNode.path()).name("b").data(createOrderProperty(3.0)).build());
    final Node childNode_a_2 = createNode(CreateNodeParams.create().setNodeId(NodeId.from("childnode_a_2")).parent(createdNode.path()).name("a").data(createOrderProperty(2.0)).build());
    final Node childNode_c_1 = createNode(CreateNodeParams.create().setNodeId(NodeId.from("childnode_c_1")).parent(createdNode.path()).name("c").data(createOrderProperty(1.0)).build());
    refresh();
    // Use default parent ordering; name
    FindNodesByParentResult result = FindNodesByParentCommand.create().params(FindNodesByParentParams.create().parentPath(createdNode.path()).build()).indexServiceInternal(indexServiceInternal).storageService(this.storageService).searchService(this.searchService).build().execute();
    Nodes childNodes = GetNodesByIdsCommand.create().ids(result.getNodeIds()).indexServiceInternal(indexServiceInternal).storageService(storageService).searchService(searchService).build().execute();
    assertEquals(3, childNodes.getSize());
    Iterator<Node> iterator = childNodes.iterator();
    assertEquals(childNode_a_2, iterator.next());
    assertEquals(childNode_b_3, iterator.next());
    assertEquals(childNode_c_1, iterator.next());
    // Override by specify childOrder-parameter by order-field
    result = FindNodesByParentCommand.create().params(FindNodesByParentParams.create().parentPath(createdNode.path()).childOrder(ChildOrder.from("order ASC")).build()).indexServiceInternal(indexServiceInternal).storageService(this.storageService).searchService(this.searchService).build().execute();
    childNodes = GetNodesByIdsCommand.create().ids(result.getNodeIds()).indexServiceInternal(indexServiceInternal).storageService(storageService).searchService(searchService).build().execute();
    assertEquals(3, childNodes.getSize());
    iterator = childNodes.iterator();
    assertEquals(childNode_c_1, iterator.next());
    assertEquals(childNode_a_2, iterator.next());
    assertEquals(childNode_b_3, iterator.next());
}
Also used : Node(com.enonic.xp.node.Node) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) Nodes(com.enonic.xp.node.Nodes) Test(org.junit.jupiter.api.Test)

Example 39 with FindNodesByParentResult

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

the class FindNodeIdsByParentCommandTest method find_after_move_to_folder_with_same_name.

@Test
public void find_after_move_to_folder_with_same_name() throws Exception {
    final Node node = createNode(CreateNodeParams.create().setNodeId(NodeId.from("node")).parent(NodePath.ROOT).name("node").build());
    final Node node1_1 = createNode(CreateNodeParams.create().setNodeId(NodeId.from("node1_1")).parent(node.path()).name("node1_1").build());
    createNode(CreateNodeParams.create().setNodeId(NodeId.from("node1_1_1")).parent(node1_1.path()).name("node1_1_1").build());
    final Node node2 = createNode(CreateNodeParams.create().setNodeId(NodeId.from("node1")).parent(NodePath.ROOT).name("node1").build());
    refresh();
    MoveNodeCommand.create().newParent(node2.path()).id(node1_1.id()).indexServiceInternal(indexServiceInternal).searchService(searchService).storageService(storageService).build().execute();
    final FindNodesByParentResult children = FindNodeIdsByParentCommand.create().parentPath(node.path()).recursive(true).searchService(this.searchService).storageService(this.storageService).indexServiceInternal(this.indexServiceInternal).build().execute();
    assertEquals(0, children.getNodeIds().getSize());
}
Also used : Node(com.enonic.xp.node.Node) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) Test(org.junit.jupiter.api.Test)

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