Search in sources :

Example 26 with Node

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

the class DuplicateContentCommand method doExecute.

private DuplicateContentsResult doExecute() {
    final NodeId sourceNodeId = NodeId.from(params.getContentId());
    final Node sourceNode = nodeService.getById(sourceNodeId);
    if (sourceNode == null) {
        throw new IllegalArgumentException(String.format("Content with id [%s] not found", params.getContentId()));
    }
    final DuplicateNodeParams duplicateNodeParams = DuplicateNodeParams.create().duplicateListener(this).nodeId(sourceNodeId).dataProcessor(new DuplicateContentProcessor()).includeChildren(params.getIncludeChildren()).build();
    final Node duplicatedNode = nodeService.duplicate(duplicateNodeParams);
    final Content duplicatedContent = translator.fromNode(duplicatedNode, true);
    final ContentIds childrenIds = params.getIncludeChildren() ? getAllChildren(duplicatedContent) : ContentIds.empty();
    return DuplicateContentsResult.create().setSourceContentPath(ContentNodeHelper.translateNodePathToContentPath(sourceNode.path())).setContentName(duplicatedContent.getDisplayName()).addDuplicated(duplicatedContent.getId()).addDuplicated(childrenIds).build();
}
Also used : DuplicateNodeParams(com.enonic.xp.node.DuplicateNodeParams) Content(com.enonic.xp.content.Content) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) ContentIds(com.enonic.xp.content.ContentIds)

Example 27 with Node

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

the class GetContentByIdCommand method execute.

Content execute() {
    final Content content;
    final NodeId nodeId = NodeId.from(contentId.toString());
    try {
        final Node node = nodeService.getById(nodeId);
        content = filter(translator.fromNode(node, true));
    } catch (NodeNotFoundException e) {
        return null;
    } catch (Exception e) {
        throw Exceptions.newRuntime("Error getting node").withCause(e);
    }
    return content;
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) Content(com.enonic.xp.content.Content) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException)

Example 28 with Node

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

the class GetContentByPathAndVersionIdCommand method execute.

public Content execute() {
    final NodePath nodePath = ContentNodeHelper.translateContentPathToNodePath(contentPath);
    final NodeVersionId nodeVersionId = NodeVersionId.from(contentVersionId.toString());
    try {
        final Node node = nodeService.getByPathAndVersionId(nodePath, nodeVersionId);
        final Content content = filter(translator.fromNode(node, true));
        if (content != null) {
            return content;
        }
        throw createContentNotFoundException();
    } catch (NodeNotFoundException e) {
        throw createContentNotFoundException();
    }
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) NodeVersionId(com.enonic.xp.node.NodeVersionId) Content(com.enonic.xp.content.Content) Node(com.enonic.xp.node.Node) NodePath(com.enonic.xp.node.NodePath)

Example 29 with Node

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

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

the class RenameContentCommand method doExecute.

private Content doExecute() {
    final NodeId nodeId = NodeId.from(params.getContentId());
    final NodeName nodeName = NodeName.from(params.getNewName().toString());
    final RenameNodeParams.Builder builder = RenameNodeParams.create().nodeId(nodeId).nodeName(nodeName);
    if (params.stopInherit()) {
        builder.processor(new RenameContentProcessor());
    }
    final Node node = nodeService.rename(builder.build());
    final Content content = translator.fromNode(node, false);
    final ValidationErrors validationErrors = validateContent(content);
    if (content.isValid() == validationErrors.hasErrors() || !validationErrors.equals(content.getValidationErrors())) {
        return updateValidState(content);
    }
    return getContent(params.getContentId());
}
Also used : NodeName(com.enonic.xp.node.NodeName) ValidationErrors(com.enonic.xp.content.ValidationErrors) Content(com.enonic.xp.content.Content) RenameNodeParams(com.enonic.xp.node.RenameNodeParams) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId)

Aggregations

Node (com.enonic.xp.node.Node)521 Test (org.junit.jupiter.api.Test)371 PropertyTree (com.enonic.xp.data.PropertyTree)114 NodeId (com.enonic.xp.node.NodeId)52 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)51 NodePath (com.enonic.xp.node.NodePath)45 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)42 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)34 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)32 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)29 NodeQuery (com.enonic.xp.node.NodeQuery)27 AccessControlList (com.enonic.xp.security.acl.AccessControlList)27 BinaryReference (com.enonic.xp.util.BinaryReference)26 ByteSource (com.google.common.io.ByteSource)24 Content (com.enonic.xp.content.Content)23 PropertySet (com.enonic.xp.data.PropertySet)20 NodeIds (com.enonic.xp.node.NodeIds)18 Context (com.enonic.xp.context.Context)17 InternalContext (com.enonic.xp.repo.impl.InternalContext)17 Application (com.enonic.xp.app.Application)16