use of com.enonic.xp.node.NodeId in project xp by enonic.
the class ApplyContentPermissionsCommand method execute.
ApplyContentPermissionsResult execute() {
final NodeId nodeId = NodeId.from(params.getContentId().toString());
final ApplyNodePermissionsParams applyNodePermissionsParams = ApplyNodePermissionsParams.create().nodeId(nodeId).permissions(params.getPermissions()).inheritPermissions(params.isInheritPermissions()).overwriteChildPermissions(params.isOverwriteChildPermissions()).applyPermissionsListener(params.getListener()).build();
final ApplyNodePermissionsResult result = nodeService.applyPermissions(applyNodePermissionsParams);
return ApplyContentPermissionsResult.create().setSucceedContents(ContentNodeHelper.translateNodePathsToContentPaths(result.getSucceedNodes().getPaths())).setSkippedContents(ContentNodeHelper.translateNodePathsToContentPaths(result.getSkippedNodes().getPaths())).build();
}
use of com.enonic.xp.node.NodeId in project xp by enonic.
the class DeleteContentCommand method deleteNodeInDraftAndMaster.
private void deleteNodeInDraftAndMaster(final NodeId nodeToDelete, final DeleteContentsResult.Builder result) {
final Context draftContext = ContextAccessor.current();
final Context masterContext = ContextBuilder.from(draftContext).branch(ContentConstants.BRANCH_MASTER).build();
final Node draftRootNode = nodeService.getById(nodeToDelete);
final NodeIds draftNodes = deleteNodeInContext(nodeToDelete, draftContext);
final NodeIds masterNodes = deleteNodeInContext(nodeToDelete, masterContext);
result.addDeleted(ContentIds.from(draftNodes.getAsStrings()));
result.addUnpublished(ContentIds.from(masterNodes.getAsStrings()));
final NodeIds masterIdsByDraftPath = masterContext.callWith(() -> this.nodeService.findByParent(FindNodesByParentParams.create().parentPath(draftRootNode.path()).recursive(true).build()).getNodeIds());
Stream.concat(masterIdsByDraftPath.stream(), draftNodes.stream()).filter(id -> !masterNodes.contains(id)).forEach(id -> {
deleteNodeInContext(id, masterContext);
result.addUnpublished(ContentId.from(id.toString()));
});
}
use of com.enonic.xp.node.NodeId in project xp by enonic.
the class GetContentByIdAndVersionIdCommand method execute.
public Content execute() {
final NodeId nodeId = NodeId.from(contentId.toString());
final NodeVersionId nodeVersionId = NodeVersionId.from(versionId.toString());
try {
return getContentByIdAndVersionId(nodeId, nodeVersionId);
} catch (NodeNotFoundException e) {
throw createContentNotFoundException();
}
}
use of com.enonic.xp.node.NodeId in project xp by enonic.
the class MoveContentCommand method doExecute.
private MoveContentsResult doExecute() {
final ContentId contentId = params.getContentId();
final Content sourceContent = getContent(contentId);
final NodePath newParentPath = ContentNodeHelper.translateContentPathToNodePath(params.getParentContentPath());
if (nodeService.nodeExists(NodePath.create(newParentPath, sourceContent.getName().toString()).build())) {
throw new ContentAlreadyMovedException(String.format("Content with name [%s] is already a child of [%s]", sourceContent.getName(), params.getParentContentPath()), sourceContent.getPath());
}
validateParentChildRelations(params.getParentContentPath(), sourceContent.getType());
final NodeId sourceNodeId = NodeId.from(contentId);
final MoveNodeParams.Builder builder = MoveNodeParams.create().nodeId(sourceNodeId).parentNodePath(newParentPath).moveListener(this);
if (params.stopInherit()) {
builder.processor(new MoveContentProcessor());
}
final Node movedNode = nodeService.move(builder.build());
final Content movedContent = translator.fromNode(movedNode, true);
return MoveContentsResult.create().setContentName(movedContent.getDisplayName()).addMoved(movedContent.getId()).build();
}
use of com.enonic.xp.node.NodeId in project xp by enonic.
the class ResolveContentsToBePublishedCommand method getWorkResult.
private ResolveSyncWorkResult getWorkResult(final ContentId contentId) {
final NodeIds nodeIds = excludedContentIds != null ? NodeIds.from(excludedContentIds.stream().map(id -> NodeId.from(id.toString())).collect(Collectors.toList())) : NodeIds.empty();
final boolean includeChildren = excludeChildrenIds == null || !this.excludeChildrenIds.contains(contentId);
return nodeService.resolveSyncWork(SyncWorkResolverParams.create().includeChildren(includeChildren).includeDependencies(this.includeDependencies).nodeId(NodeId.from(contentId.toString())).excludedNodeIds(nodeIds).branch(this.target).statusesToStopDependenciesSearch(Set.of(CompareStatus.EQUAL)).build());
}
Aggregations