Search in sources :

Example 1 with ReorderChildNodesResult

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

the class ContentServiceImpl method reorderChildren.

@Override
public ReorderChildContentsResult reorderChildren(final ReorderChildContentsParams params) {
    final ReorderChildNodesParams.Builder builder = ReorderChildNodesParams.create();
    for (final ReorderChildParams param : params) {
        builder.add(ReorderChildNodeParams.create().nodeId(NodeId.from(param.getContentToMove())).moveBefore(param.getContentToMoveBefore() == null ? null : NodeId.from(param.getContentToMoveBefore())).build());
    }
    if (params.stopInherit()) {
        builder.processor(new SetContentChildOrderProcessor());
    }
    final ReorderChildNodesResult reorderChildNodesResult = this.nodeService.reorderChildren(builder.build());
    this.nodeService.refresh(RefreshMode.SEARCH);
    final ReorderChildContentsResult result = new ReorderChildContentsResult(reorderChildNodesResult.getSize());
    contentAuditLogSupport.reorderChildren(params, result);
    return result;
}
Also used : ReorderChildParams(com.enonic.xp.content.ReorderChildParams) ReorderChildNodesParams(com.enonic.xp.node.ReorderChildNodesParams) ReorderChildNodesResult(com.enonic.xp.node.ReorderChildNodesResult) ReorderChildContentsResult(com.enonic.xp.content.ReorderChildContentsResult)

Example 2 with ReorderChildNodesResult

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

the class ReorderChildNodesCommand method execute.

public ReorderChildNodesResult execute() {
    final ReorderChildNodesResult.Builder result = ReorderChildNodesResult.create();
    final List<Node> parents = new ArrayList<>();
    for (final ReorderChildNodeParams reorderChildNodeParams : params) {
        RefreshCommand.create().refreshMode(RefreshMode.SEARCH).indexServiceInternal(this.indexServiceInternal).build().execute();
        final Node nodeToMove = doGetById(reorderChildNodeParams.getNodeId());
        final Node nodeToMoveBefore = reorderChildNodeParams.getMoveBefore() == null ? null : doGetById(reorderChildNodeParams.getMoveBefore());
        final Node parentNode = parents.stream().filter(node -> node.path().equals(nodeToMove.parentPath())).findAny().orElse(GetNodeByPathCommand.create(this).nodePath(nodeToMove.parentPath()).build().execute());
        final Node reorderedNode = ReorderChildNodeCommand.create().indexServiceInternal(this.indexServiceInternal).searchService(this.nodeSearchService).storageService(this.nodeStorageService).parentNode(parentNode).nodeToMove(nodeToMove).nodeToMoveBefore(nodeToMoveBefore).build().execute();
        result.addNodeId(reorderedNode.id());
        if (parents.stream().noneMatch(parent -> parent.id().equals(parentNode.id()))) {
            parents.add(parentNode);
        }
    }
    parents.forEach(this::processParent);
    parents.forEach(result::addParentNode);
    return result.build();
}
Also used : Node(com.enonic.xp.node.Node) ArrayList(java.util.ArrayList) ReorderChildNodeParams(com.enonic.xp.node.ReorderChildNodeParams) ReorderChildNodesResult(com.enonic.xp.node.ReorderChildNodesResult)

Example 3 with ReorderChildNodesResult

use of com.enonic.xp.node.ReorderChildNodesResult 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 4 with ReorderChildNodesResult

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

the class NodeServiceImpl method reorderChildren.

@Override
public ReorderChildNodesResult reorderChildren(final ReorderChildNodesParams params) {
    verifyContext();
    final ReorderChildNodesResult reorderChildNodesResult = ReorderChildNodesCommand.create().params(params).indexServiceInternal(this.indexServiceInternal).storageService(this.nodeStorageService).searchService(this.nodeSearchService).build().execute();
    for (Node parentNode : reorderChildNodesResult.getParentNodes()) {
        this.eventPublisher.publish(NodeEvents.sorted(parentNode));
    }
    refresh(RefreshMode.SEARCH);
    for (NodeId nodeId : reorderChildNodesResult.getNodeIds()) {
        this.eventPublisher.publish(NodeEvents.manualOrderUpdated(getById(nodeId)));
    }
    return reorderChildNodesResult;
}
Also used : Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) ReorderChildNodesResult(com.enonic.xp.node.ReorderChildNodesResult)

Aggregations

ReorderChildNodesResult (com.enonic.xp.node.ReorderChildNodesResult)4 Node (com.enonic.xp.node.Node)3 NodeId (com.enonic.xp.node.NodeId)2 ReorderChildNodeParams (com.enonic.xp.node.ReorderChildNodeParams)2 ReorderChildNodesParams (com.enonic.xp.node.ReorderChildNodesParams)2 ReorderChildContentsResult (com.enonic.xp.content.ReorderChildContentsResult)1 ReorderChildParams (com.enonic.xp.content.ReorderChildParams)1 Context (com.enonic.xp.context.Context)1 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 EventPublisher (com.enonic.xp.event.EventPublisher)1 ChildOrder (com.enonic.xp.index.ChildOrder)1 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)1 CreateRootNodeParams (com.enonic.xp.node.CreateRootNodeParams)1 DuplicateNodeParams (com.enonic.xp.node.DuplicateNodeParams)1 FindNodesByParentParams (com.enonic.xp.node.FindNodesByParentParams)1 GetNodeVersionsParams (com.enonic.xp.node.GetNodeVersionsParams)1 MoveNodeParams (com.enonic.xp.node.MoveNodeParams)1 NodeCommitEntry (com.enonic.xp.node.NodeCommitEntry)1