use of com.enonic.xp.query.expr.QueryExpr in project xp by enonic.
the class QueryParserTest method testQuery.
private void testQuery(final String query, final String expected) {
final QueryExpr expr = QueryParser.parse(query);
assertNotNull(expr);
assertEquals(expected, expr.toString());
}
use of com.enonic.xp.query.expr.QueryExpr 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.QueryExpr in project xp by enonic.
the class SetNodeChildOrderCommand method orderChildNodes.
private void orderChildNodes(final Node parentNode) {
final SearchResult result = nodeSearchService.query(NodeQuery.create().parent(parentNode.path()).query(new QueryExpr(parentNode.getChildOrder().getOrderExpressions())).size(NodeSearchService.GET_ALL_SIZE_FLAG).batchSize(BATCH_SIZE).searchMode(SearchMode.SEARCH).build(), SingleRepoSearchSource.from(ContextAccessor.current()));
final NodeIds childNodeIds = NodeIds.from(result.getIds());
final List<NodeManualOrderValueResolver.NodeIdOrderValue> orderedNodeIds = NodeManualOrderValueResolver.resolve(childNodeIds);
for (final NodeManualOrderValueResolver.NodeIdOrderValue nodeIdOrderValue : orderedNodeIds) {
final Node node = doGetById(nodeIdOrderValue.getNodeId());
final Node editedNode = Node.create(node).manualOrderValue(nodeIdOrderValue.getManualOrderValue()).timestamp(Instant.now(CLOCK)).build();
StoreNodeCommand.create(this).node(editedNode).build().execute();
}
}
use of com.enonic.xp.query.expr.QueryExpr 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.QueryExpr 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);
}
Aggregations