Search in sources :

Example 1 with CompareExpr

use of com.enonic.xp.query.expr.CompareExpr in project xp by enonic.

the class ContentQueryNodeQueryTranslator method buildNodeQueryExpr.

private static QueryExpr buildNodeQueryExpr(final ContentQuery contentQuery) {
    final QueryExpr queryExpr = contentQuery.getQueryExpr();
    final CompareExpr contentPathRootExpr = CompareExpr.like(FieldExpr.from("_path"), ValueExpr.string(ContentNodeHelper.getContentRoot() + "/*"));
    if (queryExpr != null) {
        final ConstraintExpr newExpr = queryExpr.getConstraint() != null ? LogicalExpr.and(queryExpr.getConstraint(), contentPathRootExpr) : contentPathRootExpr;
        return QueryExpr.from(newExpr, queryExpr.getOrderList());
    }
    return QueryExpr.from(contentPathRootExpr);
}
Also used : ConstraintExpr(com.enonic.xp.query.expr.ConstraintExpr) QueryExpr(com.enonic.xp.query.expr.QueryExpr) CompareExpr(com.enonic.xp.query.expr.CompareExpr)

Example 2 with CompareExpr

use of com.enonic.xp.query.expr.CompareExpr in project xp by enonic.

the class ReorderChildNodeCommand method createFirstNodeBeforeInsertQuery.

private NodeQuery createFirstNodeBeforeInsertQuery(final Long nodeAfterOrderValue) {
    final CompareExpr orderGreaterThanNodeToMoveBefore = CompareExpr.gt(FieldExpr.from(NodeIndexPath.MANUAL_ORDER_VALUE), ValueExpr.number(nodeAfterOrderValue));
    final CompareExpr parentPathEqualToParent = CompareExpr.eq(FieldExpr.from(NodeIndexPath.PARENT_PATH), ValueExpr.string(parentNode.path().toString()));
    final LogicalExpr constraint = LogicalExpr.and(orderGreaterThanNodeToMoveBefore, parentPathEqualToParent);
    final FieldOrderExpr orderManuallyDesc = FieldOrderExpr.create(NodeIndexPath.MANUAL_ORDER_VALUE, OrderExpr.Direction.ASC);
    return NodeQuery.create().query(QueryExpr.from(constraint, orderManuallyDesc)).size(1).build();
}
Also used : FieldOrderExpr(com.enonic.xp.query.expr.FieldOrderExpr) CompareExpr(com.enonic.xp.query.expr.CompareExpr) LogicalExpr(com.enonic.xp.query.expr.LogicalExpr)

Example 3 with CompareExpr

use of com.enonic.xp.query.expr.CompareExpr in project xp by enonic.

the class NotQueryBuilderTest method negate_term.

@Test
public void negate_term() throws Exception {
    final String expected = load("not_term.json");
    final CompareExpr compareExpr = CompareExpr.create(FieldExpr.from("fisk"), CompareExpr.Operator.EQ, ValueExpr.string("ost"));
    final QueryBuilder query = NotQueryBuilder.build(CompareExpressionBuilder.build(compareExpr, new SearchQueryFieldNameResolver()));
    assertEquals(cleanString(expected), cleanString(query.toString()));
}
Also used : CompareExpr(com.enonic.xp.query.expr.CompareExpr) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) SearchQueryFieldNameResolver(com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver) Test(org.junit.jupiter.api.Test)

Example 4 with CompareExpr

use of com.enonic.xp.query.expr.CompareExpr in project xp by enonic.

the class SecurityServiceImpl method findByUsername.

private User findByUsername(final IdProviderKey idProvider, final String username) {
    final CompareExpr idProviderExpr = CompareExpr.create(FieldExpr.from(PrincipalIndexPath.ID_PROVIDER_KEY), CompareExpr.Operator.EQ, ValueExpr.string(idProvider.toString()));
    final CompareExpr userNameExpr = CompareExpr.create(FieldExpr.from(PrincipalIndexPath.LOGIN_KEY), CompareExpr.Operator.EQ, ValueExpr.string(username));
    final QueryExpr query = QueryExpr.from(LogicalExpr.and(idProviderExpr, userNameExpr));
    final Nodes nodes = callWithContext(() -> {
        final FindNodesByQueryResult result = nodeService.findByQuery(NodeQuery.create().query(query).build());
        return this.nodeService.getByIds(result.getNodeIds());
    });
    if (nodes.getSize() > 1) {
        throw new IllegalArgumentException("Expected at most 1 user with username " + username + " in id provider " + idProvider);
    }
    return nodes.isEmpty() ? null : PrincipalNodeTranslator.userFromNode(nodes.first());
}
Also used : CompareExpr(com.enonic.xp.query.expr.CompareExpr) QueryExpr(com.enonic.xp.query.expr.QueryExpr) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Nodes(com.enonic.xp.node.Nodes)

Example 5 with CompareExpr

use of com.enonic.xp.query.expr.CompareExpr in project xp by enonic.

the class GetBranchDataCommand method doExecute.

private SearchResult doExecute() {
    final CompareExpr compareExpr = CompareExpr.create(FieldExpr.from(BranchIndexPath.BRANCH_NAME.getPath()), CompareExpr.Operator.EQ, ValueExpr.string(branch.getValue()));
    final Context reindexContext = ContextBuilder.from(ContextAccessor.current()).repositoryId(this.repositoryId).branch(branch).build();
    return this.nodeSearchService.query(NodeBranchQuery.create().query(QueryExpr.from(compareExpr)).size(NodeSearchService.GET_ALL_SIZE_FLAG).build(), SingleRepoStorageSource.create(reindexContext.getRepositoryId(), SingleRepoStorageSource.Type.BRANCH));
}
Also used : Context(com.enonic.xp.context.Context) CompareExpr(com.enonic.xp.query.expr.CompareExpr)

Aggregations

CompareExpr (com.enonic.xp.query.expr.CompareExpr)7 QueryExpr (com.enonic.xp.query.expr.QueryExpr)4 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)3 Nodes (com.enonic.xp.node.Nodes)3 Context (com.enonic.xp.context.Context)1 ConstraintExpr (com.enonic.xp.query.expr.ConstraintExpr)1 FieldOrderExpr (com.enonic.xp.query.expr.FieldOrderExpr)1 LogicalExpr (com.enonic.xp.query.expr.LogicalExpr)1 SearchQueryFieldNameResolver (com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver)1 User (com.enonic.xp.security.User)1 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)1 Test (org.junit.jupiter.api.Test)1