Search in sources :

Example 56 with XWikiRestException

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

the class SpacesResourceImpl method getSpaces.

@Override
public Spaces getSpaces(String wikiName, Integer start, Integer number) throws XWikiRestException {
    Spaces spaces = objectFactory.createSpaces();
    try {
        List<String> spaceNames = queryManager.getNamedQuery("getSpaces").addFilter(componentManager.<QueryFilter>getInstance(QueryFilter.class, "hidden")).setOffset(start).setLimit(number).setWiki(wikiName).execute();
        for (String spaceName : spaceNames) {
            List<String> spaceList = Utils.getSpacesFromSpaceId(spaceName);
            String homeId = Utils.getPageId(wikiName, spaceList, "WebHome");
            Document home = null;
            XWiki xwikiApi = Utils.getXWikiApi(componentManager);
            if (xwikiApi.hasAccessLevel("view", homeId)) {
                if (xwikiApi.exists(homeId)) {
                    home = Utils.getXWikiApi(componentManager).getDocument(homeId);
                }
                spaces.getSpaces().add(DomainObjectFactory.createSpace(objectFactory, uriInfo.getBaseUri(), wikiName, spaceList, home));
            }
        }
    } catch (Exception e) {
        throw new XWikiRestException(e);
    }
    return spaces;
}
Also used : QueryFilter(org.xwiki.query.QueryFilter) XWikiRestException(org.xwiki.rest.XWikiRestException) Spaces(org.xwiki.rest.model.jaxb.Spaces) XWiki(com.xpn.xwiki.api.XWiki) Document(com.xpn.xwiki.api.Document) XWikiRestException(org.xwiki.rest.XWikiRestException)

Example 57 with XWikiRestException

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

Example 58 with XWikiRestException

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

the class TagsResourceImpl method getTags.

@Override
public Tags getTags(String wikiName) throws XWikiRestException {
    String database = Utils.getXWikiContext(componentManager).getWikiId();
    try {
        Tags tags = objectFactory.createTags();
        Utils.getXWikiContext(componentManager).setWikiId(wikiName);
        List<String> tagNames = getAllTags();
        for (String tagName : tagNames) {
            Tag tag = objectFactory.createTag();
            tag.setName(tagName);
            String tagUri = Utils.createURI(uriInfo.getBaseUri(), PagesForTagsResource.class, wikiName, tagName).toString();
            Link tagLink = objectFactory.createLink();
            tagLink.setHref(tagUri);
            tagLink.setRel(Relations.TAG);
            tag.getLinks().add(tagLink);
            tags.getTags().add(tag);
        }
        return tags;
    } catch (QueryException e) {
        throw new XWikiRestException(e);
    } finally {
        Utils.getXWikiContext(componentManager).setWikiId(database);
    }
}
Also used : QueryException(org.xwiki.query.QueryException) XWikiRestException(org.xwiki.rest.XWikiRestException) PagesForTagsResource(org.xwiki.rest.resources.tags.PagesForTagsResource) Tag(org.xwiki.rest.model.jaxb.Tag) Tags(org.xwiki.rest.model.jaxb.Tags) Link(org.xwiki.rest.model.jaxb.Link)

Example 59 with XWikiRestException

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

the class WikiResourceImpl method importXAR.

@Override
public Wiki importXAR(String wikiName, Boolean backup, String history, InputStream is) throws XWikiRestException {
    try {
        if (!wikiExists(wikiName)) {
            throw new WebApplicationException(Response.Status.NOT_FOUND);
        }
        /* Use the package plugin for importing pages */
        XWikiContext xwikiContext = getXWikiContext();
        PackageAPI importer = ((PackageAPI) xwikiContext.getWiki().getPluginApi("package", xwikiContext));
        if (importer == null) {
            throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS, XWikiException.ERROR_XWIKI_ACCESS_DENIED, "Can't access Package plugin API. Generally mean you don't have enough rights.");
        }
        String database = xwikiContext.getWikiId();
        try {
            xwikiContext.setWikiId(wikiName);
            importer.setBackupPack(backup);
            importer.Import(is);
            HistoryOptions historyOption = parseHistoryOption(history, HistoryOptions.ADD);
            switch(historyOption) {
                case RESET:
                    importer.setPreserveVersion(false);
                    importer.setWithVersions(false);
                    break;
                case REPLACE:
                    importer.setPreserveVersion(false);
                    importer.setWithVersions(true);
                    break;
                default:
                case ADD:
                    importer.setPreserveVersion(true);
                    importer.setWithVersions(false);
                    break;
            }
            // Set the backup pack option
            importer.setBackupPack(backup);
            if (importer.install() == com.xpn.xwiki.plugin.packaging.DocumentInfo.INSTALL_IMPOSSIBLE) {
                throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
            }
        } catch (IOException e) {
            throw new WebApplicationException(e);
        } finally {
            xwikiContext.setWikiId(database);
        }
        return DomainObjectFactory.createWiki(objectFactory, uriInfo.getBaseUri(), wikiName);
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) PackageAPI(com.xpn.xwiki.plugin.packaging.PackageAPI) XWikiRestException(org.xwiki.rest.XWikiRestException) XWikiContext(com.xpn.xwiki.XWikiContext) IOException(java.io.IOException) XWikiException(com.xpn.xwiki.XWikiException)

Example 60 with XWikiRestException

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

the class ObjectAtPageVersionResourceImpl method getObject.

@Override
public Object getObject(String wikiName, String spaceName, String pageName, String version, String className, Integer objectNumber, Boolean withPrettyName) throws XWikiRestException {
    try {
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, version, true, false);
        Document doc = documentInfo.getDocument();
        XWikiDocument xwikiDocument = Utils.getXWiki(componentManager).getDocument(doc.getDocumentReference(), Utils.getXWikiContext(componentManager));
        xwikiDocument = Utils.getXWiki(componentManager).getDocument(xwikiDocument, doc.getVersion(), Utils.getXWikiContext(componentManager));
        com.xpn.xwiki.objects.BaseObject baseObject = xwikiDocument.getObject(className, objectNumber);
        if (baseObject == null) {
            throw new WebApplicationException(Status.NOT_FOUND);
        }
        return DomainObjectFactory.createObject(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, baseObject, true, Utils.getXWikiApi(componentManager), withPrettyName);
    } 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) 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