Search in sources :

Example 41 with NodeQuery

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

the class IssueCommentQueryNodeQueryTranslator method translate.

public static NodeQuery translate(final IssueCommentQuery issueCommentQuery, NodeName parentName) {
    final NodeQuery.Builder builder = NodeQuery.create();
    builder.parent(NodePath.create(IssueConstants.ISSUE_ROOT_PATH, parentName.toString()).build());
    final ValueFilter issueCommentsCollectionFilter = ValueFilter.create().fieldName(NodeIndexPath.NODE_TYPE.getPath()).addValue(ValueFactory.newString(IssueCommentConstants.NODE_COLLECTION.getName())).build();
    if (issueCommentQuery.isCount()) {
        builder.searchMode(SearchMode.COUNT);
    }
    builder.from(issueCommentQuery.getFrom()).size(issueCommentQuery.getSize()).addQueryFilter(issueCommentsCollectionFilter);
    final PrincipalKey creator = issueCommentQuery.getCreator();
    if (creator != null) {
        builder.addQueryFilter(ValueFilter.create().fieldName(CREATOR).addValues(creator.toString()).build());
    }
    builder.setOrderExpressions(issueCommentQuery.getOrder().getOrderExpressions());
    return builder.build();
}
Also used : NodeQuery(com.enonic.xp.node.NodeQuery) ValueFilter(com.enonic.xp.query.filter.ValueFilter) PrincipalKey(com.enonic.xp.security.PrincipalKey)

Example 42 with NodeQuery

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

the class IssueQueryNodeQueryTranslator method translate.

public static NodeQuery translate(final IssueQuery issueQuery) {
    final NodeQuery.Builder builder = NodeQuery.create();
    final ValueFilter issueCollectionFilter = ValueFilter.create().fieldName(NodeIndexPath.NODE_TYPE.getPath()).addValue(ValueFactory.newString(IssueConstants.ISSUE_NODE_COLLECTION.getName())).build();
    if (issueQuery.isCount()) {
        builder.searchMode(SearchMode.COUNT);
    }
    builder.from(issueQuery.getFrom()).size(issueQuery.getSize()).addQueryFilter(issueCollectionFilter);
    final PrincipalKey creator = issueQuery.getCreator();
    if (creator != null) {
        builder.addQueryFilter(ValueFilter.create().fieldName(CREATOR).addValues(creator.toString()).build());
    }
    final PrincipalKeys approvers = issueQuery.getApprovers();
    if (approvers != null && approvers.isNotEmpty()) {
        builder.addQueryFilter(ValueFilter.create().fieldName(APPROVERS).addValues(approvers.stream().map(PrincipalKey::toString).collect(toList())).build());
    }
    final ContentIds items = issueQuery.getItems();
    if (items != null && items.isNotEmpty()) {
        builder.addQueryFilter(ValueFilter.create().fieldName(PUBLISH_REQUEST_ITEM_ID).addValues(items.stream().map(ContentId::toString).collect(toList())).build());
    }
    final IssueStatus status = issueQuery.getStatus();
    if (status != null) {
        builder.addQueryFilter(ValueFilter.create().fieldName(STATUS).addValues(status.toString()).build());
    }
    final IssueType type = issueQuery.getType();
    if (type != null) {
        final Filter isOfType = ValueFilter.create().fieldName(TYPE).addValues(type.toString()).build();
        if (type == IssueType.STANDARD) {
            final Filter notExists = BooleanFilter.create().mustNot(ExistsFilter.create().fieldName(TYPE).build()).build();
            final Filter isStandard = BooleanFilter.create().should(isOfType).should(notExists).build();
            builder.addQueryFilter(isStandard);
        } else {
            builder.addQueryFilter(isOfType);
        }
    }
    builder.setOrderExpressions(IssueConstants.DEFAULT_CHILD_ORDER.getOrderExpressions());
    return builder.build();
}
Also used : PrincipalKeys(com.enonic.xp.security.PrincipalKeys) ExistsFilter(com.enonic.xp.query.filter.ExistsFilter) ValueFilter(com.enonic.xp.query.filter.ValueFilter) BooleanFilter(com.enonic.xp.query.filter.BooleanFilter) Filter(com.enonic.xp.query.filter.Filter) IssueType(com.enonic.xp.issue.IssueType) NodeQuery(com.enonic.xp.node.NodeQuery) ContentIds(com.enonic.xp.content.ContentIds) ValueFilter(com.enonic.xp.query.filter.ValueFilter) ContentId(com.enonic.xp.content.ContentId) PrincipalKey(com.enonic.xp.security.PrincipalKey) IssueStatus(com.enonic.xp.issue.IssueStatus)

Example 43 with NodeQuery

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

the class FindIssueCommentsCommand method execute.

public FindIssueCommentsResult execute() {
    validateBlockingChecks();
    final Node issue = nodeService.getById(NodeId.from(this.query.getIssue()));
    final NodeQuery nodeQuery = IssueCommentQueryNodeQueryTranslator.translate(this.query, issue.name());
    final FindNodesByQueryResult result = nodeService.findByQuery(nodeQuery);
    final Nodes foundNodes = this.nodeService.getByIds(result.getNodeIds());
    final List<IssueComment> issues = IssueCommentNodeTranslator.fromNodes(foundNodes);
    return FindIssueCommentsResult.create().comments(issues).hits(result.getHits()).totalHits(result.getTotalHits()).build();
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Node(com.enonic.xp.node.Node) NodeQuery(com.enonic.xp.node.NodeQuery) IssueComment(com.enonic.xp.issue.IssueComment) Nodes(com.enonic.xp.node.Nodes)

Example 44 with NodeQuery

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

the class FindIssuesCommand method execute.

public FindIssuesResult execute() {
    final NodeQuery nodeQuery = IssueQueryNodeQueryTranslator.translate(this.query);
    final FindNodesByQueryResult result = nodeService.findByQuery(nodeQuery);
    final Nodes foundNodes = this.nodeService.getByIds(result.getNodeIds());
    final List<Issue> issues = IssueNodeTranslator.fromNodes(foundNodes);
    return FindIssuesResult.create().issues(issues).hits(result.getHits()).totalHits(result.getTotalHits()).build();
}
Also used : Issue(com.enonic.xp.issue.Issue) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery) Nodes(com.enonic.xp.node.Nodes)

Example 45 with NodeQuery

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

the class NodeOrderTest method geo_distance_sorting.

@Test
public void geo_distance_sorting() throws Exception {
    final Node node1 = createNode("node1", ValueFactory.newGeoPoint(GeoPoint.from("80,80")));
    final Node node2 = createNode("node2", ValueFactory.newGeoPoint(GeoPoint.from("81,80")));
    final Node node3 = createNode("node3", ValueFactory.newGeoPoint(GeoPoint.from("82,80")));
    final Node node4 = createNode("node4", ValueFactory.newGeoPoint(GeoPoint.from("83,80")));
    final NodeQuery distanceQuery = NodeQuery.create().query(QueryExpr.from(null, new DynamicOrderExpr(FunctionExpr.from("geoDistance", ValueExpr.string("my-value"), ValueExpr.geoPoint("83,80")), OrderExpr.Direction.ASC))).build();
    final SearchResult result = searchService.query(distanceQuery, SingleRepoSearchSource.from(ContextAccessor.current()));
    final Iterator<String> iterator = result.getIds().iterator();
    assertEquals(node4.id(), NodeId.from(iterator.next()));
    assertEquals(node3.id(), NodeId.from(iterator.next()));
    assertEquals(node2.id(), NodeId.from(iterator.next()));
    assertEquals(node1.id(), NodeId.from(iterator.next()));
}
Also used : DynamicOrderExpr(com.enonic.xp.query.expr.DynamicOrderExpr) Node(com.enonic.xp.node.Node) NodeQuery(com.enonic.xp.node.NodeQuery) SearchResult(com.enonic.xp.repo.impl.search.result.SearchResult) Test(org.junit.jupiter.api.Test)

Aggregations

NodeQuery (com.enonic.xp.node.NodeQuery)74 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)59 Test (org.junit.jupiter.api.Test)45 Node (com.enonic.xp.node.Node)24 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)11 DynamicConstraintExpr (com.enonic.xp.query.expr.DynamicConstraintExpr)10 Aggregation (com.enonic.xp.aggregation.Aggregation)8 Buckets (com.enonic.xp.aggregation.Buckets)6 FindNodesByMultiRepoQueryResult (com.enonic.xp.node.FindNodesByMultiRepoQueryResult)6 MultiRepoNodeQuery (com.enonic.xp.node.MultiRepoNodeQuery)6 Nodes (com.enonic.xp.node.Nodes)5 SearchTargets (com.enonic.xp.node.SearchTargets)5 Repository (com.enonic.xp.repository.Repository)5 DateRangeBucket (com.enonic.xp.aggregation.DateRangeBucket)3 ContentId (com.enonic.xp.content.ContentId)3 NumericRangeBucket (com.enonic.xp.aggregation.NumericRangeBucket)2 SingleValueMetricAggregation (com.enonic.xp.aggregation.SingleValueMetricAggregation)2