Search in sources :

Example 36 with XWikiRestException

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

the class ObjectsAtPageVersionResourceImpl method getObjects.

@Override
public Objects getObjects(String wikiName, String spaceName, String pageName, String version, Integer start, Integer number, Boolean withPrettyNames) throws XWikiRestException {
    try {
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, version, true, false);
        Document doc = documentInfo.getDocument();
        Objects objects = objectFactory.createObjects();
        List<com.xpn.xwiki.objects.BaseObject> objectList = getBaseObjects(doc);
        RangeIterable<com.xpn.xwiki.objects.BaseObject> ri = new RangeIterable<com.xpn.xwiki.objects.BaseObject>(objectList, start, number);
        for (com.xpn.xwiki.objects.BaseObject object : ri) {
            /* By deleting objects, some of them might become null, so we must check for this */
            if (object != null) {
                objects.getObjectSummaries().add(DomainObjectFactory.createObjectSummary(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, object, true, Utils.getXWikiApi(componentManager), withPrettyNames));
            }
        }
        return objects;
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : RangeIterable(org.xwiki.rest.internal.RangeIterable) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) Objects(org.xwiki.rest.model.jaxb.Objects) XWikiException(com.xpn.xwiki.XWikiException)

Example 37 with XWikiRestException

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

the class ObjectsResourceImpl method getObjects.

@Override
public Objects getObjects(String wikiName, String spaceName, String pageName, Integer start, Integer number, Boolean withPrettyNames) throws XWikiRestException {
    try {
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
        Document doc = documentInfo.getDocument();
        Objects objects = objectFactory.createObjects();
        List<BaseObject> objectList = getBaseObjects(doc);
        RangeIterable<BaseObject> ri = new RangeIterable<BaseObject>(objectList, start, number);
        for (BaseObject object : ri) {
            /* By deleting objects, some of them might become null, so we must check for this */
            if (object != null) {
                objects.getObjectSummaries().add(DomainObjectFactory.createObjectSummary(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, object, false, Utils.getXWikiApi(componentManager), withPrettyNames));
            }
        }
        return objects;
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : RangeIterable(org.xwiki.rest.internal.RangeIterable) XWikiRestException(org.xwiki.rest.XWikiRestException) Objects(org.xwiki.rest.model.jaxb.Objects) Document(com.xpn.xwiki.api.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiException(com.xpn.xwiki.XWikiException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 38 with XWikiRestException

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

the class PageChildrenResourceImpl method getPageChildren.

@Override
public Pages getPageChildren(String wikiName, String spaceName, String pageName, Integer start, Integer number, Boolean withPrettyNames) throws XWikiRestException {
    try {
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
        Document doc = documentInfo.getDocument();
        Pages pages = objectFactory.createPages();
        /* Use an explicit query to improve performance */
        String queryString = "select distinct doc.fullName from XWikiDocument as doc where doc.parent = :parent order by doc.fullName asc";
        List<String> childPageFullNames = queryManager.createQuery(queryString, Query.XWQL).bindValue("parent", doc.getFullName()).setOffset(start).setLimit(number).execute();
        for (String childPageFullName : childPageFullNames) {
            String pageId = Utils.getPageId(wikiName, childPageFullName);
            if (!Utils.getXWikiApi(componentManager).exists(pageId)) {
                getLogger().warn("Page [{}] appears to be in space [{}] but no information is available.", pageName, spaceName);
            } else {
                Document childDoc = Utils.getXWikiApi(componentManager).getDocument(pageId);
                /* We only add pages we have the right to access */
                if (childDoc != null) {
                    pages.getPageSummaries().add(DomainObjectFactory.createPageSummary(objectFactory, uriInfo.getBaseUri(), childDoc, Utils.getXWikiApi(componentManager), withPrettyNames));
                }
            }
        }
        return pages;
    } catch (Exception e) {
        throw new XWikiRestException(e);
    }
}
Also used : Pages(org.xwiki.rest.model.jaxb.Pages) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiRestException(org.xwiki.rest.XWikiRestException)

Example 39 with XWikiRestException

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

the class PageHistoryResourceImpl method getPageHistory.

@Override
public History getPageHistory(String wikiName, String spaceName, String pageName, 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 {
        // Note that the query is made to work with Oracle which treats empty strings as null.
        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 = '' or doc.language is null)" + " 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).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, null, 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 40 with XWikiRestException

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

the class PageResourceImpl method deletePage.

@Override
public void deletePage(String wikiName, String spaceName, String pageName) throws XWikiRestException {
    try {
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, true);
        deletePage(documentInfo);
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) 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