Search in sources :

Example 1 with NodeIds

use of com.enonic.xp.node.NodeIds in project xp by enonic.

the class CommitNodeHandler method execute.

@Override
public NodeCommitEntryMapper execute() {
    final NodeCommitEntry nodeCommitEntry = NodeCommitEntry.create().message(message).build();
    final NodeIds nodeIds = getNodeIds();
    final NodeCommitEntry createdCommitEntry = nodeService.commit(nodeCommitEntry, nodeIds);
    return new NodeCommitEntryMapper(createdCommitEntry);
}
Also used : NodeIds(com.enonic.xp.node.NodeIds) NodeCommitEntryMapper(com.enonic.xp.lib.node.mapper.NodeCommitEntryMapper) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry)

Example 2 with NodeIds

use of com.enonic.xp.node.NodeIds in project xp by enonic.

the class DeleteNodeHandlerTest method mockGetNode.

private void mockGetNode() {
    Mockito.when(this.nodeService.deleteById(Mockito.any())).thenReturn(NodeIds.empty());
    Mockito.when(this.nodeService.deleteByPath(Mockito.any())).thenReturn(NodeIds.empty());
    final NodeIds nodeIds = NodeIds.from("nodeId", "aSubNodeId");
    Mockito.when(this.nodeService.deleteById(NodeId.from("nodeId"))).thenReturn(nodeIds);
    Mockito.when(this.nodeService.deleteByPath(NodePath.create("/node2-path").build())).thenReturn(nodeIds);
}
Also used : NodeIds(com.enonic.xp.node.NodeIds)

Example 3 with NodeIds

use of com.enonic.xp.node.NodeIds in project xp by enonic.

the class DeleteContentCommand method doDeleteContent.

private DeleteContentsResult doDeleteContent(NodeId nodeToDelete) {
    final CompareStatus rootNodeStatus = getCompareStatus(nodeToDelete);
    final DeleteContentsResult.Builder result = DeleteContentsResult.create();
    if (rootNodeStatus == CompareStatus.NEW) {
        // Root node is new, just delete all children
        final NodeIds nodes = this.nodeService.deleteById(nodeToDelete, this);
        result.addDeleted(ContentIds.from(nodes.getAsStrings()));
    } else if (this.params.isDeleteOnline()) {
        deleteNodeInDraftAndMaster(nodeToDelete, result);
    } else {
        this.nodeService.setNodeState(SetNodeStateParams.create().nodeId(nodeToDelete).nodeState(NodeState.PENDING_DELETE).build());
        result.addPending(ContentId.from(nodeToDelete.toString()));
        this.nodesDeleted(1);
        final NodeIds children = getDirectChildren(nodeToDelete);
        for (final NodeId child : children) {
            final DeleteContentsResult childDeleteResult = this.doDeleteContent(child);
            result.addDeleted(childDeleteResult.getDeletedContents());
            result.addPending(childDeleteResult.getPendingContents());
        }
    }
    return result.build();
}
Also used : NodeIds(com.enonic.xp.node.NodeIds) CompareStatus(com.enonic.xp.content.CompareStatus) NodeId(com.enonic.xp.node.NodeId) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult)

Example 4 with NodeIds

use of com.enonic.xp.node.NodeIds in project xp by enonic.

the class FindContentByQueryCommand method execute.

FindContentByQueryResult execute() {
    final NodeQuery nodeQuery = ContentQueryNodeQueryTranslator.translate(this.params.getContentQuery()).addQueryFilters(createFilters()).build();
    final FindNodesByQueryResult result = nodeService.findByQuery(nodeQuery);
    final NodeIds nodeIds = result.getNodeIds();
    final Map<ContentId, HighlightedProperties> highlight = result.getNodeHits().stream().filter(nodeHit -> nodeHit.getHighlight() != null && nodeHit.getHighlight().size() > 0).collect(Collectors.toMap(hit -> ContentId.from(hit.getNodeId().toString()), NodeHit::getHighlight));
    final Nodes foundNodes = this.nodeService.getByIds(nodeIds);
    Contents contents = this.translator.fromNodes(foundNodes, true);
    return FindContentByQueryResult.create().contents(contents).aggregations(result.getAggregations()).hits(result.getHits()).totalHits(result.getTotalHits()).highlight(highlight).build();
}
Also used : NodeHit(com.enonic.xp.node.NodeHit) Nodes(com.enonic.xp.node.Nodes) FindContentByQueryParams(com.enonic.xp.content.FindContentByQueryParams) Collectors(java.util.stream.Collectors) HighlightedProperties(com.enonic.xp.highlight.HighlightedProperties) ContentId(com.enonic.xp.content.ContentId) Contents(com.enonic.xp.content.Contents) Map(java.util.Map) FindContentByQueryResult(com.enonic.xp.content.FindContentByQueryResult) Preconditions(com.google.common.base.Preconditions) NodeQuery(com.enonic.xp.node.NodeQuery) NodeIds(com.enonic.xp.node.NodeIds) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Contents(com.enonic.xp.content.Contents) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeIds(com.enonic.xp.node.NodeIds) HighlightedProperties(com.enonic.xp.highlight.HighlightedProperties) NodeQuery(com.enonic.xp.node.NodeQuery) ContentId(com.enonic.xp.content.ContentId) Nodes(com.enonic.xp.node.Nodes)

Example 5 with NodeIds

use of com.enonic.xp.node.NodeIds in project xp by enonic.

the class GetContentByIdsCommand method doExecute.

private Contents doExecute() {
    final NodeIds nodeIds = getAsNodeIds(this.params.getIds());
    final Nodes nodes = nodeService.getByIds(nodeIds);
    return this.translator.fromNodes(nodes, true);
}
Also used : NodeIds(com.enonic.xp.node.NodeIds) Nodes(com.enonic.xp.node.Nodes)

Aggregations

NodeIds (com.enonic.xp.node.NodeIds)37 Node (com.enonic.xp.node.Node)12 NodeId (com.enonic.xp.node.NodeId)11 Test (org.junit.jupiter.api.Test)11 NodePath (com.enonic.xp.node.NodePath)6 Collectors (java.util.stream.Collectors)5 CompareStatus (com.enonic.xp.content.CompareStatus)4 ContentIds (com.enonic.xp.content.ContentIds)4 ContextAccessor (com.enonic.xp.context.ContextAccessor)4 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)4 NodeComparison (com.enonic.xp.node.NodeComparison)4 NodeComparisons (com.enonic.xp.node.NodeComparisons)4 NodeQuery (com.enonic.xp.node.NodeQuery)4 Branch (com.enonic.xp.branch.Branch)3 ContentId (com.enonic.xp.content.ContentId)3 DeleteContentsResult (com.enonic.xp.content.DeleteContentsResult)3 Context (com.enonic.xp.context.Context)3 ContentNotFoundException (com.enonic.xp.content.ContentNotFoundException)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 DeleteIssueCommentResult (com.enonic.xp.issue.DeleteIssueCommentResult)2