Search in sources :

Example 6 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 7 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 8 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 9 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 10 with NodeExportResult

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

the class NodeExportIntegrationTest method one_node_error.

@Test
public void one_node_error() throws Exception {
    createNode("mynode", NodePath.ROOT);
    final ExportWriter exportWriter = Mockito.mock(ExportWriter.class);
    Mockito.doThrow(new RuntimeException("exception message")).when(exportWriter).writeElement(Mockito.isA(Path.class), Mockito.anyString());
    final NodeExportResult result = NodeExporter.create().nodeService(this.nodeService).nodeExportWriter(exportWriter).sourceNodePath(NodePath.ROOT).targetDirectory(this.temporaryFolder.resolve("myExport")).build().execute();
    assertEquals(1, result.getExportErrors().size());
    assertEquals("java.lang.RuntimeException: exception message", result.getExportErrors().get(0).toString());
}
Also used : Path(java.nio.file.Path) NodePath(com.enonic.xp.node.NodePath) NodeExportResult(com.enonic.xp.export.NodeExportResult) ExportWriter(com.enonic.xp.core.impl.export.writer.ExportWriter) 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