Search in sources :

Example 66 with XWikiRestException

use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.

the class PageTranslationVersionResourceImpl method getPageTranslationVersion.

@Override
public Page getPageTranslationVersion(String wikiName, String spaceName, String pageName, String language, String version, Boolean withPrettyNames) throws XWikiRestException {
    try {
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, language, version, true, false);
        Document doc = documentInfo.getDocument();
        return DomainObjectFactory.createPage(objectFactory, uriInfo.getBaseUri(), uriInfo.getAbsolutePath(), doc, false, Utils.getXWikiApi(componentManager), withPrettyNames);
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiException(com.xpn.xwiki.XWikiException)

Example 67 with XWikiRestException

use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.

the class PageVersionResourceImpl method getPageVersion.

@Override
public Page getPageVersion(String wikiName, String spaceName, String pageName, String version, Boolean withPrettyNames) throws XWikiRestException {
    try {
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, version, true, false);
        Document doc = documentInfo.getDocument();
        return DomainObjectFactory.createPage(objectFactory, uriInfo.getBaseUri(), uriInfo.getAbsolutePath(), doc, true, Utils.getXWikiApi(componentManager), withPrettyNames);
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiException(com.xpn.xwiki.XWikiException)

Example 68 with XWikiRestException

use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.

the class PagesResourceImpl method getPages.

@Override
public Pages getPages(String wikiName, String spaceName, Integer start, Integer number, String parentFilterExpression, String order, Boolean withPrettyNames) throws XWikiRestException {
    String database = Utils.getXWikiContext(componentManager).getWikiId();
    List<String> spaces = parseSpaceSegments(spaceName);
    String spaceId = Utils.getLocalSpaceId(spaces);
    Pages pages = objectFactory.createPages();
    try {
        Utils.getXWikiContext(componentManager).setWikiId(wikiName);
        Query query = ("date".equals(order)) ? queryManager.createQuery("select doc.name from Document doc where doc.space=:space and language='' order by doc.date desc", "xwql") : queryManager.getNamedQuery("getSpaceDocsName");
        /* Use an explicit query to improve performance */
        List<String> pageNames = query.addFilter(componentManager.<QueryFilter>getInstance(QueryFilter.class, "hidden")).bindValue("space", spaceId).setOffset(start).setLimit(number).execute();
        Pattern parentFilter = null;
        if (parentFilterExpression != null) {
            if (parentFilterExpression.equals("null")) {
                parentFilter = Pattern.compile("");
            } else {
                parentFilter = Pattern.compile(parentFilterExpression);
            }
        }
        for (String pageName : pageNames) {
            String pageFullName = Utils.getPageId(wikiName, spaces, pageName);
            if (!Utils.getXWikiApi(componentManager).exists(pageFullName)) {
                getLogger().warn("Page [{}] appears to be in space [{}] but no information is available.", pageName, spaceId);
            } else {
                Document doc = Utils.getXWikiApi(componentManager).getDocument(pageFullName);
                /* We only add pages we have the right to access */
                if (doc != null) {
                    boolean add = true;
                    Document parent = Utils.getParentDocument(doc, Utils.getXWikiApi(componentManager));
                    if (parentFilter != null) {
                        String parentId = "";
                        if (parent != null && !parent.isNew()) {
                            parentId = parent.getPrefixedFullName();
                        }
                        add = parentFilter.matcher(parentId).matches();
                    }
                    if (add) {
                        pages.getPageSummaries().add(DomainObjectFactory.createPageSummary(objectFactory, uriInfo.getBaseUri(), doc, Utils.getXWikiApi(componentManager), withPrettyNames));
                    }
                }
            }
        }
    } catch (Exception e) {
        throw new XWikiRestException(e);
    } finally {
        Utils.getXWikiContext(componentManager).setWikiId(database);
    }
    return pages;
}
Also used : Pages(org.xwiki.rest.model.jaxb.Pages) Pattern(java.util.regex.Pattern) QueryFilter(org.xwiki.query.QueryFilter) Query(org.xwiki.query.Query) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiRestException(org.xwiki.rest.XWikiRestException)

Example 69 with XWikiRestException

use of org.xwiki.rest.XWikiRestException 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 70 with XWikiRestException

use of org.xwiki.rest.XWikiRestException in project xwiki-platform by xwiki.

the class AttachmentAtPageVersionResourceImpl method getAttachment.

@Override
public Response getAttachment(String wikiName, String spaceName, String pageName, String version, String attachmentName) throws XWikiRestException {
    try {
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, version, true, false);
        Document doc = documentInfo.getDocument();
        final com.xpn.xwiki.api.Attachment xwikiAttachment = doc.getAttachment(attachmentName);
        if (xwikiAttachment == null) {
            throw new WebApplicationException(Status.NOT_FOUND);
        }
        return Response.ok().type(xwikiAttachment.getMimeType()).entity(xwikiAttachment.getContent()).build();
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

XWikiRestException (org.xwiki.rest.XWikiRestException)71 XWikiException (com.xpn.xwiki.XWikiException)46 Document (com.xpn.xwiki.api.Document)40 WebApplicationException (javax.ws.rs.WebApplicationException)26 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)15 Link (org.xwiki.rest.model.jaxb.Link)12 QueryException (org.xwiki.query.QueryException)8 BaseObject (com.xpn.xwiki.objects.BaseObject)7 RangeIterable (org.xwiki.rest.internal.RangeIterable)7 XWikiContext (com.xpn.xwiki.XWikiContext)6 Object (org.xwiki.rest.model.jaxb.Object)5 Property (org.xwiki.rest.model.jaxb.Property)5 Date (java.util.Date)4 Test (org.junit.Test)4 ClassPropertyReference (org.xwiki.model.reference.ClassPropertyReference)4 Objects (org.xwiki.rest.model.jaxb.Objects)4 XWikiRCSNodeId (com.xpn.xwiki.doc.rcs.XWikiRCSNodeId)3 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)3 URI (java.net.URI)3 URL (java.net.URL)3