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