Search in sources :

Example 61 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.

the class PushNodesCommandTest method only_selected_node_pushed.

@Test
public void only_selected_node_pushed() throws Exception {
    final Node node = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("my-node").build());
    createNode(CreateNodeParams.create().parent(node.path()).name("my-child").build());
    createNode(CreateNodeParams.create().parent(node.path()).name("my-child2").build());
    final PushNodesResult result = pushNodes(NodeIds.from(node.id()), WS_OTHER);
    assertEquals(1, result.getSuccessful().getSize());
    final FindNodesByQueryResult allNodesInOther = ctxOther().callWith(() -> FindNodesByQueryCommand.create().query(NodeQuery.create().build()).indexServiceInternal(this.indexServiceInternal).searchService(this.searchService).storageService(this.storageService).build().execute());
    assertEquals(2L, allNodesInOther.getTotalHits());
}
Also used : FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Node(com.enonic.xp.node.Node) PushNodesResult(com.enonic.xp.node.PushNodesResult) Test(org.junit.jupiter.api.Test)

Example 62 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.

the class SecurityServiceImpl method duplicateEmailValidation.

private void duplicateEmailValidation(final PrincipalKey key, final String email) {
    if (email == null) {
        return;
    }
    final CompareExpr idProviderExpr = CompareExpr.create(FieldExpr.from(PrincipalIndexPath.ID_PROVIDER_KEY), CompareExpr.Operator.EQ, ValueExpr.string(key.getIdProviderKey().toString()));
    final CompareExpr emailExpr = CompareExpr.create(FieldExpr.from(PrincipalIndexPath.EMAIL_KEY), CompareExpr.Operator.EQ, ValueExpr.string(email));
    final QueryExpr query = QueryExpr.from(LogicalExpr.and(idProviderExpr, emailExpr));
    final Nodes nodes = callWithContext(() -> {
        final FindNodesByQueryResult result = nodeService.findByQuery(NodeQuery.create().query(query).build());
        return this.nodeService.getByIds(result.getNodeIds());
    });
    final User user = nodes.isEmpty() ? null : PrincipalNodeTranslator.userFromNode(nodes.first());
    if (nodes.getSize() > 1 || (user != null && !user.getKey().equals(key))) {
        throw new IllegalArgumentException("A user with email '" + email + "' already exists in id provider '" + key.getIdProviderKey() + "'");
    }
}
Also used : User(com.enonic.xp.security.User) 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 63 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.

the class SecurityServiceImpl method findByEmail.

private User findByEmail(final IdProviderKey idProvider, final String email) {
    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.EMAIL_KEY), CompareExpr.Operator.EQ, ValueExpr.string(email));
    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 email " + email + " 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 64 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.

the class NodeServiceImpl method findByQuery.

@Override
public FindNodesByQueryResult findByQuery(final NodeQuery nodeQuery) {
    final Trace trace = Tracer.newTrace("node.findByQuery");
    if (trace == null) {
        return executeFindByQuery(nodeQuery);
    }
    return Tracer.trace(trace, () -> {
        trace.put("query", nodeQuery.getQuery() != null ? nodeQuery.getQuery().toString() : "");
        trace.put("from", nodeQuery.getFrom());
        trace.put("size", nodeQuery.getSize());
        final FindNodesByQueryResult result = executeFindByQuery(nodeQuery);
        trace.put("hits", result.getTotalHits());
        return result;
    });
}
Also used : Trace(com.enonic.xp.trace.Trace) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult)

Example 65 with FindNodesByQueryResult

use of com.enonic.xp.node.FindNodesByQueryResult in project xp by enonic.

the class FindNodesByQueryCommandTest method query_instant_different_field_name_case.

@Test
public void query_instant_different_field_name_case() throws Exception {
    final Instant BASE_INSTANT = Instant.parse("2000-01-01T00:00:00.00Z");
    final PropertyTree data13 = new PropertyTree();
    data13.addInstant("myProperty", BASE_INSTANT.plus(10, ChronoUnit.DAYS));
    final PropertyTree data2 = new PropertyTree();
    data2.addInstant("myProperty", BASE_INSTANT.plus(20, ChronoUnit.DAYS));
    final Node node1 = createNode(CreateNodeParams.create().name("my-node-1").parent(NodePath.ROOT).data(data13).build());
    final Node node2 = createNode(CreateNodeParams.create().name("my-node-2").parent(NodePath.ROOT).data(data2).build());
    final Node node3 = createNode(CreateNodeParams.create().name("child-node").parent(node1.path()).data(data13).build());
    final Value from = ValueFactory.newDateTime(BASE_INSTANT);
    final Value to = ValueFactory.newDateTime(BASE_INSTANT.plus(15, ChronoUnit.DAYS));
    final QueryExpr queryExpr = QueryExpr.from(CompareExpr.eq(FieldExpr.from("MYProperty"), ValueExpr.instant(BASE_INSTANT.plus(10, ChronoUnit.DAYS).toString())));
    final NodeQuery query = NodeQuery.create().query(queryExpr).addPostFilter(RangeFilter.create().fieldName("MYProperty").from(from).to(to).build()).build();
    final FindNodesByQueryResult result = doFindByQuery(query);
    assertEquals(2, result.getNodeIds().getSize());
    assertTrue(result.getNodeIds().contains(node1.id()));
    assertTrue(result.getNodeIds().contains(node3.id()));
    assertFalse(result.getNodeIds().contains(node2.id()));
}
Also used : QueryExpr(com.enonic.xp.query.expr.QueryExpr) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) Instant(java.time.Instant) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) NodeQuery(com.enonic.xp.node.NodeQuery) Value(com.enonic.xp.data.Value) Test(org.junit.jupiter.api.Test)

Aggregations

FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)84 NodeQuery (com.enonic.xp.node.NodeQuery)61 Test (org.junit.jupiter.api.Test)55 Node (com.enonic.xp.node.Node)32 BucketAggregation (com.enonic.xp.aggregation.BucketAggregation)19 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)19 Bucket (com.enonic.xp.aggregation.Bucket)14 PropertyTree (com.enonic.xp.data.PropertyTree)13 Nodes (com.enonic.xp.node.Nodes)9 DynamicConstraintExpr (com.enonic.xp.query.expr.DynamicConstraintExpr)9 Aggregation (com.enonic.xp.aggregation.Aggregation)8 Buckets (com.enonic.xp.aggregation.Buckets)6 QueryExpr (com.enonic.xp.query.expr.QueryExpr)4 DateRangeBucket (com.enonic.xp.aggregation.DateRangeBucket)3 NodeHit (com.enonic.xp.node.NodeHit)3 CompareExpr (com.enonic.xp.query.expr.CompareExpr)3 NumericRangeBucket (com.enonic.xp.aggregation.NumericRangeBucket)2 SingleValueMetricAggregation (com.enonic.xp.aggregation.SingleValueMetricAggregation)2 ContentId (com.enonic.xp.content.ContentId)2 Context (com.enonic.xp.context.Context)2