Search in sources :

Example 46 with QueryException

use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.

the class PageTranslationHistoryResourceImpl method getPageTranslationHistory.

@Override
public History getPageTranslationHistory(String wikiName, String spaceName, String pageName, String language, Integer start, Integer number, String order, Boolean withPrettyNames) throws XWikiRestException {
    List<String> spaces = parseSpaceSegments(spaceName);
    String spaceId = Utils.getLocalSpaceId(spaces);
    History history = new History();
    try {
        String query = String.format("select doc.space, doc.name, rcs.id, rcs.date, rcs.author, rcs.comment" + " from XWikiRCSNodeInfo as rcs, XWikiDocument as doc where rcs.id.docId = doc.id and" + " doc.space = :space and doc.name = :name and doc.language = :language" + " order by rcs.date %s, rcs.id.version1 %s, rcs.id.version2 %s", order, order, order);
        List<Object> queryResult = null;
        queryResult = queryManager.createQuery(query, Query.XWQL).bindValue("space", spaceId).bindValue("name", pageName).setLimit(number).bindValue("language", language).setOffset(start).setWiki(wikiName).execute();
        for (Object object : queryResult) {
            Object[] fields = (Object[]) object;
            XWikiRCSNodeId nodeId = (XWikiRCSNodeId) fields[2];
            Timestamp timestamp = (Timestamp) fields[3];
            Date modified = new Date(timestamp.getTime());
            String modifier = (String) fields[4];
            String comment = (String) fields[5];
            HistorySummary historySummary = DomainObjectFactory.createHistorySummary(objectFactory, uriInfo.getBaseUri(), wikiName, spaces, pageName, language, nodeId.getVersion(), modifier, modified, comment, Utils.getXWikiApi(componentManager), withPrettyNames);
            history.getHistorySummaries().add(historySummary);
        }
    } catch (QueryException e) {
        throw new XWikiRestException(e);
    }
    return history;
}
Also used : QueryException(org.xwiki.query.QueryException) XWikiRestException(org.xwiki.rest.XWikiRestException) HistorySummary(org.xwiki.rest.model.jaxb.HistorySummary) XWikiRCSNodeId(com.xpn.xwiki.doc.rcs.XWikiRCSNodeId) History(org.xwiki.rest.model.jaxb.History) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Example 47 with QueryException

use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.

the class TagsResourceImpl method getTags.

@Override
public Tags getTags(String wikiName) throws XWikiRestException {
    String database = Utils.getXWikiContext(componentManager).getWikiId();
    try {
        Tags tags = objectFactory.createTags();
        Utils.getXWikiContext(componentManager).setWikiId(wikiName);
        List<String> tagNames = getAllTags();
        for (String tagName : tagNames) {
            Tag tag = objectFactory.createTag();
            tag.setName(tagName);
            String tagUri = Utils.createURI(uriInfo.getBaseUri(), PagesForTagsResource.class, wikiName, tagName).toString();
            Link tagLink = objectFactory.createLink();
            tagLink.setHref(tagUri);
            tagLink.setRel(Relations.TAG);
            tag.getLinks().add(tagLink);
            tags.getTags().add(tag);
        }
        return tags;
    } catch (QueryException e) {
        throw new XWikiRestException(e);
    } finally {
        Utils.getXWikiContext(componentManager).setWikiId(database);
    }
}
Also used : QueryException(org.xwiki.query.QueryException) XWikiRestException(org.xwiki.rest.XWikiRestException) PagesForTagsResource(org.xwiki.rest.resources.tags.PagesForTagsResource) Tag(org.xwiki.rest.model.jaxb.Tag) Tags(org.xwiki.rest.model.jaxb.Tags) Link(org.xwiki.rest.model.jaxb.Link)

Example 48 with QueryException

use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.

the class ModificationsResourceImpl method getModifications.

@Override
public History getModifications(String wikiName, Integer start, Integer number, String order, Long ts, Boolean withPrettyNames) throws XWikiRestException {
    try {
        History history = new History();
        String query = String.format("select doc.space, doc.name, doc.language, rcs.id, rcs.date, rcs.author," + " rcs.comment from XWikiRCSNodeInfo as rcs, XWikiDocument as doc where rcs.id.docId = doc.id and" + " rcs.date > :date order by rcs.date %s, rcs.id.version1 %s, rcs.id.version2 %s", order, order, order);
        List<Object> queryResult = null;
        queryResult = queryManager.createQuery(query, Query.XWQL).bindValue("date", new Date(ts)).setLimit(number).setOffset(start).setWiki(wikiName).execute();
        for (Object object : queryResult) {
            Object[] fields = (Object[]) object;
            String spaceId = (String) fields[0];
            List<String> spaces = Utils.getSpacesFromSpaceId(spaceId);
            String pageName = (String) fields[1];
            String language = (String) fields[2];
            if (language.equals("")) {
                language = null;
            }
            XWikiRCSNodeId nodeId = (XWikiRCSNodeId) fields[3];
            Timestamp timestamp = (Timestamp) fields[4];
            Date modified = new Date(timestamp.getTime());
            String modifier = (String) fields[5];
            String comment = (String) fields[6];
            HistorySummary historySummary = DomainObjectFactory.createHistorySummary(objectFactory, uriInfo.getBaseUri(), wikiName, spaces, pageName, language, nodeId.getVersion(), modifier, modified, comment, Utils.getXWikiApi(componentManager), withPrettyNames);
            history.getHistorySummaries().add(historySummary);
        }
        return history;
    } catch (QueryException e) {
        throw new XWikiRestException(e);
    }
}
Also used : QueryException(org.xwiki.query.QueryException) XWikiRestException(org.xwiki.rest.XWikiRestException) HistorySummary(org.xwiki.rest.model.jaxb.HistorySummary) XWikiRCSNodeId(com.xpn.xwiki.doc.rcs.XWikiRCSNodeId) History(org.xwiki.rest.model.jaxb.History) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Example 49 with QueryException

use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.

the class XWiki method refreshLinks.

public void refreshLinks(XWikiContext context) throws XWikiException {
    try {
        // refreshes all Links of each doc of the wiki
        @SuppressWarnings("deprecation") List<String> docs = getStore().getQueryManager().getNamedQuery("getAllDocuments").addFilter(Utils.<QueryFilter>getComponent(QueryFilter.class, "hidden")).execute();
        for (int i = 0; i < docs.size(); i++) {
            XWikiDocument myDoc = this.getDocument(docs.get(i), context);
            myDoc.getStore().saveLinks(myDoc, context, true);
        }
    } catch (QueryException ex) {
        throw new XWikiException(0, 0, ex.getMessage(), ex);
    }
}
Also used : QueryFilter(org.xwiki.query.QueryFilter) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) QueryException(org.xwiki.query.QueryException) ParseGroovyFromString(com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString) IncludeServletAsString(com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString)

Example 50 with QueryException

use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.

the class SecureQueryExecutorManagerTest method executeNotSecureQueryWithoutProgrammingRight.

// Tests
@Test
public void executeNotSecureQueryWithoutProgrammingRight() {
    this.hasProgrammingRight = false;
    // Create a Query not implementing SecureQuery
    Query query = mock(Query.class);
    try {
        this.executor.execute(query);
        fail("Should have thrown an exception here");
    } catch (QueryException expected) {
        assertEquals("Unsecure query require programming right. Query statement = [null]", expected.getMessage());
    }
}
Also used : QueryException(org.xwiki.query.QueryException) Query(org.xwiki.query.Query) Test(org.junit.Test)

Aggregations

QueryException (org.xwiki.query.QueryException)57 Query (org.xwiki.query.Query)32 DocumentReference (org.xwiki.model.reference.DocumentReference)19 XWikiException (com.xpn.xwiki.XWikiException)18 ArrayList (java.util.ArrayList)14 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)11 BaseObject (com.xpn.xwiki.objects.BaseObject)8 Test (org.junit.Test)8 QueryFilter (org.xwiki.query.QueryFilter)7 XWikiContext (com.xpn.xwiki.XWikiContext)6 HashMap (java.util.HashMap)6 XWikiRestException (org.xwiki.rest.XWikiRestException)6 Event (org.xwiki.eventstream.Event)5 WikiReference (org.xwiki.model.reference.WikiReference)5 Date (java.util.Date)4 List (java.util.List)4 IconException (org.xwiki.icon.IconException)4 QueryManager (org.xwiki.query.QueryManager)4 SecureQuery (org.xwiki.query.SecureQuery)4 XWiki (com.xpn.xwiki.XWiki)3