Search in sources :

Example 6 with NodePath

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

the class RestoreContentCommand method doExecute.

private RestoreContentsResult doExecute() {
    final Node nodeToRestore = nodeService.getById(NodeId.from(params.getContentId()));
    validateLocation(nodeToRestore);
    final boolean isRootContent = nodeToRestore.path().asAbsolute().elementCount() == 2;
    final NodePath parentPathToRestore = getParentPathToRestore(nodeToRestore, isRootContent);
    final String originalSourceName = getOriginalSourceName(nodeToRestore, isRootContent);
    final RestoreContentsResult.Builder result = RestoreContentsResult.create();
    rename(nodeToRestore, parentPathToRestore, originalSourceName);
    final MoveNodeParams.Builder builder = MoveNodeParams.create().nodeId(nodeToRestore.id()).parentNodePath(parentPathToRestore).moveListener(this);
    stopInherit(builder);
    final Node movedNode = move(builder.build(), originalSourceName);
    updateProperties(movedNode, isRootContent);
    commitNode(movedNode.id(), ContentConstants.RESTORE_COMMIT_PREFIX);
    result.addRestored(ContentId.from(movedNode.id().toString())).parentPath(ContentNodeHelper.translateNodePathToContentPath(parentPathToRestore));
    return result.build();
}
Also used : MoveNodeParams(com.enonic.xp.node.MoveNodeParams) RestoreContentsResult(com.enonic.xp.archive.RestoreContentsResult) Node(com.enonic.xp.node.Node) NodePath(com.enonic.xp.node.NodePath)

Example 7 with NodePath

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

the class NodeImportPathResolver method resolveNodeImportPath.

public static NodePath resolveNodeImportPath(final VirtualFile parent, final VirtualFile exportRoot, final NodePath importRoot) {
    final VirtualFilePath parentPath = parent.getPath();
    final VirtualFilePath exportRootPath = exportRoot.getPath();
    final VirtualFilePath relativePath = parentPath.subtractPath(exportRootPath);
    final NodePath.Builder builder = NodePath.create(importRoot);
    relativePath.getElements().forEach(builder::addElement);
    return builder.build();
}
Also used : VirtualFilePath(com.enonic.xp.vfs.VirtualFilePath) NodePath(com.enonic.xp.node.NodePath)

Example 8 with NodePath

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

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

the class NodeImportPathResolverTest method resolve_child_into_folder.

@Test
public void resolve_child_into_folder() throws Exception {
    final NodePath resolvedPath = NodeImportPathResolver.resolveNodeImportPath(// 
    VirtualFiles.from(Path.of("/var", "folder", "myExport", "mynode", "mychild")), // 
    VirtualFiles.from(Path.of("/var", "folder", "myExport")), NodePath.create(NodePath.ROOT, "myimport").build());
    assertEquals("/myimport/mynode/mychild", resolvedPath.toString());
    assertEquals("/myimport/mynode", resolvedPath.getParentPath().toString());
}
Also used : NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

Example 10 with NodePath

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

the class NodeImportPathResolverTest method resolve_into_folder.

@Test
public void resolve_into_folder() throws Exception {
    final NodePath resolvedPath = // 
    NodeImportPathResolver.resolveNodeImportPath(// 
    VirtualFiles.from(Path.of("/var", "folder", "myExport", "mynode")), // 
    VirtualFiles.from(Path.of("/var", "folder", "myExport")), NodePath.create(NodePath.ROOT, "myimport").build());
    assertEquals("/myimport/mynode", resolvedPath.toString());
}
Also used : NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

Aggregations

NodePath (com.enonic.xp.node.NodePath)54 Node (com.enonic.xp.node.Node)27 Test (org.junit.jupiter.api.Test)20 NodeId (com.enonic.xp.node.NodeId)15 InternalContext (com.enonic.xp.repo.impl.InternalContext)12 Content (com.enonic.xp.content.Content)7 Event (com.enonic.xp.event.Event)7 NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)4 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)4 NodeVersionId (com.enonic.xp.node.NodeVersionId)4 ChildOrder (com.enonic.xp.index.ChildOrder)3 NodeIds (com.enonic.xp.node.NodeIds)3 NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)2 ContentId (com.enonic.xp.content.ContentId)2 ContentPath (com.enonic.xp.content.ContentPath)2 CreateContentParams (com.enonic.xp.content.CreateContentParams)2 Context (com.enonic.xp.context.Context)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 MoveNodeParams (com.enonic.xp.node.MoveNodeParams)2 NodeVersion (com.enonic.xp.node.NodeVersion)2