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