use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class FindNodesByMultiRepoQueryCommandTest method multi_repo_search_different_branches_same_repo.
@Test
public void multi_repo_search_different_branches_same_repo() throws Exception {
final Repository repo1 = createRepo(REPO_USER_1, "repo1");
final Repository repo2 = createRepo(REPO_USER_2, "repo2");
// Create new branch in repo1
final Branch otherBranch = callInContext(REPO_USER_1, repo1.getId(), MASTER_BRANCH, () -> createBranch("otherBranch"));
final Node repo1MasterNode1 = callInContext(REPO_USER_1, repo1.getId(), MASTER_BRANCH, () -> createNode(NodePath.ROOT, "repo1Node"));
final Node repo1OtherNode1 = callInContext(REPO_USER_1, repo1.getId(), otherBranch, () -> createNode(NodePath.ROOT, "repo1Node"));
final Node repo2MasterNode1 = callInContext(REPO_USER_2, repo2.getId(), MASTER_BRANCH, () -> createNode(NodePath.ROOT, "repo2Node"));
final SearchTargets targets = SearchTargets.create().add(createTarget(otherBranch, REPO_USER_1, repo1.getId())).add(createTarget(MASTER_BRANCH, REPO_USER_1, repo1.getId())).add(createTarget(MASTER_BRANCH, REPO_USER_2, repo2.getId())).build();
final NodeQuery query = NodeQuery.create().parent(NodePath.ROOT).build();
final FindNodesByMultiRepoQueryResult result = doQuery(query, targets);
assertEquals(3L, result.getTotalHits());
assertRepos(result, repo1.getId(), repo2.getId());
assertBranches(result, MASTER_BRANCH, otherBranch);
assertNodes(result, repo1OtherNode1.id(), repo1MasterNode1.id(), repo2MasterNode1.id());
}
use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class FindNodesByMultiRepoQueryCommandTest method multi_repo_search_different_branches.
@Test
public void multi_repo_search_different_branches() throws Exception {
final Repository repo1 = createRepo(REPO_USER_1, "repo1");
final Repository repo2 = createRepo(REPO_USER_2, "repo2");
// Create new branch in repo1
final Branch otherBranch = callInContext(REPO_USER_1, repo1.getId(), MASTER_BRANCH, () -> createBranch("otherBranch"));
final Node repo1MasterNode1 = callInContext(REPO_USER_1, repo1.getId(), MASTER_BRANCH, () -> createNode(NodePath.ROOT, "repo1Node"));
final Node repo1OtherNode1 = callInContext(REPO_USER_1, repo1.getId(), otherBranch, () -> createNode(NodePath.ROOT, "repo1Node"));
final Node repo2MasterNode1 = callInContext(REPO_USER_2, repo2.getId(), MASTER_BRANCH, () -> createNode(NodePath.ROOT, "repo2Node"));
final SearchTargets targets = SearchTargets.create().add(createTarget(otherBranch, REPO_USER_1, repo1.getId())).add(createTarget(MASTER_BRANCH, REPO_USER_2, repo2.getId())).build();
final NodeQuery query = NodeQuery.create().parent(NodePath.ROOT).build();
final FindNodesByMultiRepoQueryResult result = doQuery(query, targets);
assertEquals(2L, result.getTotalHits());
assertRepos(result, repo1.getId(), repo2.getId());
assertBranches(result, MASTER_BRANCH, otherBranch);
assertNodes(result, repo1OtherNode1.id(), repo2MasterNode1.id());
}
use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class FindNodesByQueryCommandTest_func_range method queryAndAssert.
private void queryAndAssert(final int exptected, final String queryString) {
final NodeQuery query = NodeQuery.create().query(QueryParser.parse(queryString)).build();
final FindNodesByQueryResult result = doFindByQuery(query);
assertEquals(exptected, result.getNodeIds().getSize());
}
use of com.enonic.xp.node.NodeQuery in project xp by enonic.
the class FindNodesByQueryCommandTest_func_stemmed method queryAndAssert.
private void queryAndAssert(final Node node, final String queryString, final int expected) {
final NodeQuery query = NodeQuery.create().query(QueryParser.parse(queryString)).build();
final FindNodesByQueryResult result = doFindByQuery(query);
assertEquals(expected, result.getNodeIds().getSize());
assertTrue(result.getNodeIds().contains(node.id()));
}
use of com.enonic.xp.node.NodeQuery 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();
}
}
Aggregations