use of com.enonic.xp.node.NodeId in project xp by enonic.
the class VersionTableVacuumCommand method findVersionsInBranches.
private BRANCH_CHECK_RESULT findVersionsInBranches(final Repository repository, final NodeVersionMetadata versionMetadata) {
final NodeId nodeId = versionMetadata.getNodeId();
final NodeVersionId versionId = versionMetadata.getNodeVersionId();
boolean nodeFound = false;
for (final Branch branch : repository.getBranches()) {
try {
final Node node = ContextBuilder.from(ContextAccessor.current()).branch(branch).repositoryId(repository.getId()).build().callWith(() -> this.nodeService.getById(nodeId));
if (versionId.equals(node.getNodeVersionId())) {
return BRANCH_CHECK_RESULT.SAME_VERSION_FOUND;
}
nodeFound = true;
} catch (NodeNotFoundException e) {
// Ignore
}
}
return nodeFound ? BRANCH_CHECK_RESULT.OTHER_VERSION_FOUND : BRANCH_CHECK_RESULT.NO_VERSION_FOUND;
}
use of com.enonic.xp.node.NodeId in project xp by enonic.
the class DumpServiceImplTest method binaries_in_versions.
@Test
public void binaries_in_versions() throws Exception {
final PropertyTree data = new PropertyTree();
final BinaryReference binaryRef = BinaryReference.from("binaryRef");
data.addBinaryReference("myBinary", binaryRef);
final Node node = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("myNode").data(data).attachBinary(binaryRef, ByteSource.wrap("this is binary data".getBytes())).build());
final BinaryReference binaryRef2 = BinaryReference.from("anotherBinary");
final Node updatedNode = updateNode(UpdateNodeParams.create().id(node.id()).editor(n -> n.data.setBinaryReference("myBinary", binaryRef2)).attachBinary(binaryRef2, ByteSource.wrap("anotherBinary".getBytes())).build());
NodeHelper.runAsAdmin(() -> dumpDeleteAndLoad(true));
final NodeVersionQueryResult versions = this.nodeService.findVersions(GetNodeVersionsParams.create().nodeId(node.id()).build());
assertEquals(2, versions.getHits());
verifyBinaries(node, updatedNode, versions);
}
use of com.enonic.xp.node.NodeId 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.NodeId 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.NodeId in project xp by enonic.
the class NodeServiceImplTest method test_duplicate_with_children.
@Test
public void test_duplicate_with_children() {
final PropertyTree data = new PropertyTree();
final Node node_1 = this.nodeService.create(CreateNodeParams.create().name("parent").parent(NodePath.ROOT).data(data).build());
final Node node_1_2 = this.nodeService.create(CreateNodeParams.create().name("child").parent(node_1.path()).data(data).build());
final Node node_1_2_3 = this.nodeService.create(CreateNodeParams.create().name("child_of_child").parent(node_1_2.path()).data(data).build());
this.nodeService.refresh(RefreshMode.SEARCH);
final Node duplicatedNode = this.nodeService.duplicate(DuplicateNodeParams.create().nodeId(node_1.id()).build());
final NodeId node_1_2_dup_id = this.nodeService.findByParent(FindNodesByParentParams.create().parentId(duplicatedNode.id()).build()).getNodeIds().first();
final Node node_1_2_dup = this.nodeService.getById(node_1_2_dup_id);
assertEquals(node_1_2.name(), node_1_2_dup.name());
final NodeId node_1_2_3_dup_id = this.nodeService.findByParent(FindNodesByParentParams.create().parentPath(node_1_2_dup.path()).build()).getNodeIds().first();
final Node node_1_2_3_dup = this.nodeService.getById(node_1_2_3_dup_id);
assertEquals(node_1_2_3.name(), node_1_2_3_dup.name());
}
Aggregations