Search in sources :

Example 1 with ImportNodeResult

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

the class ImportContentCommand method doExecute.

private ImportContentResult doExecute() {
    final Node importNode = ImportContentFactory.create().params(params).contentDataSerializer(contentDataSerializer).build().execute();
    final ImportNodeParams importNodeParams = ImportNodeParams.create().importNode(importNode).binaryAttachments(params.getBinaryAttachments()).insertManualStrategy(params.getInsertManualStrategy()).dryRun(params.isDryRun()).importPermissions(params.isImportPermissions()).importPermissionsOnCreate(params.isImportPermissionsOnCreate()).build();
    final ImportNodeResult result = nodeService.importNode(importNodeParams);
    return ImportContentResult.create().content(translator.fromNode(result.getNode(), false)).build();
}
Also used : Node(com.enonic.xp.node.Node) ImportNodeResult(com.enonic.xp.node.ImportNodeResult) ImportNodeParams(com.enonic.xp.node.ImportNodeParams)

Example 2 with ImportNodeResult

use of com.enonic.xp.node.ImportNodeResult 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 3 with ImportNodeResult

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

the class NodeServiceImpl method importNode.

@Override
public ImportNodeResult importNode(final ImportNodeParams params) {
    verifyContext();
    final ImportNodeResult importNodeResult = ImportNodeCommand.create().binaryAttachments(params.getBinaryAttachments()).importNode(params.getNode()).insertManualStrategy(params.getInsertManualStrategy()).dryRun(params.isDryRun()).importPermissions(params.isImportPermissions()).importPermissionsOnCreate(params.isImportPermissionsOnCreate()).binaryBlobStore(this.binaryService).indexServiceInternal(this.indexServiceInternal).storageService(this.nodeStorageService).searchService(this.nodeSearchService).build().execute();
    if (importNodeResult.isPreExisting()) {
        this.eventPublisher.publish(NodeEvents.updated(importNodeResult.getNode()));
    } else {
        this.eventPublisher.publish(NodeEvents.created(importNodeResult.getNode()));
    }
    return importNodeResult;
}
Also used : ImportNodeResult(com.enonic.xp.node.ImportNodeResult)

Example 4 with ImportNodeResult

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

the class ImportNodeCommandTest method no_timestamp.

@Test
public void no_timestamp() throws Exception {
    final Node importNode = Node.create().name("myNode").parentPath(NodePath.ROOT).data(new PropertyTree()).build();
    final ImportNodeResult importNodeResult = importNode(importNode);
    assertNotNull(importNodeResult.getNode().getTimestamp());
}
Also used : Node(com.enonic.xp.node.Node) PropertyTree(com.enonic.xp.data.PropertyTree) ImportNodeResult(com.enonic.xp.node.ImportNodeResult) Test(org.junit.jupiter.api.Test)

Example 5 with ImportNodeResult

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

the class ImportNodeCommandTest method import_existing_node.

@Test
public void import_existing_node() {
    PropertyTree data = new PropertyTree();
    data.addString("name", "value");
    final Node importNode = Node.create().id(NodeId.from("abc")).name("myNode").parentPath(NodePath.ROOT).data(data).build();
    importNode(importNode);
    final Node abc = getNodeById(NodeId.from("abc"));
    assertNotNull(abc);
    assertEquals(data, abc.data());
    PropertyTree data2 = new PropertyTree();
    data2.addString("name", "valueUpdated");
    final Node importNode2 = Node.create().id(NodeId.from("abc")).name("myNode").parentPath(NodePath.ROOT).data(data2).build();
    final ImportNodeResult importNodeResult = importNode(importNode2);
    final Node abc2 = getNodeById(NodeId.from("abc"));
    assertNotNull(abc2);
    assertEquals(data2, abc2.data());
    assertEquals(importNodeResult.getNode().data(), abc2.data());
    assertTrue(importNodeResult.isPreExisting());
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) ImportNodeResult(com.enonic.xp.node.ImportNodeResult) Test(org.junit.jupiter.api.Test)

Aggregations

ImportNodeResult (com.enonic.xp.node.ImportNodeResult)8 Node (com.enonic.xp.node.Node)7 PropertyTree (com.enonic.xp.data.PropertyTree)5 Test (org.junit.jupiter.api.Test)5 AccessControlList (com.enonic.xp.security.acl.AccessControlList)3 XmlNodeParser (com.enonic.xp.core.impl.export.xml.XmlNodeParser)1 ImportNodeException (com.enonic.xp.export.ImportNodeException)1 ImportNodeParams (com.enonic.xp.node.ImportNodeParams)1 NodePath (com.enonic.xp.node.NodePath)1 VirtualFile (com.enonic.xp.vfs.VirtualFile)1 XmlException (com.enonic.xp.xml.XmlException)1 CharSource (com.google.common.io.CharSource)1