Search in sources :

Example 6 with XWikiRestException

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

the class AttachmentsResourceImpl method getAttachments.

@Override
public Attachments getAttachments(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();
        return getAttachmentsForDocument(doc, start, number, withPrettyNames);
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) XWikiException(com.xpn.xwiki.XWikiException)

Example 7 with XWikiRestException

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

the class AbstractClassPropertyValuesProvider method getValues.

@Override
public PropertyValues getValues(ClassPropertyReference propertyReference, int limit, Object... filterParameters) throws XWikiRestException {
    T propertyDefinition = getPropertyDefinition(propertyReference);
    String filter = "";
    if (filterParameters.length > 0 && filterParameters[0] != null) {
        filter = filterParameters[0].toString();
    }
    try {
        if (filter.isEmpty() || limit <= 0) {
            return getAllowedValues(propertyDefinition, limit, filter);
        } else {
            return getMixedValues(propertyDefinition, limit, filter);
        }
    } catch (Exception e) {
        throw new XWikiRestException(e);
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) XWikiException(com.xpn.xwiki.XWikiException) QueryException(org.xwiki.query.QueryException) XWikiRestException(org.xwiki.rest.XWikiRestException)

Example 8 with XWikiRestException

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

the class ClassPropertyResourceImpl method getClassProperty.

@Override
public Property getClassProperty(String wikiName, String className, String propertyName) throws XWikiRestException {
    String database = Utils.getXWikiContext(componentManager).getWikiId();
    try {
        Utils.getXWikiContext(componentManager).setWikiId(wikiName);
        com.xpn.xwiki.api.Class xwikiClass = Utils.getXWikiApi(componentManager).getClass(className);
        if (xwikiClass == null) {
            throw new WebApplicationException(Status.NOT_FOUND);
        }
        Class clazz = DomainObjectFactory.createClass(objectFactory, uriInfo.getBaseUri(), wikiName, xwikiClass);
        for (Property property : clazz.getProperties()) {
            if (property.getName().equals(propertyName)) {
                String classUri = Utils.createURI(uriInfo.getBaseUri(), ClassResource.class, wikiName, xwikiClass.getName()).toString();
                Link classLink = objectFactory.createLink();
                classLink.setHref(classUri);
                classLink.setRel(Relations.CLASS);
                property.getLinks().add(classLink);
                return property;
            }
        }
        throw new WebApplicationException(Status.NOT_FOUND);
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    } finally {
        Utils.getXWikiContext(componentManager).setWikiId(database);
    }
}
Also used : ClassResource(org.xwiki.rest.resources.classes.ClassResource) WebApplicationException(javax.ws.rs.WebApplicationException) XWikiRestException(org.xwiki.rest.XWikiRestException) Class(org.xwiki.rest.model.jaxb.Class) Property(org.xwiki.rest.model.jaxb.Property) Link(org.xwiki.rest.model.jaxb.Link) XWikiException(com.xpn.xwiki.XWikiException)

Example 9 with XWikiRestException

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

the class SpaceSearchResourceImpl method search.

@Override
public SearchResults search(String wikiName, String spaceName, String keywords, List<String> searchScopeStrings, Integer number, Integer start, String orderField, String order, Boolean withPrettyNames) throws XWikiRestException {
    List<String> spaces = parseSpaceSegments(spaceName);
    try {
        SearchResults searchResults = objectFactory.createSearchResults();
        searchResults.setTemplate(String.format("%s?%s", Utils.createURI(uriInfo.getBaseUri(), SpaceSearchResource.class, wikiName, spaces).toString(), SEARCH_TEMPLATE_INFO));
        List<SearchScope> searchScopes = parseSearchScopeStrings(searchScopeStrings);
        searchResults.getSearchResults().addAll(search(searchScopes, keywords, wikiName, Utils.getLocalSpaceId(spaces), Utils.getXWiki(componentManager).getRightService().hasProgrammingRights(Utils.getXWikiContext(componentManager)), number, start, true, orderField, order, withPrettyNames));
        return searchResults;
    } catch (Exception e) {
        throw new XWikiRestException(e);
    }
}
Also used : XWikiRestException(org.xwiki.rest.XWikiRestException) SearchResults(org.xwiki.rest.model.jaxb.SearchResults) SpaceSearchResource(org.xwiki.rest.resources.spaces.SpaceSearchResource) XWikiRestException(org.xwiki.rest.XWikiRestException)

Example 10 with XWikiRestException

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

the class CurrentUserPropertyResourceImpl method setNextPropertyValue.

@Override
public Response setNextPropertyValue(String propertyName) throws XWikiRestException {
    XWikiContext xcontext = (XWikiContext) this.execution.getContext().getProperty(XWikiContext.EXECUTIONCONTEXT_KEY);
    try {
        // For Guest users, raise an error
        if (xcontext.getUserReference() == null) {
            throw new XWikiRestException(String.format("Cannot change property [%s] since the current user is guest", propertyName));
        }
        XWikiDocument userDocument = xcontext.getWiki().getDocument(xcontext.getUserReference(), xcontext);
        if (!this.authorizationManager.hasAccess(Right.EDIT, userDocument.getDocumentReference())) {
            throw new WebApplicationException(Status.UNAUTHORIZED);
        }
        BaseObject object = userDocument.getXObject(USER_REFERENCE);
        if (object == null) {
            throw new WebApplicationException(Status.NOT_FOUND);
        }
        // Find the value to replace:
        // - for a boolean type, if true then the new value is false, if false then then new value is true
        // - for a static list type, find the next value in the list. Note that multiselect lists are not handled
        java.lang.Object newValue = computeNewValue(object, propertyName, xcontext);
        if (newValue != null) {
            object.set(propertyName, newValue, xcontext);
            xcontext.getWiki().saveDocument(userDocument, "Setting next value", true, xcontext);
            return buildResponse(userDocument, propertyName, xcontext);
        } else {
            return Response.status(Status.NOT_MODIFIED).build();
        }
    } catch (XWikiException e) {
        throw new XWikiRestException(String.format("Failed to change property [%s] for user [%s]", propertyName, xcontext.getUserReference()), e);
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WebApplicationException(javax.ws.rs.WebApplicationException) XWikiRestException(org.xwiki.rest.XWikiRestException) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException) BaseObject(com.xpn.xwiki.objects.BaseObject)

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