Search in sources :

Example 51 with XWikiRestException

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

the class CommentResourceImpl method getComment.

@Override
public Comment getComment(String wikiName, String spaceName, String pageName, Integer id, Integer start, Integer number, Boolean withPrettyNames) throws XWikiRestException {
    try {
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
        Document doc = documentInfo.getDocument();
        Vector<com.xpn.xwiki.api.Object> xwikiComments = doc.getComments();
        for (com.xpn.xwiki.api.Object xwikiComment : xwikiComments) {
            if (id.equals(xwikiComment.getNumber())) {
                return DomainObjectFactory.createComment(objectFactory, uriInfo.getBaseUri(), doc, xwikiComment, Utils.getXWikiApi(componentManager), withPrettyNames);
            }
        }
        throw new WebApplicationException(Status.NOT_FOUND);
    } 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)

Example 52 with XWikiRestException

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

the class CommentsResourceImpl method getComments.

@Override
public Comments getComments(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();
        Comments comments = objectFactory.createComments();
        Vector<com.xpn.xwiki.api.Object> xwikiComments = doc.getComments();
        RangeIterable<com.xpn.xwiki.api.Object> ri = new RangeIterable<com.xpn.xwiki.api.Object>(xwikiComments, start, number);
        for (com.xpn.xwiki.api.Object xwikiComment : ri) {
            comments.getComments().add(DomainObjectFactory.createComment(objectFactory, uriInfo.getBaseUri(), doc, xwikiComment, Utils.getXWikiApi(componentManager), withPrettyNames));
        }
        return comments;
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : RangeIterable(org.xwiki.rest.internal.RangeIterable) Comments(org.xwiki.rest.model.jaxb.Comments) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiException(com.xpn.xwiki.XWikiException)

Example 53 with XWikiRestException

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

the class CommentsResourceImpl method postComment.

@Override
public Response postComment(String wikiName, String spaceName, String pageName, Comment comment) throws XWikiRestException {
    try {
        List<String> spaces = parseSpaceSegments(spaceName);
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaces, pageName, null, null, true, true);
        Document doc = documentInfo.getDocument();
        int id = doc.createNewObject("XWiki.XWikiComments");
        com.xpn.xwiki.api.Object commentObject = doc.getObject("XWiki.XWikiComments", id);
        commentObject.set("author", Utils.getXWikiUser(componentManager));
        commentObject.set("date", new Date());
        boolean save = false;
        if (comment.getHighlight() != null) {
            commentObject.set("highlight", comment.getHighlight());
            save = true;
        }
        if (comment.getText() != null) {
            commentObject.set("comment", comment.getText());
            save = true;
        }
        if (comment.getReplyTo() != null) {
            commentObject.set("replyto", comment.getReplyTo());
        }
        if (save) {
            doc.save();
            Comment createdComment = DomainObjectFactory.createComment(objectFactory, uriInfo.getBaseUri(), doc, commentObject, Utils.getXWikiApi(componentManager), false);
            return Response.created(Utils.createURI(uriInfo.getBaseUri(), CommentResource.class, wikiName, spaces, pageName, id)).entity(createdComment).build();
        }
        return null;
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : Comment(org.xwiki.rest.model.jaxb.Comment) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) Date(java.util.Date) CommentResource(org.xwiki.rest.resources.comments.CommentResource) XWikiException(com.xpn.xwiki.XWikiException)

Example 54 with XWikiRestException

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

the class CommentsVersionResourceImpl method getCommentsVersion.

@Override
public Comments getCommentsVersion(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();
        Comments comments = objectFactory.createComments();
        Vector<com.xpn.xwiki.api.Object> xwikiComments = doc.getComments();
        RangeIterable<com.xpn.xwiki.api.Object> ri = new RangeIterable<com.xpn.xwiki.api.Object>(xwikiComments, start, number);
        for (com.xpn.xwiki.api.Object xwikiComment : ri) {
            comments.getComments().add(DomainObjectFactory.createComment(objectFactory, uriInfo.getBaseUri(), doc, xwikiComment, Utils.getXWikiApi(componentManager), withPrettyNames));
        }
        return comments;
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : RangeIterable(org.xwiki.rest.internal.RangeIterable) Comments(org.xwiki.rest.model.jaxb.Comments) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiException(com.xpn.xwiki.XWikiException)

Example 55 with XWikiRestException

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

the class SpaceResourceImpl method getSpace.

@Override
public Space getSpace(String wikiName, String spaceName) throws XWikiRestException {
    String database = Utils.getXWikiContext(componentManager).getWikiId();
    List<String> spaces = parseSpaceSegments(spaceName);
    try {
        Utils.getXWikiContext(componentManager).setWikiId(wikiName);
        String homeId = Utils.getPageId(wikiName, spaces, "WebHome");
        Document home = null;
        if (Utils.getXWikiApi(componentManager).exists(homeId)) {
            home = Utils.getXWikiApi(componentManager).getDocument(homeId);
        }
        return DomainObjectFactory.createSpace(objectFactory, uriInfo.getBaseUri(), wikiName, spaces, home);
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    } finally {
        Utils.getXWikiContext(componentManager).setWikiId(database);
    }
}
Also used : 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