Search in sources :

Example 41 with XWikiRestException

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

the class PageResourceImpl method getPage.

@Override
public Page getPage(String wikiName, String spaceName, String pageName, Boolean withPrettyNames, Boolean withObjects, Boolean withXClass, Boolean withAttachments) throws XWikiRestException {
    try {
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
        Document doc = documentInfo.getDocument();
        URI baseUri = uriInfo.getBaseUri();
        Page page = this.factory.toRestPage(baseUri, uriInfo.getAbsolutePath(), doc, false, withPrettyNames, withObjects, withXClass, withAttachments);
        return page;
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) Page(org.xwiki.rest.model.jaxb.Page) Document(com.xpn.xwiki.api.Document) URI(java.net.URI) XWikiException(com.xpn.xwiki.XWikiException)

Example 42 with XWikiRestException

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

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

the class AttachmentHistoryResourceImpl method getAttachmentHistory.

@Override
public Attachments getAttachmentHistory(String wikiName, String spaceName, String pageName, String attachmentName, Integer start, Integer number) throws XWikiRestException {
    try {
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, 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);
        }
        Attachments attachments = new Attachments();
        Version[] versions = xwikiAttachment.getVersions();
        List<Version> versionList = new ArrayList<Version>();
        for (Version version : versions) {
            versionList.add(version);
        }
        RangeIterable<Version> ri = new RangeIterable<Version>(versionList, start, number);
        for (Version version : ri) {
            com.xpn.xwiki.api.Attachment xwikiAttachmentAtVersion = xwikiAttachment.getAttachmentRevision(version.toString());
            URL url = Utils.getXWikiContext(componentManager).getURLFactory().createAttachmentRevisionURL(attachmentName, spaceName, doc.getName(), version.toString(), null, wikiName, Utils.getXWikiContext(componentManager));
            String attachmentXWikiAbsoluteUrl = url.toString();
            String attachmentXWikiRelativeUrl = Utils.getXWikiContext(componentManager).getURLFactory().getURL(url, Utils.getXWikiContext(componentManager));
            attachments.getAttachments().add(DomainObjectFactory.createAttachmentAtVersion(objectFactory, uriInfo.getBaseUri(), xwikiAttachmentAtVersion, attachmentXWikiRelativeUrl, attachmentXWikiAbsoluteUrl, Utils.getXWikiApi(componentManager), false));
        }
        return attachments;
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : RangeIterable(org.xwiki.rest.internal.RangeIterable) WebApplicationException(javax.ws.rs.WebApplicationException) XWikiRestException(org.xwiki.rest.XWikiRestException) ArrayList(java.util.ArrayList) Document(com.xpn.xwiki.api.Document) Attachments(org.xwiki.rest.model.jaxb.Attachments) URL(java.net.URL) Version(org.suigeneris.jrcs.rcs.Version) XWikiException(com.xpn.xwiki.XWikiException)

Example 44 with XWikiRestException

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

the class AttachmentResourceImpl method putAttachment.

@Override
public Response putAttachment(String wikiName, String spaceName, String pageName, String attachmentName, byte[] content) throws XWikiRestException {
    try {
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, true);
        Document doc = documentInfo.getDocument();
        if (!doc.hasAccessLevel("edit", Utils.getXWikiUser(componentManager))) {
            throw new WebApplicationException(Status.UNAUTHORIZED);
        }
        /* Attach the file */
        AttachmentInfo attachmentInfo = storeAttachment(doc, attachmentName, content);
        if (attachmentInfo.isAlreadyExisting()) {
            return Response.status(Status.ACCEPTED).entity(attachmentInfo.getAttachment()).build();
        } else {
            return Response.created(uriInfo.getAbsolutePath()).entity(attachmentInfo.getAttachment()).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) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiException(com.xpn.xwiki.XWikiException)

Example 45 with XWikiRestException

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

the class AttachmentResourceImpl method deleteAttachment.

@Override
public void deleteAttachment(String wikiName, String spaceName, String pageName, String attachmentName) throws XWikiRestException {
    try {
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, true);
        Document doc = documentInfo.getDocument();
        if (!doc.hasAccessLevel("edit", Utils.getXWikiUser(componentManager))) {
            throw new WebApplicationException(Status.UNAUTHORIZED);
        }
        com.xpn.xwiki.api.Attachment xwikiAttachment = doc.getAttachment(attachmentName);
        if (xwikiAttachment == null) {
            throw new WebApplicationException(Status.NOT_FOUND);
        }
        XWikiDocument xwikiDocument = Utils.getXWiki(componentManager).getDocument(doc.getDocumentReference(), Utils.getXWikiContext(componentManager));
        XWikiAttachment baseXWikiAttachment = xwikiDocument.getAttachment(attachmentName);
        xwikiDocument.removeAttachment(baseXWikiAttachment);
        Utils.getXWiki(componentManager).saveDocument(xwikiDocument, "Deleted attachment [" + baseXWikiAttachment.getFilename() + "]", Utils.getXWikiContext(componentManager));
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WebApplicationException(javax.ws.rs.WebApplicationException) XWikiRestException(org.xwiki.rest.XWikiRestException) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) Document(com.xpn.xwiki.api.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) 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