Search in sources :

Example 51 with Node

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);
}
Also used : ChildOrder(com.enonic.xp.index.ChildOrder) RefreshMode(com.enonic.xp.node.RefreshMode) BeforeEach(org.junit.jupiter.api.BeforeEach) ExportWriter(com.enonic.xp.core.impl.export.writer.ExportWriter) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Node(com.enonic.xp.node.Node) BINARY_FOLDER(com.enonic.xp.core.impl.export.writer.NodeExportPathResolver.BINARY_FOLDER) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Disabled(org.junit.jupiter.api.Disabled) SYSTEM_FOLDER_NAME(com.enonic.xp.core.impl.export.writer.NodeExportPathResolver.SYSTEM_FOLDER_NAME) NODE_XML_EXPORT_NAME(com.enonic.xp.core.impl.export.writer.NodeExportPathResolver.NODE_XML_EXPORT_NAME) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) FileExportWriter(com.enonic.xp.core.impl.export.writer.FileExportWriter) Path(java.nio.file.Path) PropertyTree(com.enonic.xp.data.PropertyTree) BinaryReference(com.enonic.xp.util.BinaryReference) VERSION_FOLDER(com.enonic.xp.core.impl.export.writer.NodeExportPathResolver.VERSION_FOLDER) NodePath(com.enonic.xp.node.NodePath) Instant(java.time.Instant) File(java.io.File) RenameNodeParams(com.enonic.xp.node.RenameNodeParams) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) NodeName(com.enonic.xp.node.NodeName) NodeExportListener(com.enonic.xp.export.NodeExportListener) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest) NodeExportResult(com.enonic.xp.export.NodeExportResult) NodeExportResult(com.enonic.xp.export.NodeExportResult) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) BinaryReference(com.enonic.xp.util.BinaryReference) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 52 with Node

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);
}
Also used : NodeExportResult(com.enonic.xp.export.NodeExportResult) Node(com.enonic.xp.node.Node) NodeExportListener(com.enonic.xp.export.NodeExportListener) FileExportWriter(com.enonic.xp.core.impl.export.writer.FileExportWriter) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 53 with Node

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);
    }
}
Also used : User(com.enonic.xp.security.User) Node(com.enonic.xp.node.Node) PropertyTree(com.enonic.xp.data.PropertyTree)

Example 54 with Node

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);
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) PropertySet(com.enonic.xp.data.PropertySet)

Example 55 with Node

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);
    }
}
Also used : Branch(com.enonic.xp.branch.Branch) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult)

Aggregations

Node (com.enonic.xp.node.Node)521 Test (org.junit.jupiter.api.Test)371 PropertyTree (com.enonic.xp.data.PropertyTree)114 NodeId (com.enonic.xp.node.NodeId)52 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)51 NodePath (com.enonic.xp.node.NodePath)45 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)42 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)34 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)32 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)29 NodeQuery (com.enonic.xp.node.NodeQuery)27 AccessControlList (com.enonic.xp.security.acl.AccessControlList)27 BinaryReference (com.enonic.xp.util.BinaryReference)26 ByteSource (com.google.common.io.ByteSource)24 Content (com.enonic.xp.content.Content)23 PropertySet (com.enonic.xp.data.PropertySet)20 NodeIds (com.enonic.xp.node.NodeIds)18 Context (com.enonic.xp.context.Context)17 InternalContext (com.enonic.xp.repo.impl.InternalContext)17 Application (com.enonic.xp.app.Application)16