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();
}
Aggregations