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