Search in sources :

Example 1 with Nodes

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

the class FindContentByParentCommand method execute.

FindContentByParentResult execute() {
    final FindNodesByParentResult result = nodeService.findByParent(createFindNodesByParentParams());
    final Nodes nodes = this.nodeService.getByIds(result.getNodeIds());
    final Contents contents = this.translator.fromNodes(nodes, true);
    return FindContentByParentResult.create().contents(contents).totalHits(result.getTotalHits()).hits(result.getHits()).build();
}
Also used : Contents(com.enonic.xp.content.Contents) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) Nodes(com.enonic.xp.node.Nodes)

Example 2 with Nodes

use of com.enonic.xp.node.Nodes 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 3 with Nodes

use of com.enonic.xp.node.Nodes 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)

Example 4 with Nodes

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

the class UnpublishContentCommand method removePendingDeleteFromDraft.

private void removePendingDeleteFromDraft(final UnpublishContentsResult result) {
    final Branch currentBranch = ContextAccessor.current().getBranch();
    if (!currentBranch.equals(ContentConstants.BRANCH_DRAFT)) {
        final Context draftContext = ContextBuilder.from(ContextAccessor.current()).branch(ContentConstants.BRANCH_DRAFT).build();
        draftContext.callWith(() -> {
            final Nodes draftNodes = this.nodeService.getByIds(NodeIds.from(result.getUnpublishedContents().asStrings()));
            for (final Node draftNode : draftNodes) {
                if (draftNode.getNodeState().value().equalsIgnoreCase(ContentState.PENDING_DELETE.toString())) {
                    this.nodeService.deleteById(draftNode.id());
                }
            }
            return null;
        });
    }
}
Also used : Context(com.enonic.xp.context.Context) Branch(com.enonic.xp.branch.Branch) Node(com.enonic.xp.node.Node) Nodes(com.enonic.xp.node.Nodes)

Example 5 with Nodes

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

the class ContentNodeTranslatorTest method testFromNodesResolvingChildren.

@Test
public void testFromNodesResolvingChildren() throws Exception {
    final Nodes nodes = createNodes();
    final NodesHasChildrenResult hasChildrenResult = NodesHasChildrenResult.create().add(ID_1, true).add(ID_2, true).add(ID_3, false).build();
    Mockito.when(this.nodeService.hasChildren(Mockito.any(Nodes.class))).thenReturn(hasChildrenResult);
    final Contents contents = this.contentNodeTranslator.fromNodes(nodes, true);
    assertEquals(3, contents.getSize());
    final Content content1 = contents.getContentById(ContentId.from(ID_1.toString()));
    final Content content3 = contents.getContentById(ContentId.from(ID_3.toString()));
    final Content content2 = contents.getContentById(ContentId.from(ID_2.toString()));
    assertTrue(content1.hasChildren());
    assertTrue(content2.hasChildren());
    assertFalse(content3.hasChildren());
}
Also used : NodesHasChildrenResult(com.enonic.xp.node.NodesHasChildrenResult) Contents(com.enonic.xp.content.Contents) Content(com.enonic.xp.content.Content) Nodes(com.enonic.xp.node.Nodes) Test(org.junit.jupiter.api.Test)

Aggregations

Nodes (com.enonic.xp.node.Nodes)31 Node (com.enonic.xp.node.Node)14 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)9 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)9 Test (org.junit.jupiter.api.Test)8 NodeQuery (com.enonic.xp.node.NodeQuery)5 Contents (com.enonic.xp.content.Contents)4 NodeIds (com.enonic.xp.node.NodeIds)3 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)3 CompareExpr (com.enonic.xp.query.expr.CompareExpr)3 QueryExpr (com.enonic.xp.query.expr.QueryExpr)3 Branch (com.enonic.xp.branch.Branch)2 Content (com.enonic.xp.content.Content)2 FindNodesByParentParams (com.enonic.xp.node.FindNodesByParentParams)2 NodePaths (com.enonic.xp.node.NodePaths)2 Principals (com.enonic.xp.security.Principals)2 AccessControlList (com.enonic.xp.security.acl.AccessControlList)2 Application (com.enonic.xp.app.Application)1 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 BlobKey (com.enonic.xp.blob.BlobKey)1