use of com.enonic.xp.node.NodePath in project xp by enonic.
the class ContentServiceImpl method getRootPermissions.
@Override
public AccessControlList getRootPermissions() {
final ContentPath rootContentPath = ContentPath.ROOT;
final NodePath rootNodePath = ContentNodeHelper.translateContentPathToNodePath(rootContentPath);
final Node rootNode = nodeService.getByPath(rootNodePath);
return rootNode != null ? rootNode.getPermissions() : AccessControlList.empty();
}
use of com.enonic.xp.node.NodePath in project xp by enonic.
the class DeleteContentCommand method doExecute.
private DeleteContentsResult doExecute() {
this.nodeService.refresh(RefreshMode.ALL);
final NodePath nodePath = ContentNodeHelper.translateContentPathToNodePath(this.params.getContentPath());
final Node nodeToDelete = this.nodeService.getByPath(nodePath);
if (nodeToDelete == null) {
throw new ContentNotFoundException(this.params.getContentPath(), ContextAccessor.current().getBranch());
}
if (!params.isDeleteOnline()) {
final NodeIds draftChildren = this.nodeService.findByParent(FindNodesByParentParams.create().parentId(nodeToDelete.id()).recursive(true).build()).getNodeIds();
final boolean anyChildIsMovedIn = nodeService.compare(draftChildren, ContentConstants.BRANCH_MASTER).getComparisons().stream().anyMatch(nodeComparison -> {
final boolean moved = CompareStatus.MOVED.equals(nodeComparison.getCompareStatus());
return moved && !nodeComparison.getTargetPath().asAbsolute().toString().startsWith(nodePath.asAbsolute().toString());
});
if (anyChildIsMovedIn) {
throw new RuntimeException(String.format("Cannot make content tree pending delete for [%s], at least one published child is moved in from outside.", nodeToDelete.id()));
}
}
final DeleteContentsResult deletedContents = doDeleteContent(nodeToDelete.id());
this.nodeService.refresh(RefreshMode.ALL);
return deletedContents;
}
use of com.enonic.xp.node.NodePath in project xp by enonic.
the class GetContentByPathCommand method execute.
Content execute() {
final NodePath nodePath = ContentNodeHelper.translateContentPathToNodePath(contentPath);
final Node node = nodeService.getByPath(nodePath);
if (node == null) {
return null;
}
final Content content = translator.fromNode(node, true);
return filter(content);
}
use of com.enonic.xp.node.NodePath 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.NodePath in project xp by enonic.
the class ParentContentSynchronizer method doSyncWithChildren.
private void doSyncWithChildren(final Collection<ContentToSync> sourceContents) {
final Queue<ContentToSync> queue = new ArrayDeque<>(sourceContents);
final Map<NodePath, Context> targetContexts = !sourceContents.isEmpty() ? initContexts(ProjectName.from(sourceContents.stream().findAny().get().getTargetContext().getRepositoryId())) : Map.of();
final List<ContentToSync> contentsToSync = sourceContents.stream().filter(sourceContent -> {
final Content root = sourceContent.getSourceContext().callWith(() -> contentService.getByPath(ContentPath.ROOT));
return !root.getId().equals(sourceContent.getSourceContent().getId());
}).collect(Collectors.toList());
if (!contentsToSync.isEmpty()) {
this.doSync(contentsToSync);
}
while (queue.size() > 0) {
final ContentToSync currentContentToSync = queue.poll();
final FindContentByParentResult result = currentContentToSync.getSourceContext().callWith(() -> contentService.findByParent(FindContentByParentParams.create().parentId(currentContentToSync.getId()).recursive(false).childOrder(currentContentToSync.getSourceContent().getChildOrder()).size(-1).build()));
if (result.getContents().isNotEmpty()) {
final List<ContentToSync> childrenToSync = result.getContents().stream().map(content -> {
final Context actualTargetContext = getActualContext(content.getId(), targetContexts.values());
return ContentToSync.create().sourceContent(content).targetContent(actualTargetContext != null ? actualTargetContext.callWith(() -> contentService.getById(content.getId())) : null).sourceContext(currentContentToSync.getSourceContext()).targetContext(actualTargetContext != null ? actualTargetContext : currentContentToSync.getTargetContext()).build();
}).collect(Collectors.toList());
this.doSync(childrenToSync);
for (final ContentToSync content : childrenToSync) {
if (content.getSourceContent().hasChildren()) {
queue.offer(content);
}
}
}
}
sourceContents.forEach(sourceContent -> {
if (sourceContent.getTargetContent() != null) {
cleanDeletedContents(sourceContent);
return;
}
final Content root = sourceContent.getSourceContext().callWith(() -> contentService.getByPath(ContentPath.ROOT));
if (root.getId().equals(sourceContent.getSourceContent().getId())) {
cleanDeletedContents(ContentToSync.create(sourceContent).targetContent(sourceContent.getTargetContext().callWith(() -> contentService.getByPath(ContentPath.ROOT))).build());
}
});
}
Aggregations