Search in sources :

Example 31 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult 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();
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery) AuditLog(com.enonic.xp.audit.AuditLog)

Example 32 with FindNodesByQueryResult

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

the class NodesHasPermissionResolver method execute.

public boolean execute() {
    final Context context = ContextAccessor.current();
    if (context.getAuthInfo().hasRole(RoleKeys.ADMIN)) {
        return true;
    }
    if (nodeIds.isEmpty()) {
        return false;
    }
    final NodeQuery query = NodeQuery.create().addQueryFilter(IdFilter.create().fieldName(NodeIndexPath.ID.getPath()).values(nodeIds).build()).addQueryFilter(ValueFilter.create().fieldName(getPermissionFieldName().getPath()).addValues(context.getAuthInfo().getPrincipals().stream().map(PrincipalKey::toString).collect(Collectors.toList())).build()).searchMode(SearchMode.COUNT).build();
    final FindNodesByQueryResult result = FindNodesByQueryCommand.create(this).query(query).build().execute();
    return result.getTotalHits() == nodeIds.getSize();
}
Also used : Context(com.enonic.xp.context.Context) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery) PrincipalKey(com.enonic.xp.security.PrincipalKey)

Example 33 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult 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();
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery) IssueQuery(com.enonic.xp.issue.IssueQuery)

Example 34 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult 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());
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery)

Example 35 with FindNodesByQueryResult

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

the class FindNodesByQueryCommandTest_order_geoDistance method order_by_odd_geopoint.

@Test
public void order_by_odd_geopoint() throws Exception {
    createGeoLocations();
    final FindNodesByQueryResult result = doQuery("_parentPath = '/' ORDER BY geoDistance('myLocation', '" + ODD_GEOPOINT.getLatitude() + "," + ODD_GEOPOINT.getLongitude() + "')");
    assertEquals(result.getNodeIds().getSize(), 8);
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Test(org.junit.jupiter.api.Test)

Aggregations

FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)84 NodeQuery (com.enonic.xp.node.NodeQuery)61 Test (org.junit.jupiter.api.Test)55 Node (com.enonic.xp.node.Node)32 BucketAggregation (com.enonic.xp.aggregation.BucketAggregation)19 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)19 Bucket (com.enonic.xp.aggregation.Bucket)14 PropertyTree (com.enonic.xp.data.PropertyTree)13 Nodes (com.enonic.xp.node.Nodes)9 DynamicConstraintExpr (com.enonic.xp.query.expr.DynamicConstraintExpr)9 Aggregation (com.enonic.xp.aggregation.Aggregation)8 Buckets (com.enonic.xp.aggregation.Buckets)6 QueryExpr (com.enonic.xp.query.expr.QueryExpr)4 DateRangeBucket (com.enonic.xp.aggregation.DateRangeBucket)3 NodeHit (com.enonic.xp.node.NodeHit)3 CompareExpr (com.enonic.xp.query.expr.CompareExpr)3 NumericRangeBucket (com.enonic.xp.aggregation.NumericRangeBucket)2 SingleValueMetricAggregation (com.enonic.xp.aggregation.SingleValueMetricAggregation)2 ContentId (com.enonic.xp.content.ContentId)2 Context (com.enonic.xp.context.Context)2