Search in sources :

Example 1 with ExportError

use of com.enonic.xp.export.ExportError 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 2 with ExportError

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

the class NodeExporter method execute.

public NodeExportResult execute() {
    this.result.dryRun(this.dryRun);
    final Node rootNode = this.nodeService.getByPath(this.sourceNodePath);
    if (rootNode != null) {
        if (nodeExportListener != null) {
            final long childNodeCount = getRecursiveNodeCountByParentPath(sourceNodePath);
            nodeExportListener.nodeResolved(childNodeCount + 1);
        }
        try {
            exportNode(rootNode);
        } catch (Exception e) {
            LOG.error(String.format("Failed to export node with path [%s]", rootNode.path()), e);
            result.addError(new ExportError(e.toString()));
        }
    } else {
        addRootNodeNotFoundError();
    }
    writeExportProperties();
    return result.build();
}
Also used : Node(com.enonic.xp.node.Node) ExportError(com.enonic.xp.export.ExportError)

Example 3 with ExportError

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

the class NodeExporter method doExport.

private FindNodesByParentResult doExport(final NodePath nodePath) {
    final FindNodesByParentResult children = nodeService.findByParent(FindNodesByParentParams.create().parentPath(nodePath).build());
    final Nodes childNodes = this.nodeService.getByIds(children.getNodeIds());
    for (final Node child : childNodes) {
        try {
            exportNode(child);
        } catch (Exception e) {
            LOG.error(String.format("Failed to export node with path [%s]", child.path()), e);
            result.addError(new ExportError(e.toString()));
        }
    }
    return children;
}
Also used : Node(com.enonic.xp.node.Node) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) ExportError(com.enonic.xp.export.ExportError) Nodes(com.enonic.xp.node.Nodes)

Aggregations

ExportError (com.enonic.xp.export.ExportError)3 Node (com.enonic.xp.node.Node)2 NodeExportResult (com.enonic.xp.export.NodeExportResult)1 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)1 Nodes (com.enonic.xp.node.Nodes)1 Test (org.junit.jupiter.api.Test)1