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