@Override public RemoteValue getColumnValue(String column) { return toRemoteValue(row.getValue(column)); }
@Override protected Principal getNext() { if (!propValues.hasNext()) { if (rows.hasNext()) { propValues = rows.next().getValue(REP_EXTERNAL_PRINCIPAL_NAMES).getValue(Type.STRINGS).iterator(); } else { propValues = Collections.emptyIterator(); } } while (propValues.hasNext()) { String principalName = propValues.next(); if (principalName != null && !processed.contains(principalName) && matchesQuery(principalName) ) { processed.add(principalName); return new ExternalGroupPrincipal(principalName); } } return null; }
@Override public Value getValue(String columnName) throws RepositoryException { try { return result.createValue(row.getValue(columnName)); } catch (IllegalArgumentException e) { throw new RepositoryException(e); } }
@Override public Value getValue(String columnName) throws RepositoryException { try { return result.createValue(row.getValue(columnName)); } catch (IllegalArgumentException e) { throw new RepositoryException(e); } }
@Override public Value getValue(String columnName) throws RepositoryException { try { return result.createValue(row.getValue(columnName)); } catch (IllegalArgumentException e) { throw new RepositoryException(e); } }
protected String explainXpath(String query) throws ParseException { String explain = "explain " + query; Result result = executeQuery(explain, "xpath", NO_BINDINGS); ResultRow row = Iterables.getOnlyElement(result.getRows()); String plan = row.getValue("plan").getValue(Type.STRING); return plan; }
private String explainXpath(String query) throws ParseException { String explain = "explain " + query; Result result = executeQuery(explain, "xpath", NO_BINDINGS); ResultRow row = Iterables.getOnlyElement(result.getRows()); return row.getValue("plan").getValue(Type.STRING); }
Set<String> getSuggestions(String nodeType, String suggestFor) throws Exception { Set<String> ret = Sets.newHashSet(); String suggQuery = createSuggestQuery(nodeType, suggestFor); QueryEngine qe = root.getQueryEngine(); Result result = qe.executeQuery(suggQuery, Query.JCR_SQL2, null, null); for (ResultRow row : result.getRows()) { ret.add(row.getValue("suggestion").toString()); } return ret; }
@Nullable private Authorizable getAuthorizable(@Nullable ResultRow row) { Authorizable authorizable = null; if (row != null) { String resultPath = row.getValue(QueryConstants.JCR_PATH).getValue(Type.STRING); try { Tree tree = root.getTree(resultPath); AuthorizableType type = UserUtil.getType(tree); while (tree.exists() && !tree.isRoot() && type == null) { tree = tree.getParent(); type = UserUtil.getType(tree); } if (tree.exists() && (targetType == null || targetType == type)) { authorizable = userManager.getAuthorizable(tree); } } catch (RepositoryException e) { log.debug("Failed to access authorizable " + resultPath); } } return authorizable; } }
@Nullable private Authorizable getAuthorizable(@Nullable ResultRow row) { Authorizable authorizable = null; if (row != null) { String resultPath = row.getValue(QueryConstants.JCR_PATH).getValue(Type.STRING); try { Tree tree = root.getTree(resultPath); AuthorizableType type = UserUtil.getType(tree); while (tree.exists() && !tree.isRoot() && type == null) { tree = tree.getParent(); type = UserUtil.getType(tree); } if (tree.exists() && (targetType == null || targetType == type)) { authorizable = userManager.getAuthorizable(tree); } } catch (RepositoryException e) { log.debug("Failed to access authorizable " + resultPath); } } return authorizable; } }
@CheckForNull private Authorizable getAuthorizable(@CheckForNull ResultRow row) { Authorizable authorizable = null; if (row != null) { String resultPath = row.getValue(QueryConstants.JCR_PATH).getValue(Type.STRING); try { Tree tree = root.getTree(resultPath); AuthorizableType type = UserUtil.getType(tree); while (tree.exists() && !tree.isRoot() && type == null) { tree = tree.getParent(); type = UserUtil.getType(tree); } if (tree.exists() && (targetType == null || targetType == type)) { authorizable = userManager.getAuthorizable(tree); } } catch (RepositoryException e) { log.debug("Failed to access authorizable " + resultPath); } } return authorizable; } }
@Test public void simpleRepExcerpt() throws Exception { createFullTextIndex(root.getTree("/"), "lucene"); root.commit(); Tree content = root.getTree("/").addChild("content"); content.setProperty("foo", "Lorem ipsum, dolor sit", STRING); content.setProperty("bar", "dolor sit, luctus leo, ipsum", STRING); root.commit(); String query = "SELECT [jcr:path],[rep:excerpt] from [nt:base] WHERE CONTAINS(*, 'ipsum')"; Result result = executeQuery(query, SQL2, NO_BINDINGS); Iterator<? extends ResultRow> resultRows = result.getRows().iterator(); assertTrue(resultRows.hasNext()); ResultRow firstRow = result.getRows().iterator().next(); PropertyValue excerptValue = firstRow.getValue("rep:excerpt"); assertTrue("There is an excerpt expected for rep:excerpt",excerptValue != null && !"".equals(excerptValue.getValue(STRING))); excerptValue = firstRow.getValue("rep:excerpt(.)"); assertTrue("There is an excerpt expected for rep:excerpt(.)",excerptValue != null && !"".equals(excerptValue.getValue(STRING))); excerptValue = firstRow.getValue("rep:excerpt(bar)"); assertTrue("There is an excerpt expected for rep:excerpt(bar) ",excerptValue != null && !"".equals(excerptValue.getValue(STRING))); }
private void assertDontTraverseFor(String sql) throws ParseException { QueryImpl query = (QueryImpl)p.parse(sql); query.setExecutionContext(QUERY_ENGINE.getExecutionContext()); Result result = query.executeQuery(); Iterator<? extends ResultRow> it = result.getRows().iterator(); assertFalse("Zero results expected", it.hasNext()); query = (QueryImpl)p.parse("measure " + sql); query.setExecutionContext(QUERY_ENGINE.getExecutionContext()); result = query.executeQuery(); it = result.getRows().iterator(); while(it.hasNext()) { ResultRow row = it.next(); String selector = row.getValue("selector").getValue(Type.STRING); if ("nt:base".equals(selector)) { long scanCount = row.getValue("scanCount").getValue(Type.LONG); // we expect that no was scanned that's it // - no traversal of the whole respository assertEquals("Repository's scan count doesn't match", 0, scanCount); } } } }
@Test public void nonIndexedRequestedPropExcerpt() throws Exception { Tree contentRoot = root.getTree("/").addChild("testRoot"); contentRoot.setProperty("foo", "fox"); contentRoot.setProperty("baz", "is fox ifoxing"); root.commit(); String query = "SELECT [rep:excerpt(baz)] FROM [nt:base] WHERE CONTAINS(*, 'fox')"; Result result = executeQuery(query, SQL2, NO_BINDINGS); Iterator<? extends ResultRow> resultIter = result.getRows().iterator(); assertTrue(resultIter.hasNext()); ResultRow firstRow = resultIter.next(); PropertyValue nodeExcerpt = firstRow.getValue("rep:excerpt(baz)"); assertNull("rep:excerpt(baz) if requested explicitly must be indexed to be evaluated", nodeExcerpt); }
@Test public void binaryExcerpt() throws Exception { Tree contentRoot = root.getTree("/").addChild("testRoot"); String binaryText = "is fox foxing as a fox cub"; Blob blob = new ArrayBasedBlob(binaryText.getBytes()); TestUtil.createFileNode(contentRoot, "binaryNode", blob, "text/plain"); root.commit(); String query = "SELECT [rep:excerpt] FROM [nt:base] WHERE CONTAINS(*, 'fox')"; Result result = executeQuery(query, SQL2, NO_BINDINGS); Iterator<? extends ResultRow> resultIter = result.getRows().iterator(); assertTrue(resultIter.hasNext()); ResultRow firstRow = resultIter.next(); PropertyValue nodeExcerpt; String excerpt; nodeExcerpt = firstRow.getValue("rep:excerpt"); assertNotNull("rep:excerpt not evaluated", nodeExcerpt); excerpt = nodeExcerpt.getValue(STRING); String expected = binaryText.replaceAll(" fox ", " <strong>fox</strong> "); assertTrue("rep:excerpt didn't evaluate correctly - got '" + excerpt + "'", excerpt.contains(expected)); } }
@Test public void propExcerpt() throws Exception { Tree contentRoot = root.getTree("/").addChild("testRoot"); contentRoot.setProperty("foo", "is fox ifoxing"); root.commit(); String query = "SELECT [rep:excerpt(foo)] FROM [nt:base] WHERE CONTAINS(*, 'fox')"; Result result = executeQuery(query, SQL2, NO_BINDINGS); Iterator<? extends ResultRow> resultIter = result.getRows().iterator(); assertTrue(resultIter.hasNext()); ResultRow firstRow = resultIter.next(); PropertyValue nodeExcerpt; String excerpt; nodeExcerpt = firstRow.getValue("rep:excerpt(foo)"); assertNotNull("rep:excerpt(foo) not evaluated", nodeExcerpt); excerpt = nodeExcerpt.getValue(STRING); assertTrue("rep:excerpt(foo) didn't evaluate correctly - got '" + excerpt + "'", "is <strong>fox</strong> ifoxing".equals(excerpt)); }
@Test public void indexedNonRequestedPropExcerpt() throws Exception { Tree contentRoot = root.getTree("/").addChild("testRoot"); contentRoot.setProperty("foo", "is fox ifoxing"); root.commit(); String query = "SELECT [rep:excerpt] FROM [nt:base] WHERE CONTAINS(*, 'fox')"; Result result = executeQuery(query, SQL2, NO_BINDINGS); Iterator<? extends ResultRow> resultIter = result.getRows().iterator(); assertTrue(resultIter.hasNext()); ResultRow firstRow = resultIter.next(); PropertyValue nodeExcerpt; String excerpt; nodeExcerpt = firstRow.getValue("rep:excerpt(foo)"); assertNotNull("rep:excerpt(foo) not evaluated", nodeExcerpt); excerpt = nodeExcerpt.getValue(STRING); assertTrue("rep:excerpt(foo) didn't evaluate correctly - got '" + excerpt + "'", excerpt.contains("<strong>fox</strong>")); assertTrue("rep:excerpt(foo) highlighting inside words - got '" + excerpt + "'", !excerpt.contains("i<strong>fox</strong>ing")); }
@Test public void nodeExcerpt() throws Exception { Tree contentRoot = root.getTree("/").addChild("testRoot"); contentRoot.setProperty("foo", "is fox ifoxing"); contentRoot.setProperty("bar", "ifoxing fox"); root.commit(); String query = "SELECT [rep:excerpt],[rep:excerpt(.)] FROM [nt:base] WHERE CONTAINS(*, 'fox')"; Result result = executeQuery(query, SQL2, NO_BINDINGS); Iterator<? extends ResultRow> resultIter = result.getRows().iterator(); assertTrue(resultIter.hasNext()); ResultRow firstRow = resultIter.next(); PropertyValue nodeExcerpt; String excerpt1, excerpt2; nodeExcerpt = firstRow.getValue("rep:excerpt"); assertNotNull("rep:excerpt not evaluated", nodeExcerpt); excerpt1 = nodeExcerpt.getValue(STRING); assertTrue("rep:excerpt didn't evaluate correctly - got '" + excerpt1 + "'", "is <strong>fox</strong> ifoxing".equals(excerpt1) || "ifoxing <strong>fox</strong>".equals(excerpt1)); nodeExcerpt = firstRow.getValue("rep:excerpt(.)"); assertNotNull("rep:excerpt(.) not evaluated", nodeExcerpt); excerpt2 = nodeExcerpt.getValue(STRING); assertEquals("excerpt extracted via rep:excerpt not same as rep:excerpt(.)", excerpt1, excerpt2); }
@Test public void relativePropExcerpt() throws Exception { Tree contentRoot = root.getTree("/").addChild("testRoot"); contentRoot.addChild("relative").setProperty("baz", "is fox ifoxing"); root.commit(); String query = "SELECT [rep:excerpt(relative/baz)] FROM [nt:base] WHERE CONTAINS([relative/baz], 'fox')"; Result result = executeQuery(query, SQL2, NO_BINDINGS); Iterator<? extends ResultRow> resultIter = result.getRows().iterator(); assertTrue(resultIter.hasNext()); ResultRow firstRow = resultIter.next(); PropertyValue nodeExcerpt; String excerpt; nodeExcerpt = firstRow.getValue("rep:excerpt(relative/baz)"); assertNotNull("rep:excerpt(relative/baz) not evaluated", nodeExcerpt); excerpt = nodeExcerpt.getValue(STRING); assertTrue("rep:excerpt(relative/baz) didn't evaluate correctly - got '" + excerpt + "'", "is <strong>fox</strong> ifoxing".equals(excerpt)); }
@Test public void nonIndexedNonRequestedPropExcerpt() throws Exception { Tree contentRoot = root.getTree("/").addChild("testRoot"); contentRoot.setProperty("foo", "fox"); contentRoot.setProperty("baz", "is fox ifoxing"); root.commit(); String query = "SELECT [rep:excerpt] FROM [nt:base] WHERE CONTAINS(*, 'fox')"; Result result = executeQuery(query, SQL2, NO_BINDINGS); Iterator<? extends ResultRow> resultIter = result.getRows().iterator(); assertTrue(resultIter.hasNext()); ResultRow firstRow = resultIter.next(); PropertyValue nodeExcerpt; String excerpt; nodeExcerpt = firstRow.getValue("rep:excerpt(baz)"); assertNotNull("rep:excerpt(baz) not evaluated", nodeExcerpt); excerpt = nodeExcerpt.getValue(STRING); assertTrue("rep:excerpt(foo) didn't evaluate correctly - got '" + excerpt + "'", excerpt.contains("<strong>fox</strong>")); assertTrue("rep:excerpt(baz) highlighting inside words - got '" + excerpt + "'", !excerpt.contains("i<strong>fox</strong>ing")); }