Search in sources :

Example 1 with DuplicateNodeParams

use of com.enonic.xp.node.DuplicateNodeParams 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)

Aggregations

Content (com.enonic.xp.content.Content)1 ContentIds (com.enonic.xp.content.ContentIds)1 DuplicateNodeParams (com.enonic.xp.node.DuplicateNodeParams)1 Node (com.enonic.xp.node.Node)1 NodeId (com.enonic.xp.node.NodeId)1