use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class NodesHasPermissionResolver method execute.
public boolean execute() {
final Context context = ContextAccessor.current();
if (context.getAuthInfo().hasRole(RoleKeys.ADMIN)) {
return true;
}
if (nodeIds.isEmpty()) {
return false;
}
final NodeQuery query = NodeQuery.create().addQueryFilter(IdFilter.create().fieldName(NodeIndexPath.ID.getPath()).values(nodeIds).build()).addQueryFilter(ValueFilter.create().fieldName(getPermissionFieldName().getPath()).addValues(context.getAuthInfo().getPrincipals().stream().map(PrincipalKey::toString).collect(Collectors.toList())).build()).searchMode(SearchMode.COUNT).build();
final FindNodesByQueryResult result = FindNodesByQueryCommand.create(this).query(query).build().execute();
return result.getTotalHits() == nodeIds.getSize();
}
use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class CreateIssueCommand method countTotalIssues.
private long countTotalIssues() {
final IssueQuery query = IssueQuery.create().size(0).count(true).build();
final NodeQuery nodeQuery = IssueQueryNodeQueryTranslator.translate(query);
final FindNodesByQueryResult result = nodeService.findByQuery(nodeQuery);
return result.getTotalHits();
}
use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class FindeNodesByQueryCommandTest_like method queryAndExpect.
private void queryAndExpect(final String queryString, final int expected) {
final NodeQuery query = NodeQuery.create().query(QueryParser.parse(queryString)).build();
final FindNodesByQueryResult result = doFindByQuery(query);
assertEquals(expected, result.getHits());
}
use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class NodeOrderTest method score_sorting.
@Test
public void score_sorting() throws Exception {
final Node node1 = createNode("node1", ValueFactory.newString("denne har en fisk"));
final Node node2 = createNode("node2", ValueFactory.newString("denne har fisk og ost"));
final Node node3 = createNode("node3", ValueFactory.newString("mens denne har både fisk, ost og pølse"));
final Node node4 = createNode("node4", ValueFactory.newString("denne vinner, siden den har alle sammen: fisk, ost, pølse og pai"));
final FunctionExpr fulltextExpression = FunctionExpr.from("fulltext", ValueExpr.string("my-value"), ValueExpr.string("pai fisk pølse ost"), ValueExpr.string("OR"));
final NodeQuery fulltextQuery = NodeQuery.create().query(QueryExpr.from(new DynamicConstraintExpr(fulltextExpression), FieldOrderExpr.create(IndexPath.from("_score"), OrderExpr.Direction.DESC))).build();
printContentRepoIndex();
final SearchResult result = searchService.query(fulltextQuery, SingleRepoSearchSource.from(ContextAccessor.current()));
assertEquals(4, result.getNumberOfHits());
final Iterator<String> iterator = result.getIds().iterator();
assertEquals(node4.id(), NodeId.from(iterator.next()));
assertEquals(node3.id(), NodeId.from(iterator.next()));
assertEquals(node2.id(), NodeId.from(iterator.next()));
assertEquals(node1.id(), NodeId.from(iterator.next()));
}
use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class FindNodesByQueryCommandTest_references method incomingReferences.
@Test
public void incomingReferences() throws Exception {
final Node node1 = createNode(CreateNodeParams.create().name("node1").setNodeId(NodeId.from("node1")).parent(NodePath.ROOT).build());
createNodeWithReference("node2", node1.id());
createNodeWithReference("node3", node1.id());
createNodeWithReference("node4", node1.id());
final NodeQuery query = NodeQuery.create().query(QueryParser.parse("_references = 'node1'")).build();
final FindNodesByQueryResult result = doFindByQuery(query);
assertEquals(3, result.getHits());
assertTrue(result.getNodeIds().contains(NodeId.from("node2")));
assertTrue(result.getNodeIds().contains(NodeId.from("node3")));
assertTrue(result.getNodeIds().contains(NodeId.from("node4")));
}
Aggregations