Search in sources :

Example 6 with RangeIterable

use of org.xwiki.rest.internal.RangeIterable in project xwiki-platform by xwiki.

the class ClassesResourceImpl method getClasses.

@Override
public Classes getClasses(String wikiName, Integer start, Integer number) throws XWikiRestException {
    String database = Utils.getXWikiContext(componentManager).getWikiId();
    try {
        getXWikiContext().setWikiId(wikiName);
        List<String> classNames = Utils.getXWikiApi(componentManager).getClassList();
        Collections.sort(classNames);
        RangeIterable<String> ri = new RangeIterable<String>(classNames, start, number);
        Classes classes = objectFactory.createClasses();
        for (String className : ri) {
            com.xpn.xwiki.api.Class xwikiClass = Utils.getXWikiApi(componentManager).getClass(className);
            classes.getClazzs().add(this.utils.toRestClass(uriInfo.getBaseUri(), xwikiClass));
        }
        return classes;
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    } finally {
        Utils.getXWikiContext(componentManager).setWikiId(database);
    }
}
Also used : RangeIterable(org.xwiki.rest.internal.RangeIterable) XWikiRestException(org.xwiki.rest.XWikiRestException) XWikiException(com.xpn.xwiki.XWikiException) Classes(org.xwiki.rest.model.jaxb.Classes)

Example 7 with RangeIterable

use of org.xwiki.rest.internal.RangeIterable 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 8 with RangeIterable

use of org.xwiki.rest.internal.RangeIterable 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 9 with RangeIterable

use of org.xwiki.rest.internal.RangeIterable in project xwiki-platform by xwiki.

the class PagesForTagsResourceImpl method getTags.

@Override
public Pages getTags(String wikiName, String tagNames, Integer start, Integer number, Boolean withPrettyNames) throws XWikiRestException {
    String database = Utils.getXWikiContext(componentManager).getWikiId();
    try {
        Pages pages = objectFactory.createPages();
        Utils.getXWikiContext(componentManager).setWikiId(wikiName);
        String[] tagNamesArray = tagNames.split(",");
        List<String> documentNames = new ArrayList<String>();
        for (String tagName : tagNamesArray) {
            List<String> documentNamesForTag = getDocumentsWithTag(tagName);
            /* Avoid duplicates */
            for (String documentName : documentNamesForTag) {
                if (!documentNames.contains(documentName)) {
                    documentNames.add(documentName);
                }
            }
        }
        RangeIterable<String> ri = new RangeIterable<String>(documentNames, start, number);
        for (String documentName : ri) {
            Document doc = Utils.getXWikiApi(componentManager).getDocument(documentName);
            if (doc != null) {
                pages.getPageSummaries().add(DomainObjectFactory.createPageSummary(objectFactory, uriInfo.getBaseUri(), doc, Utils.getXWikiApi(componentManager), withPrettyNames));
            }
        }
        return pages;
    } catch (Exception e) {
        throw new XWikiRestException(e);
    } finally {
        Utils.getXWikiContext(componentManager).setWikiId(database);
    }
}
Also used : Pages(org.xwiki.rest.model.jaxb.Pages) RangeIterable(org.xwiki.rest.internal.RangeIterable) XWikiRestException(org.xwiki.rest.XWikiRestException) ArrayList(java.util.ArrayList) Document(com.xpn.xwiki.api.Document) QueryException(org.xwiki.query.QueryException) XWikiRestException(org.xwiki.rest.XWikiRestException)

Aggregations

RangeIterable (org.xwiki.rest.internal.RangeIterable)9 XWikiRestException (org.xwiki.rest.XWikiRestException)8 XWikiException (com.xpn.xwiki.XWikiException)7 Document (com.xpn.xwiki.api.Document)7 Objects (org.xwiki.rest.model.jaxb.Objects)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Attachments (org.xwiki.rest.model.jaxb.Attachments)2 Comments (org.xwiki.rest.model.jaxb.Comments)2 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 BaseObject (com.xpn.xwiki.objects.BaseObject)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Version (org.suigeneris.jrcs.rcs.Version)1 QueryException (org.xwiki.query.QueryException)1 Attachment (org.xwiki.rest.model.jaxb.Attachment)1 Classes (org.xwiki.rest.model.jaxb.Classes)1 Pages (org.xwiki.rest.model.jaxb.Pages)1