Search in sources :

Example 1 with ChildOrder

use of com.enonic.xp.index.ChildOrder in project xp by enonic.

the class NodeTest method equals.

@Test
public void equals() {
    NodeName name1 = NodeName.from("name1");
    NodeName name2 = NodeName.from("name2");
    ChildOrder childOrder1 = ChildOrder.defaultOrder();
    ChildOrder childOrder2 = ChildOrder.manualOrder();
    PropertyTree data1 = new PropertyTree();
    data1.addString("some", "config");
    PropertyTree data2 = new PropertyTree();
    data2.addString("other", "config");
    AbstractEqualsTest equalsTest = new AbstractEqualsTest() {

        @Override
        public Object getObjectX() {
            return Node.create().name(name1).data(data1).childOrder(childOrder1).build();
        }

        @Override
        public Object[] getObjectsThatNotEqualsX() {
            Node notX1 = Node.create().name(name2).data(data1).childOrder(childOrder1).build();
            Node notX2 = Node.create().name(name1).data(data2).childOrder(childOrder1).build();
            Node notX3 = Node.create().name(name1).data(data1).childOrder(childOrder2).build();
            return new Object[] { notX1, notX2, notX3 };
        }

        @Override
        public Object getObjectThatEqualsXButNotTheSame() {
            return Node.create().name(name1).data(data1).childOrder(childOrder1).build();
        }

        @Override
        public Object getObjectThatEqualsXButNotTheSame2() {
            return Node.create().name(name1).data(data1).childOrder(childOrder1).build();
        }
    };
    equalsTest.assertEqualsAndHashCodeContract();
}
Also used : ChildOrder(com.enonic.xp.index.ChildOrder) PropertyTree(com.enonic.xp.data.PropertyTree) AbstractEqualsTest(com.enonic.xp.support.AbstractEqualsTest) Test(org.junit.jupiter.api.Test) AbstractEqualsTest(com.enonic.xp.support.AbstractEqualsTest)

Example 2 with ChildOrder

use of com.enonic.xp.index.ChildOrder in project xp by enonic.

the class FindNodeIdsByParentCommand method execute.

public FindNodesByParentResult execute() {
    NodePath parentPath = getParentPath();
    if (parentPath == null) {
        return FindNodesByParentResult.empty();
    }
    final ChildOrder order = NodeChildOrderResolver.create(this).nodePath(parentPath).childOrder(childOrder).build().resolve();
    final SearchResult result = this.nodeSearchService.query(createFindChildrenQuery(parentPath, order), SingleRepoSearchSource.from(ContextAccessor.current()));
    if (result.getNumberOfHits() == 0) {
        return FindNodesByParentResult.create().totalHits(result.getTotalHits()).build();
    }
    return FindNodesByParentResult.create().nodeIds(NodeIds.from(result.getIds())).totalHits(result.getTotalHits()).hits(result.getNumberOfHits()).build();
}
Also used : ChildOrder(com.enonic.xp.index.ChildOrder) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult) NodePath(com.enonic.xp.node.NodePath)

Example 3 with ChildOrder

use of com.enonic.xp.index.ChildOrder in project xp by enonic.

the class FindNodesByParentCommand method execute.

public FindNodesByParentResult execute() {
    NodePath parentPath = params.getParentPath();
    if (parentPath == null) {
        Node parent = GetNodeByIdCommand.create(this).id(params.getParentId()).build().execute();
        if (parent == null) {
            return FindNodesByParentResult.empty();
        }
        parentPath = parent.path();
    }
    final ChildOrder order = NodeChildOrderResolver.create(this).nodePath(parentPath).childOrder(params.getChildOrder()).build().resolve();
    final SearchResult result = this.nodeSearchService.query(NodeQuery.create().parent(parentPath).addQueryFilters(params.getQueryFilters()).from(params.getFrom()).size(params.getSize()).searchMode(params.isCountOnly() ? SearchMode.COUNT : SearchMode.SEARCH).setOrderExpressions(order.getOrderExpressions()).accurateScoring(true).build(), SingleRepoSearchSource.from(ContextAccessor.current()));
    if (result.isEmpty()) {
        return FindNodesByParentResult.create().hits(0).totalHits(result.getTotalHits()).nodeIds(NodeIds.empty()).build();
    }
    return FindNodesByParentResult.create().nodeIds(NodeIds.from(result.getIds())).totalHits(result.getTotalHits()).hits(result.getNumberOfHits()).build();
}
Also used : Node(com.enonic.xp.node.Node) ChildOrder(com.enonic.xp.index.ChildOrder) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult) NodePath(com.enonic.xp.node.NodePath)

Example 4 with ChildOrder

use of com.enonic.xp.index.ChildOrder in project xp by enonic.

the class NodeServiceImplTest method testReorderChildren.

@Test
public void testReorderChildren() {
    final Node parent = createNode(CreateNodeParams.create().name("my-parent").parent(NodePath.ROOT).childOrder(ChildOrder.manualOrder()).build());
    final Node child1 = createNode(CreateNodeParams.create().name("my-child-1").parent(parent.path()).build());
    final Node child2 = createNode(CreateNodeParams.create().name("my-child-2").parent(parent.path()).build());
    final Node child3 = createNode(CreateNodeParams.create().name("my-child-3").parent(parent.path()).build());
    final ReorderChildNodesParams params = ReorderChildNodesParams.create().add(ReorderChildNodeParams.create().nodeId(child1.id()).moveBefore(child2.id()).build()).add(ReorderChildNodeParams.create().nodeId(child3.id()).moveBefore(child1.id()).build()).processor(data -> {
        data.addString("processedValue", "value");
        return data;
    }).build();
    final ReorderChildNodesResult result = this.nodeService.reorderChildren(params);
    assertThat(result.getNodeIds()).containsExactly(child1.id(), child3.id());
    assertThat(result.getParentNodes().getIds()).containsExactly(parent.id());
    assertThat(nodeService.findByParent(FindNodesByParentParams.create().parentId(parent.id()).build()).getNodeIds()).containsExactly(child3.id(), child1.id(), child2.id());
    nodeService.refresh(RefreshMode.ALL);
    final Node processedParent = this.nodeService.getById(parent.id());
    assertEquals("value", processedParent.data().getString("processedValue"));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) IdProviderKey(com.enonic.xp.security.IdProviderKey) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Permission(com.enonic.xp.security.acl.Permission) NodeCommitId(com.enonic.xp.node.NodeCommitId) ContextAccessor(com.enonic.xp.context.ContextAccessor) NodeVersionsMetadata(com.enonic.xp.node.NodeVersionsMetadata) ContextBuilder(com.enonic.xp.context.ContextBuilder) BinaryReference(com.enonic.xp.util.BinaryReference) User(com.enonic.xp.security.User) NodeIndexPath(com.enonic.xp.node.NodeIndexPath) CreateRootNodeParams(com.enonic.xp.node.CreateRootNodeParams) Instant(java.time.Instant) AccessControlList(com.enonic.xp.security.acl.AccessControlList) NodeId(com.enonic.xp.node.NodeId) RenameNodeParams(com.enonic.xp.node.RenameNodeParams) Test(org.junit.jupiter.api.Test) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) OrderExpr(com.enonic.xp.query.expr.OrderExpr) RoutableNodeVersionId(com.enonic.xp.node.RoutableNodeVersionId) ReorderChildNodesResult(com.enonic.xp.node.ReorderChildNodesResult) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) ChildOrder(com.enonic.xp.index.ChildOrder) RefreshMode(com.enonic.xp.node.RefreshMode) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) EventPublisher(com.enonic.xp.event.EventPublisher) RoutableNodeVersionIds(com.enonic.xp.node.RoutableNodeVersionIds) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Node(com.enonic.xp.node.Node) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) DuplicateNodeParams(com.enonic.xp.node.DuplicateNodeParams) NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) ReorderChildNodesParams(com.enonic.xp.node.ReorderChildNodesParams) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) FieldOrderExpr(com.enonic.xp.query.expr.FieldOrderExpr) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) PropertyTree(com.enonic.xp.data.PropertyTree) Iterator(java.util.Iterator) NodePath(com.enonic.xp.node.NodePath) IOException(java.io.IOException) ReorderChildNodeParams(com.enonic.xp.node.ReorderChildNodeParams) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) GetNodeVersionsParams(com.enonic.xp.node.GetNodeVersionsParams) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Mockito(org.mockito.Mockito) NodeName(com.enonic.xp.node.NodeName) BranchNotFoundException(com.enonic.xp.repository.BranchNotFoundException) PrincipalKey(com.enonic.xp.security.PrincipalKey) MoveNodeParams(com.enonic.xp.node.MoveNodeParams) NodeIds(com.enonic.xp.node.NodeIds) RepositoryNotFoundException(com.enonic.xp.repository.RepositoryNotFoundException) ReorderChildNodesParams(com.enonic.xp.node.ReorderChildNodesParams) Node(com.enonic.xp.node.Node) ReorderChildNodesResult(com.enonic.xp.node.ReorderChildNodesResult) Test(org.junit.jupiter.api.Test)

Example 5 with ChildOrder

use of com.enonic.xp.index.ChildOrder in project xp by enonic.

the class NodeServiceImplTest method create.

@Test
public void create() throws Exception {
    final ChildOrder childOrder = ChildOrder.create().add(FieldOrderExpr.create(NodeIndexPath.TIMESTAMP, OrderExpr.Direction.DESC)).add(FieldOrderExpr.create(NodeIndexPath.NAME, OrderExpr.Direction.ASC)).build();
    final AccessControlList aclList = AccessControlList.create().add(AccessControlEntry.create().principal(PrincipalKey.from("user:myidprovider:rmy")).allow(Permission.READ).build()).build();
    final CreateNodeParams params = CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).permissions(aclList).childOrder(childOrder).build();
    final Node node = this.nodeService.create(params);
    refresh();
    assertTrue(node.getPermissions() != null);
    assertEquals(aclList, node.getPermissions());
    assertEquals(childOrder, node.getChildOrder());
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) ChildOrder(com.enonic.xp.index.ChildOrder) Node(com.enonic.xp.node.Node) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Test(org.junit.jupiter.api.Test)

Aggregations

ChildOrder (com.enonic.xp.index.ChildOrder)10 Test (org.junit.jupiter.api.Test)6 Node (com.enonic.xp.node.Node)4 NodePath (com.enonic.xp.node.NodePath)4 PropertyTree (com.enonic.xp.data.PropertyTree)2 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)2 SearchResult (com.enonic.xp.repo.impl.search.result.SearchResult)2 AccessControlList (com.enonic.xp.security.acl.AccessControlList)2 Context (com.enonic.xp.context.Context)1 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1 EventPublisher (com.enonic.xp.event.EventPublisher)1 CreateRootNodeParams (com.enonic.xp.node.CreateRootNodeParams)1 DuplicateNodeParams (com.enonic.xp.node.DuplicateNodeParams)1 FindNodesByParentParams (com.enonic.xp.node.FindNodesByParentParams)1 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)1 GetNodeVersionsParams (com.enonic.xp.node.GetNodeVersionsParams)1 MoveNodeParams (com.enonic.xp.node.MoveNodeParams)1 NodeCommitEntry (com.enonic.xp.node.NodeCommitEntry)1 NodeCommitId (com.enonic.xp.node.NodeCommitId)1