Search in sources :

Example 6 with ValueFilter

use of com.enonic.xp.query.filter.ValueFilter in project xp by enonic.

the class QueryBuilderFactoryTest method createQueryWithFilter.

@Test
public void createQueryWithFilter() throws Exception {
    final String expected = load("query_with_queryfilter.json");
    final ValueFilter queryFilter = ValueFilter.create().fieldName("myField").addValue(ValueFactory.newString("myValue1")).addValue(ValueFactory.newString("myValue2")).build();
    final QueryExpr query = QueryParser.parse("not( myField > 1) ");
    final QueryBuilder builtQuery = QueryBuilderFactory.newBuilder().queryExpr(query).addQueryFilter(queryFilter).fieldNameResolver(new SearchQueryFieldNameResolver()).build().create();
    final String expectedJson = cleanString(expected);
    final String actualJson = cleanString(builtQuery.toString());
    assertEquals(expectedJson, actualJson);
}
Also used : QueryExpr(com.enonic.xp.query.expr.QueryExpr) ValueFilter(com.enonic.xp.query.filter.ValueFilter) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) SearchQueryFieldNameResolver(com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver) Test(org.junit.jupiter.api.Test)

Example 7 with ValueFilter

use of com.enonic.xp.query.filter.ValueFilter in project xp by enonic.

the class AbstractBlobVacuumTaskTest method setUp.

public void setUp() throws Exception {
    this.blobStore = new MemoryBlobStore();
    this.nodeService = Mockito.mock(NodeService.class);
    Mockito.when(nodeService.findVersions(Mockito.any(NodeVersionQuery.class))).thenAnswer((invocation) -> {
        final NodeVersionQuery query = invocation.getArgument(0);
        final ValueFilter valueFilter = (ValueFilter) query.getQueryFilters().first();
        if (valueFilter.getValues().contains(ValueFactory.newString(createBlobKey('a').toString()))) {
            return NodeVersionQueryResult.empty(1);
        }
        return NodeVersionQueryResult.empty(0);
    });
}
Also used : NodeVersionQuery(com.enonic.xp.node.NodeVersionQuery) NodeService(com.enonic.xp.node.NodeService) ValueFilter(com.enonic.xp.query.filter.ValueFilter) MemoryBlobStore(com.enonic.xp.internal.blobstore.MemoryBlobStore)

Example 8 with ValueFilter

use of com.enonic.xp.query.filter.ValueFilter in project xp by enonic.

the class ContentQueryNodeQueryTranslator method translate.

public static NodeQuery.Builder translate(final ContentQuery contentQuery) {
    final NodeQuery.Builder builder = NodeQuery.create();
    final ValueFilter contentCollectionFilter = ValueFilter.create().fieldName(NodeIndexPath.NODE_TYPE.getPath()).addValue(ValueFactory.newString(ContentConstants.CONTENT_NODE_COLLECTION.getName())).build();
    builder.query(buildNodeQueryExpr(contentQuery)).from(contentQuery.getFrom()).size(contentQuery.getSize()).addAggregationQueries(contentQuery.getAggregationQueries()).addQueryFilters(contentQuery.getQueryFilters()).addQueryFilter(contentCollectionFilter).highlight(contentQuery.getHighlight());
    processContentTypesNames(contentQuery, builder);
    processReferenceIds(contentQuery, builder);
    return builder;
}
Also used : NodeQuery(com.enonic.xp.node.NodeQuery) ValueFilter(com.enonic.xp.query.filter.ValueFilter)

Example 9 with ValueFilter

use of com.enonic.xp.query.filter.ValueFilter 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 10 with ValueFilter

use of com.enonic.xp.query.filter.ValueFilter 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)

Aggregations

ValueFilter (com.enonic.xp.query.filter.ValueFilter)10 Test (org.junit.jupiter.api.Test)6 NodeQuery (com.enonic.xp.node.NodeQuery)3 Filter (com.enonic.xp.query.filter.Filter)3 SearchQueryFieldNameResolver (com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver)3 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)3 PrincipalKey (com.enonic.xp.security.PrincipalKey)2 ContentId (com.enonic.xp.content.ContentId)1 ContentIds (com.enonic.xp.content.ContentIds)1 MemoryBlobStore (com.enonic.xp.internal.blobstore.MemoryBlobStore)1 IssueStatus (com.enonic.xp.issue.IssueStatus)1 IssueType (com.enonic.xp.issue.IssueType)1 NodeService (com.enonic.xp.node.NodeService)1 NodeVersionQuery (com.enonic.xp.node.NodeVersionQuery)1 QueryExpr (com.enonic.xp.query.expr.QueryExpr)1 BooleanFilter (com.enonic.xp.query.filter.BooleanFilter)1 ExistsFilter (com.enonic.xp.query.filter.ExistsFilter)1 Filters (com.enonic.xp.query.filter.Filters)1 PrincipalKeys (com.enonic.xp.security.PrincipalKeys)1 Principals (com.enonic.xp.security.Principals)1