use of com.enonic.xp.node.Node in project xp by enonic.
the class NodeExportIntegrationTest method single_node_with_binary_changed.
@Test
public void single_node_with_binary_changed() throws Exception {
final BinaryReference binaryRef = BinaryReference.from("myFile");
final BinaryReference binaryRefUpdated = BinaryReference.from("myOtherFile");
final PropertyTree data = new PropertyTree();
data.addBinaryReference("myBinary", binaryRef);
final Node myNode = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("myNode").data(data).attachBinary(binaryRef, ByteSource.wrap("this is a binary file".getBytes())).build());
final Node updatedNode = updateNode(UpdateNodeParams.create().id(myNode.id()).editor((n) -> n.data.setBinaryReference("myBinary", binaryRefUpdated)).attachBinary(binaryRefUpdated, ByteSource.wrap("this is another binary file".getBytes())).build());
final NodeExportResult result = doExportRoot(true);
printPaths();
assertEquals(2, result.size());
assertExported(myNode);
assertBinaryExported(updatedNode, binaryRefUpdated);
assertVersionBinaryExported(updatedNode, myNode, binaryRef);
}
use of com.enonic.xp.node.Node in project xp by enonic.
the class NodeExportIntegrationTest method children_nodes.
@Test
public void children_nodes() throws Exception {
final Node root = createNode("mynode", NodePath.ROOT);
final Node child1 = createNode("child1", root.path());
createNode("child1_1", child1.path());
final Node child1_2 = createNode("child1_2", child1.path());
createNode("child1_2_1", child1_2.path());
createNode("child1_2_2", child1_2.path());
final Node child2 = createNode("child2", root.path());
createNode("child2_1", child2.path());
final NodeExportListener nodeExportListener = Mockito.mock(NodeExportListener.class);
nodeService.refresh(RefreshMode.ALL);
final NodeExportResult result = NodeExporter.create().nodeService(this.nodeService).nodeExportWriter(new FileExportWriter()).sourceNodePath(NodePath.ROOT).targetDirectory(this.temporaryFolder.resolve("myExport")).nodeExportListener(nodeExportListener).build().execute();
assertEquals(9, result.size());
assertFileExists("myExport/_/node.xml");
assertFileExists("myExport/mynode/_/node.xml");
assertFileExists("myExport/mynode/child1/_/node.xml");
assertFileExists("myExport/mynode/child1/child1_1/_/node.xml");
assertFileExists("myExport/mynode/child1/child1_2/_/node.xml");
assertFileExists("myExport/mynode/child1/child1_2/child1_2_1/_/node.xml");
assertFileExists("myExport/mynode/child1/child1_2/child1_2_2/_/node.xml");
assertFileExists("myExport/mynode/child2/_/node.xml");
assertFileExists("myExport/mynode/child2/child2_1/_/node.xml");
Mockito.verify(nodeExportListener).nodeResolved(9L);
Mockito.verify(nodeExportListener, Mockito.times(9)).nodeExported(1L);
}
use of com.enonic.xp.node.Node in project xp by enonic.
the class ContentInitializer method initContentNode.
private void initContentNode() {
final Node contentRootNode = nodeService.getByPath(ContentConstants.CONTENT_ROOT_PATH);
final User user = ContextAccessor.current().getAuthInfo().getUser();
if (contentRootNode == null) {
LOG.info("Content root-node not found, creating");
PropertyTree data = new PropertyTree();
data.setString(ContentPropertyNames.TYPE, "base:folder");
data.setString(ContentPropertyNames.DISPLAY_NAME, "Content");
data.addSet(ContentPropertyNames.DATA);
data.addSet(ContentPropertyNames.FORM);
data.setString(ContentPropertyNames.CREATOR, user.getKey().toString());
data.setInstant(ContentPropertyNames.CREATED_TIME, Instant.now());
final Node contentRoot = nodeService.create(CreateNodeParams.create().data(data).name(ContentConstants.CONTENT_ROOT_NAME).parent(NodePath.ROOT).permissions(Objects.requireNonNullElse(this.accessControlList, CONTENT_ROOT_DEFAULT_ACL)).childOrder(CONTENT_DEFAULT_CHILD_ORDER).build());
LOG.info("Created content root-node: {}", contentRoot);
nodeService.refresh(RefreshMode.ALL);
nodeService.push(NodeIds.from(contentRoot.id()), ContentConstants.BRANCH_MASTER);
}
}
use of com.enonic.xp.node.Node in project xp by enonic.
the class ArchiveInitializer method initArchiveNode.
private void initArchiveNode() {
LOG.info("Archive root-node not found, creating");
final PropertyTree data = new PropertyTree();
data.setString(ContentPropertyNames.TYPE, ContentTypeName.folder().toString());
data.setSet(ContentPropertyNames.DATA, new PropertySet());
data.setString(ContentPropertyNames.CREATOR, ContextAccessor.current().getAuthInfo().getUser().toString());
data.setString(ContentPropertyNames.MODIFIER, ContextAccessor.current().getAuthInfo().getUser().toString());
final Node archiveRoot = nodeService.create(CreateNodeParams.create().data(data).name(ArchiveConstants.ARCHIVE_ROOT_NAME).parent(NodePath.ROOT).permissions(Objects.requireNonNullElse(accessControlList, ArchiveConstants.ARCHIVE_ROOT_DEFAULT_ACL)).childOrder(ArchiveConstants.DEFAULT_ARCHIVE_REPO_ROOT_ORDER).build());
LOG.info("Created archive root-node: " + archiveRoot.path());
nodeService.refresh(RefreshMode.ALL);
}
use of com.enonic.xp.node.Node in project xp by enonic.
the class RepoDumper method dumpBranch.
private void dumpBranch(final BranchDumpResult.Builder dumpResult, Consumer<NodeId> nodeIdsAccumulator) {
final Node rootNode = this.nodeService.getRoot();
final FindNodesByParentResult children = this.nodeService.findByParent(FindNodesByParentParams.create().parentId(rootNode.id()).recursive(true).childOrder(ChildOrder.from("_path asc")).build());
final Branch branch = ContextAccessor.current().getBranch();
this.listener.dumpingBranch(repository.getId(), branch, children.getTotalHits() + 1);
LOG.info("Dumping repository [{}], branch [{}]", repository.getId(), branch);
doDumpNode(rootNode.id(), dumpResult);
nodeIdsAccumulator.accept(rootNode.id());
for (final NodeId child : children.getNodeIds()) {
doDumpNode(child, dumpResult);
nodeIdsAccumulator.accept(child);
}
}
Aggregations