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;
}
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();
}
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"));
}
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;
}
Aggregations