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);
}
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();
}
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()));
}
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());
}
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));
}
Aggregations