use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class FindNodesByQueryCommandTest_compare method compare_gt.
@Test
public void compare_gt() throws Exception {
final PropertyTree data = new PropertyTree();
data.setDouble("my-value", 5.5);
createNode(CreateNodeParams.create().name("my-node-1").parent(NodePath.ROOT).data(data).build());
final PropertyTree data2 = new PropertyTree();
data2.setDouble("my-value", 10.0);
final Node node2 = createNode(CreateNodeParams.create().name("my-node-2").parent(NodePath.ROOT).data(data2).build());
final NodeQuery query = NodeQuery.create().query(QueryExpr.from(CompareExpr.gt(FieldExpr.from(IndexPath.from("my-value")), ValueExpr.number(7)))).build();
final FindNodesByQueryResult result = doFindByQuery(query);
assertEquals(1, result.getNodeIds().getSize());
assertTrue(result.getNodeIds().contains(node2.id()));
}
use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class CleanUpAuditLogCommand method createQuery.
private NodeQuery createQuery() {
final NodeQuery.Builder builder = NodeQuery.create().addQueryFilter(ValueFilter.create().fieldName(NodeIndexPath.NODE_TYPE.toString()).addValue(ValueFactory.newString(AuditLogConstants.NODE_TYPE.toString())).build());
final RangeFilter timeToFilter = RangeFilter.create().fieldName(AuditLogConstants.TIME.toString()).to(ValueFactory.newDateTime(until)).build();
builder.addQueryFilter(timeToFilter);
builder.addOrderBy(FieldOrderExpr.create(AuditLogConstants.TIME, OrderExpr.Direction.ASC)).size(BATCH_SIZE);
return builder.build();
}
use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class FindAuditLogCommand method runQuery.
private FindAuditLogResult runQuery() {
final NodeQuery query = createQuery();
if (query == null) {
return FindAuditLogResult.empty();
}
FindNodesByQueryResult result = nodeService.findByQuery(query);
List<AuditLog> logs = result.getNodeIds().stream().map(nodeService::getById).map(AuditLogSerializer::fromNode).collect(Collectors.toList());
return FindAuditLogResult.create().total(result.getTotalHits()).hits(AuditLogs.from(logs)).build();
}
use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class CreateIssueCommand method countTotalIssues.
private long countTotalIssues() {
final IssueQuery query = IssueQuery.create().size(0).count(true).build();
final NodeQuery nodeQuery = IssueQueryNodeQueryTranslator.translate(query);
final FindNodesByQueryResult result = nodeService.findByQuery(nodeQuery);
return result.getTotalHits();
}
use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class FindeNodesByQueryCommandTest_like method queryAndExpect.
private void queryAndExpect(final String queryString, final int expected) {
final NodeQuery query = NodeQuery.create().query(QueryParser.parse(queryString)).build();
final FindNodesByQueryResult result = doFindByQuery(query);
assertEquals(expected, result.getHits());
}
Aggregations