Search in sources :

Example 46 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class NodeImporter method importNode.

private ImportNodeResult importNode(final VirtualFile nodeFolder, final ProcessNodeSettings.Builder processNodeSettings, final Node serializedNode, final NodePath importNodePath) {
    final BinaryAttachments binaryAttachments = processBinaryAttachments(nodeFolder, serializedNode);
    final ProcessNodeSettings settings = processNodeSettings.build();
    final Node importNode = ImportNodeFactory.create().importNodeIds(this.importNodeIds).importPermissions(this.importPermissions).serializedNode(serializedNode).importPath(importNodePath).processNodeSettings(settings).build().execute();
    final ImportNodeParams importNodeParams = ImportNodeParams.create().importNode(importNode).binaryAttachments(binaryAttachments).insertManualStrategy(settings.getInsertManualStrategy()).dryRun(this.dryRun).importPermissions(this.importPermissions).importPermissionsOnCreate(this.importPermissions).build();
    return this.nodeService.importNode(importNodeParams);
}
Also used : BinaryAttachments(com.enonic.xp.node.BinaryAttachments) Node(com.enonic.xp.node.Node) ImportNodeParams(com.enonic.xp.node.ImportNodeParams)

Example 47 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class NodeImporter method processNodeSource.

private Node processNodeSource(final VirtualFile nodeFolder, final ProcessNodeSettings.Builder processNodeSettings) {
    final VirtualFile nodeSource = this.exportReader.getNodeSource(nodeFolder);
    final CharSource nodeCharSource;
    try {
        nodeCharSource = transformer == null ? nodeSource.getCharSource() : CharSource.wrap(this.transformer.transform(nodeSource.getCharSource()));
    } catch (Exception e) {
        throw new ImportNodeException("Error during XSLT pre-processing for node in '" + nodeSource.getUrl() + "'", e);
    }
    final Node.Builder newNodeBuilder = Node.create();
    try {
        final XmlNodeParser parser = new XmlNodeParser();
        parser.builder(newNodeBuilder);
        parser.source(nodeCharSource);
        parser.parse();
    } catch (final Exception e) {
        throw new XmlException(e, "Could not load source node [" + nodeSource.getUrl() + "]: ", e);
    }
    final Node newNode = newNodeBuilder.build();
    final NodePath importNodePath = NodeImportPathResolver.resolveNodeImportPath(nodeFolder, this.exportRoot, this.importRoot);
    final ImportNodeResult importNodeResult = importNode(nodeFolder, processNodeSettings, newNode, importNodePath);
    if (nodeImportListener != null) {
        nodeImportListener.nodeImported(1L);
    }
    if (importNodeResult.isPreExisting()) {
        result.updated(importNodeResult.getNode().path());
    } else {
        result.added(importNodeResult.getNode().path());
    }
    return importNodeResult.getNode();
}
Also used : VirtualFile(com.enonic.xp.vfs.VirtualFile) CharSource(com.google.common.io.CharSource) ImportNodeException(com.enonic.xp.export.ImportNodeException) XmlException(com.enonic.xp.xml.XmlException) Node(com.enonic.xp.node.Node) ImportNodeResult(com.enonic.xp.node.ImportNodeResult) XmlNodeParser(com.enonic.xp.core.impl.export.xml.XmlNodeParser) ImportNodeException(com.enonic.xp.export.ImportNodeException) XmlException(com.enonic.xp.xml.XmlException) NodePath(com.enonic.xp.node.NodePath)

Example 48 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class ImportNodeFactoryTest method testName.

@Test
public void testName() throws Exception {
    final Node serializedNode = Node.create().data(new PropertyTree()).timestamp(Instant.parse("2010-01-01T10:00:00Z")).build();
    final Node importNode = ImportNodeFactory.create().serializedNode(serializedNode).importPath(NodePath.create("/test").build()).processNodeSettings(ProcessNodeSettings.create().build()).build().execute();
    assertEquals(serializedNode.getTimestamp(), importNode.getTimestamp());
}
Also used : Node(com.enonic.xp.node.Node) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 49 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class NodeExportIntegrationTest method include_export_root_and_nested_children.

@Test
public void include_export_root_and_nested_children() throws Exception {
    final Node root = createNode("mynode", NodePath.ROOT);
    final Node child1 = createNode("child1", root.path());
    createNode("child2", root.path());
    final Node child1_1 = createNode("child1_1", child1.path());
    createNode("child1_1_1", child1_1.path());
    createNode("child1_1_2", child1_1.path());
    nodeService.refresh(RefreshMode.ALL);
    final NodeExportResult result = NodeExporter.create().nodeService(this.nodeService).nodeExportWriter(new FileExportWriter()).sourceNodePath(NodePath.create("/mynode/child1").build()).targetDirectory(this.temporaryFolder.resolve("myExport")).build().execute();
    assertEquals(4, result.getExportedNodes().getSize());
    assertFileExists("myExport/child1/_/node.xml");
    assertFileExists("myExport/child1/child1_1/_/node.xml");
    assertFileExists("myExport/child1/child1_1/child1_1_1/_/node.xml");
    assertFileExists("myExport/child1/child1_1/child1_1_2/_/node.xml");
}
Also used : NodeExportResult(com.enonic.xp.export.NodeExportResult) Node(com.enonic.xp.node.Node) FileExportWriter(com.enonic.xp.core.impl.export.writer.FileExportWriter) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 50 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class NodeExportIntegrationTest method export_from_child_of_child.

@Test
public void export_from_child_of_child() throws Exception {
    final Node root = createNode("mynode", NodePath.ROOT);
    final Node child1 = createNode("child1", root.path());
    final Node child1_1 = createNode("child1_1", child1.path());
    createNode("child1_1_1", child1_1.path());
    createNode("child1_1_2", child1_1.path());
    nodeService.refresh(RefreshMode.ALL);
    final NodeExportResult result = NodeExporter.create().nodeService(this.nodeService).nodeExportWriter(new FileExportWriter()).sourceNodePath(NodePath.create("/mynode/child1/child1_1").build()).targetDirectory(this.temporaryFolder.resolve("myExport")).build().execute();
    assertEquals(3, result.getExportedNodes().getSize());
    assertFileExists("myExport/child1_1/_/node.xml");
    assertFileExists("myExport/child1_1/child1_1_1/_/node.xml");
    assertFileExists("myExport/child1_1/child1_1_2/_/node.xml");
}
Also used : NodeExportResult(com.enonic.xp.export.NodeExportResult) Node(com.enonic.xp.node.Node) FileExportWriter(com.enonic.xp.core.impl.export.writer.FileExportWriter) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

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