Search in sources :

Example 1 with ScriptQuery

use of org.xwiki.query.internal.ScriptQuery in project xwiki-platform by xwiki.

the class QueryManagerScriptService method createQuery.

private Query createQuery(String statement, String language, boolean checkCurrentUser) throws QueryException {
    Query query = this.secureQueryManager.createQuery(statement, language);
    if (query instanceof SecureQuery) {
        ((SecureQuery) query).checkCurrentAuthor(true);
        ((SecureQuery) query).checkCurrentUser(checkCurrentUser);
    }
    return new ScriptQuery(query, this.componentManager);
}
Also used : Query(org.xwiki.query.Query) SecureQuery(org.xwiki.query.SecureQuery) ScriptQuery(org.xwiki.query.internal.ScriptQuery) ScriptQuery(org.xwiki.query.internal.ScriptQuery) SecureQuery(org.xwiki.query.SecureQuery)

Example 2 with ScriptQuery

use of org.xwiki.query.internal.ScriptQuery in project xwiki-platform by xwiki.

the class HelpTest method verifySubHeadingVelocityVariableCorrectlyEvaluatedWhenUsedInSection.

/**
 * The bug we're trying to prevent happening again was that there was that "$subHeading" was rendered when going to
 * the Links section (for example).
 * Note: It was working fine when displaying all sections though.
 * @see <a href="https://jira.xwiki.org/browse/XWIKI-13650">XWIKI-13650</a>
 */
@Test
public void verifySubHeadingVelocityVariableCorrectlyEvaluatedWhenUsedInSection() throws Exception {
    // URL that we're simulating:
    // http://localhost:8080/xwiki/bin/view/XWiki/XWikiSyntax?syntax=2.1&section=Links&xpage=print
    setOutputSyntax(Syntax.XHTML_1_0);
    request.put("section", "Links");
    request.put("xpage", "print");
    // Register the XWikiSyntaxLinks page with an XWikiSyntaxClass xobject in it so that it can be found later on
    // by XWiki.XWikiSyntax
    loadPage(new DocumentReference("xwiki", "XWiki", "XWikiSyntaxLinks"));
    // Register query script service since it's not registered by default and it's used in XWiki.XWikiSyntax to
    // find all syntax pages.
    QueryManagerScriptService qss = mock(QueryManagerScriptService.class);
    mocker.registerComponent(ScriptService.class, "query", qss);
    ScriptQuery sq = mock(ScriptQuery.class);
    when(qss.xwql(contains("from doc.object(XWiki.XWikiSyntaxClass)"))).thenReturn(sq);
    when(sq.addFilter((String) any())).thenReturn(sq);
    when(sq.execute()).thenReturn(Arrays.asList("XWiki.XWikiSyntaxLinks"));
    String result = renderPage(new DocumentReference("xwiki", "XWiki", "XWikiSyntax"));
    assertTrue("$subHeading should have been evaluated and replaced by '==='", result.contains("<h3 id=\"HXWikiSyntax2.1LinkSpecification\""));
    assertTrue("$subHeading should have been evaluated and replaced by '==='", !result.contains("$subHeading"));
}
Also used : QueryManagerScriptService(org.xwiki.query.script.QueryManagerScriptService) ScriptQuery(org.xwiki.query.internal.ScriptQuery) DocumentReference(org.xwiki.model.reference.DocumentReference) PageTest(org.xwiki.test.page.PageTest) Test(org.junit.Test)

Example 3 with ScriptQuery

use of org.xwiki.query.internal.ScriptQuery in project xwiki-platform by xwiki.

the class LiveTableResultsTest method plainPageResults.

@Test
public void plainPageResults() throws Exception {
    setColumns("doc.name", "doc.date");
    setSort("doc.date", false);
    setQueryFilters("currentlanguage", "hidden");
    // Offset starting from 1.
    setOffset(13);
    setLimit(7);
    ScriptQuery query = mock(ScriptQuery.class);
    when(queryService.hql("  where 1=1    order by doc.date desc")).thenReturn(query);
    when(query.addFilter("currentlanguage")).thenReturn(query);
    when(query.addFilter("hidden")).thenReturn(query);
    when(query.setLimit(7)).thenReturn(query);
    // Offset starting from 0.
    when(query.setOffset(12)).thenReturn(query);
    when(query.bindValues(anyListOf(Object.class))).thenReturn(query);
    when(query.count()).thenReturn(17L);
    when(query.execute()).thenReturn(Arrays.<Object>asList("A.B", "X.Y"));
    DocumentReference abReference = new DocumentReference("wiki", "A", "B");
    when(modelService.resolveDocument("A.B")).thenReturn(abReference);
    when(modelService.serialize(abReference.getParent(), "local")).thenReturn("A");
    DocumentReference xyReference = new DocumentReference("wiki", "X", "Y");
    when(modelService.resolveDocument("X.Y")).thenReturn(xyReference);
    when(modelService.serialize(xyReference.getParent(), "local")).thenReturn("X");
    renderPage();
    assertEquals(17L, getTotalRowCount());
    assertEquals(2, getRowCount());
    assertEquals(13, getOffset());
    List<Map<String, String>> rows = getRows();
    assertEquals(2, rows.size());
    Map<String, String> ab = rows.get(0);
    assertEquals("A", ab.get("doc_space"));
    assertEquals("B", ab.get("doc_name"));
    Map<String, String> xy = rows.get(1);
    assertEquals("X", xy.get("doc_space"));
    assertEquals("Y", xy.get("doc_name"));
}
Also used : ScriptQuery(org.xwiki.query.internal.ScriptQuery) Map(java.util.Map) DocumentReference(org.xwiki.model.reference.DocumentReference) PageTest(org.xwiki.test.page.PageTest) Test(org.junit.Test)

Aggregations

ScriptQuery (org.xwiki.query.internal.ScriptQuery)3 Test (org.junit.Test)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 PageTest (org.xwiki.test.page.PageTest)2 Map (java.util.Map)1 Query (org.xwiki.query.Query)1 SecureQuery (org.xwiki.query.SecureQuery)1 QueryManagerScriptService (org.xwiki.query.script.QueryManagerScriptService)1