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