Search in sources :

Example 1 with NodeExportResult

use of com.enonic.xp.export.NodeExportResult in project xp by enonic.

the class ExportHandler method execute.

public NodeExportResultMapper execute() {
    final ExportNodesParams.Builder paramsBuilder = ExportNodesParams.create().sourceNodePath(NodePath.create(sourceNodePath).build()).exportName(exportName).nodeExportListener(new FunctionBasedNodeExportListener(nodeExported, nodeResolved));
    if (includeNodeIds != null) {
        paramsBuilder.includeNodeIds(includeNodeIds);
    }
    if (includeVersions != null) {
        paramsBuilder.includeVersions(includeVersions);
    }
    final NodeExportResult nodeImportResult = this.context.getService(ExportService.class).get().exportNodes(paramsBuilder.build());
    return new NodeExportResultMapper(nodeImportResult);
}
Also used : NodeExportResult(com.enonic.xp.export.NodeExportResult) ExportNodesParams(com.enonic.xp.export.ExportNodesParams)

Example 2 with NodeExportResult

use of com.enonic.xp.export.NodeExportResult in project xp by enonic.

the class ExportRunnableTask method run.

@Override
public void run(final TaskId id, final ProgressReporter progressReporter) {
    final NodeExportResult result = getContext(params.getSourceRepoPath()).callWith(() -> this.exportService.exportNodes(ExportNodesParams.create().sourceNodePath(params.getSourceRepoPath().getNodePath()).exportName(params.getExportName()).dryRun(params.isDryRun()).includeNodeIds(params.isExportWithIds()).includeVersions(params.isIncludeVersions()).nodeExportListener(new ExportListenerImpl(progressReporter)).build()));
    progressReporter.info(NodeExportResultJson.from(result).toString());
}
Also used : ExportListenerImpl(com.enonic.xp.impl.server.rest.task.listener.ExportListenerImpl) NodeExportResult(com.enonic.xp.export.NodeExportResult)

Example 3 with NodeExportResult

use of com.enonic.xp.export.NodeExportResult in project xp by enonic.

the class ExportHandlerTest method testExample.

@Test
public void testExample() {
    final NodeExportResult result = NodeExportResult.create().addNodePath(NodePath.create("/content").build()).addBinary(NodePath.create("binaryPath").build(), BinaryReference.from("ref")).addError(new ExportError("some error")).build();
    when(exportService.exportNodes(any())).thenReturn(result);
    runScript("/lib/xp/examples/export/exportNodes.js");
}
Also used : NodeExportResult(com.enonic.xp.export.NodeExportResult) ExportError(com.enonic.xp.export.ExportError) Test(org.junit.jupiter.api.Test)

Example 4 with NodeExportResult

use of com.enonic.xp.export.NodeExportResult in project xp by enonic.

the class ExportRunnableTaskTest method exportNodes.

@Test
public void exportNodes() {
    final NodeExportResult nodeExportResult = NodeExportResult.create().addNodePath(NodePath.create().addElement("node").addElement("path").build()).addBinary(NodePath.create().elements("binary").build(), BinaryReference.from("binaryRef")).build();
    Mockito.when(this.exportService.exportNodes(isA(ExportNodesParams.class))).thenReturn(nodeExportResult);
    final ExportRunnableTask task = createAndRunTask(new ExportNodesRequestJson("a:b:c", "export", true, true, true));
    task.createTaskResult();
    Mockito.verify(progressReporter, Mockito.times(1)).info(contentQueryArgumentCaptor.capture());
    Mockito.verify(taskService, Mockito.times(1)).submitTask(Mockito.isA(RunnableTask.class), Mockito.eq("export"));
    final String result = contentQueryArgumentCaptor.getAllValues().get(0);
    jsonTestHelper.assertJsonEquals(jsonTestHelper.loadTestJson("exportNodes_result.json"), jsonTestHelper.stringToJson(result));
}
Also used : NodeExportResult(com.enonic.xp.export.NodeExportResult) RunnableTask(com.enonic.xp.task.RunnableTask) ExportNodesParams(com.enonic.xp.export.ExportNodesParams) ExportNodesRequestJson(com.enonic.xp.impl.server.rest.model.ExportNodesRequestJson) Test(org.junit.jupiter.api.Test) AbstractRunnableTaskTest(com.enonic.xp.task.AbstractRunnableTaskTest)

Example 5 with NodeExportResult

use of com.enonic.xp.export.NodeExportResult 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)

Aggregations

NodeExportResult (com.enonic.xp.export.NodeExportResult)16 Test (org.junit.jupiter.api.Test)14 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)12 Node (com.enonic.xp.node.Node)9 FileExportWriter (com.enonic.xp.core.impl.export.writer.FileExportWriter)8 PropertyTree (com.enonic.xp.data.PropertyTree)3 BinaryReference (com.enonic.xp.util.BinaryReference)3 ExportWriter (com.enonic.xp.core.impl.export.writer.ExportWriter)2 ExportNodesParams (com.enonic.xp.export.ExportNodesParams)2 NodeExportListener (com.enonic.xp.export.NodeExportListener)2 NodePath (com.enonic.xp.node.NodePath)2 Path (java.nio.file.Path)2 Disabled (org.junit.jupiter.api.Disabled)2 BINARY_FOLDER (com.enonic.xp.core.impl.export.writer.NodeExportPathResolver.BINARY_FOLDER)1 NODE_XML_EXPORT_NAME (com.enonic.xp.core.impl.export.writer.NodeExportPathResolver.NODE_XML_EXPORT_NAME)1 SYSTEM_FOLDER_NAME (com.enonic.xp.core.impl.export.writer.NodeExportPathResolver.SYSTEM_FOLDER_NAME)1 VERSION_FOLDER (com.enonic.xp.core.impl.export.writer.NodeExportPathResolver.VERSION_FOLDER)1 ExportError (com.enonic.xp.export.ExportError)1 ExportNodesRequestJson (com.enonic.xp.impl.server.rest.model.ExportNodesRequestJson)1 ExportListenerImpl (com.enonic.xp.impl.server.rest.task.listener.ExportListenerImpl)1