use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class FindNodesByQueryHandler method execute.
@Override
public Object execute() {
final NodeQuery nodeQuery = createNodeQuery();
final FindNodesByQueryResult result = nodeService.findByQuery(nodeQuery);
return convert(result);
}
use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class CleanUpAuditLogCommand method doCleanUp.
private CleanUpAuditLogResult doCleanUp() {
final CleanUpAuditLogResult.Builder result = CleanUpAuditLogResult.create();
final NodeQuery query = createQuery();
nodeService.refresh(RefreshMode.ALL);
FindNodesByQueryResult nodesToDelete = nodeService.findByQuery(query);
long hits = nodesToDelete.getHits();
final long totalHits = nodesToDelete.getTotalHits();
if (totalHits == 0) {
return CleanUpAuditLogResult.empty();
}
listener.start(BATCH_SIZE);
while (hits > 0) {
for (NodeHit nodeHit : nodesToDelete.getNodeHits()) {
result.deleted(nodeService.deleteById(nodeHit.getNodeId()).getSize());
listener.processed();
}
nodesToDelete = nodeService.findByQuery(query);
hits = nodesToDelete.getHits();
}
listener.finished();
return result.build();
}
use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class SetPublishInfoCommand method findNodesWithoutPublishFirstAndFrom.
private NodeIds findNodesWithoutPublishFirstAndFrom(final NodeIds nodesToPush) {
if (nodesToPush.isEmpty()) {
return NodeIds.empty();
}
final BooleanFilter containPublishFirstAndFromFilter = BooleanFilter.create().must(ExistsFilter.create().fieldName(ContentIndexPath.PUBLISH_FIRST.getPath()).build()).must(ExistsFilter.create().fieldName(ContentIndexPath.PUBLISH_FROM.getPath()).build()).build();
final NodeQuery query = NodeQuery.create().addQueryFilter(BooleanFilter.create().mustNot(containPublishFirstAndFromFilter).must(IdFilter.create().fieldName(ContentIndexPath.ID.getPath()).values(nodesToPush).build()).build()).size(NodeQuery.ALL_RESULTS_SIZE_FLAG).build();
final FindNodesByQueryResult result = this.nodeService.findByQuery(query);
return result.getNodeIds();
}
use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class DateHistogramAggregationsTest method intervals.
@Test
public void intervals() throws Exception {
createNode(Instant.parse("2014-12-10T10:00:00Z"), "n1", NodePath.ROOT);
createNode(Instant.parse("2014-12-10T10:30:00Z"), "n2", NodePath.ROOT);
createNode(Instant.parse("2014-12-10T11:30:00Z"), "n3", NodePath.ROOT);
createNode(Instant.parse("2014-12-10T12:45:00Z"), "n4", NodePath.ROOT);
createNode(Instant.parse("2014-12-10T13:59:59Z"), "n5", NodePath.ROOT);
createNode(Instant.parse("2014-12-10T14:01:00Z"), "n6", NodePath.ROOT);
final NodeQuery query = NodeQuery.create().addAggregationQuery(DateHistogramAggregationQuery.create("hour").format("Y-MM-DD").fieldName("instant").interval("1h").build()).addAggregationQuery(DateHistogramAggregationQuery.create("day").fieldName("instant").interval("1d").build()).addAggregationQuery(DateHistogramAggregationQuery.create("minute").fieldName("instant").interval("1m").build()).build();
FindNodesByQueryResult result = doFindByQuery(query);
assertEquals(3, result.getAggregations().getSize());
final BucketAggregation hour = (BucketAggregation) result.getAggregations().get("hour");
final BucketAggregation day = (BucketAggregation) result.getAggregations().get("day");
final BucketAggregation minute = (BucketAggregation) result.getAggregations().get("minute");
assertEquals(5, hour.getBuckets().getSize());
assertEquals(1, day.getBuckets().getSize());
assertEquals(6, minute.getBuckets().getSize());
}
use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class DateHistogramAggregationsTest method format.
@Test
public void format() throws Exception {
// Create 5 nodes with two hours between
createNode(Instant.parse("2014-12-10T10:30:00Z"), "n1", NodePath.ROOT);
createNode(Instant.parse("2014-12-10T10:40:00Z"), "n2", NodePath.ROOT);
final NodeQuery query = NodeQuery.create().addAggregationQuery(DateHistogramAggregationQuery.create("hhMM").fieldName("instant").interval("1h").format("HH:mm").build()).addAggregationQuery(DateHistogramAggregationQuery.create("mm").fieldName("instant").interval("1h").format("mm").build()).build();
FindNodesByQueryResult result = doFindByQuery(query);
assertEquals(2, result.getAggregations().getSize());
// The min-doc-count=0 will also return the empty fill-ins
final BucketAggregation hhMM = (BucketAggregation) result.getAggregations().get("hhMM");
final BucketAggregation mm = (BucketAggregation) result.getAggregations().get("mm");
assertEquals(1, hhMM.getBuckets().getSize());
assertEquals(1, mm.getBuckets().getSize());
assertEquals("10:00", hhMM.getBuckets().first().getKey());
assertEquals("00", mm.getBuckets().first().getKey());
}
Aggregations