use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.
the class SecurityServiceImpl method query.
@Override
public PrincipalQueryResult query(final PrincipalQuery query) {
try {
final NodeQuery nodeQueryBuilder = PrincipalQueryNodeQueryTranslator.translate(query);
final FindNodesByQueryResult result = callWithContext(() -> this.nodeService.findByQuery(nodeQueryBuilder));
final Nodes nodes = callWithContext(() -> this.nodeService.getByIds(result.getNodeIds()));
final Principals principals = PrincipalNodeTranslator.fromNodes(nodes);
return PrincipalQueryResult.create().addPrincipals(principals).totalSize(Ints.checkedCast(result.getTotalHits())).build();
} catch (NodeNotFoundException e) {
return PrincipalQueryResult.create().build();
}
}
use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.
the class SecurityServiceImpl method query.
@Override
public UserQueryResult query(final UserQuery query) {
try {
final NodeQuery nodeQueryBuilder = UserQueryNodeQueryTranslator.translate(query);
final FindNodesByQueryResult result = callWithContext(() -> this.nodeService.findByQuery(nodeQueryBuilder));
final Nodes nodes = callWithContext(() -> this.nodeService.getByIds(result.getNodeIds()));
final Principals principals = PrincipalNodeTranslator.fromNodes(nodes);
return UserQueryResult.create().addUsers(principals).totalSize(Ints.checkedCast(result.getTotalHits())).build();
} catch (NodeNotFoundException e) {
return UserQueryResult.create().build();
}
}
use of com.enonic.xp.node.FindNodesByQueryResult 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.node.FindNodesByQueryResult in project xp by enonic.
the class AbstractNodeTest method queryAndAssert.
protected void queryAndAssert(final String queryString, final int expected) {
final FindNodesByQueryResult result = doQuery(queryString);
assertEquals(expected, result.getNodeIds().getSize());
}
use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.
the class ValueCountAggregationTest method testCountAggregation.
@Test
public void testCountAggregation() {
createNode("c1", "n1", NodePath.ROOT);
createNode("c2", "n2", NodePath.ROOT);
createNode("c3", "n3", NodePath.ROOT);
createNode(null, "n4", NodePath.ROOT);
NodeQuery query = NodeQuery.create().addAggregationQuery(ValueCountAggregationQuery.create("testCountAgg").fieldName("category").build()).build();
FindNodesByQueryResult result = doFindByQuery(query);
assertEquals(1, result.getAggregations().getSize());
Aggregation agg = result.getAggregations().get("testCountAgg");
assertTrue(agg instanceof SingleValueMetricAggregation);
SingleValueMetricAggregation categoryAgg = (SingleValueMetricAggregation) agg;
assertEquals(3, categoryAgg.getValue());
}
Aggregations