Search in sources :

Example 46 with XWikiRestException

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

the class AttachmentVersionResourceImpl method getAttachment.

@Override
public Response getAttachment(String wikiName, String spaceName, String pageName, String attachmentName, String attachmentVersion) throws XWikiRestException {
    try {
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
        Document doc = documentInfo.getDocument();
        com.xpn.xwiki.api.Attachment xwikiAttachment = doc.getAttachment(attachmentName);
        if (xwikiAttachment == null) {
            throw new WebApplicationException(Status.NOT_FOUND);
        }
        /* Get the requested version */
        final com.xpn.xwiki.api.Attachment xwikiAttachmentVersion = xwikiAttachment.getAttachmentRevision(attachmentVersion);
        if (xwikiAttachmentVersion == null) {
            throw new WebApplicationException(Status.NOT_FOUND);
        }
        return Response.ok().type(xwikiAttachment.getMimeType()).entity(xwikiAttachmentVersion.getContent()).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) XWikiException(com.xpn.xwiki.XWikiException)

Example 47 with XWikiRestException

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

the class AbstractClassPropertyValuesProvider method getPropertyDefinition.

@SuppressWarnings("unchecked")
protected T getPropertyDefinition(ClassPropertyReference propertyReference) throws XWikiRestException {
    try {
        XWikiContext xcontext = this.xcontextProvider.get();
        PropertyInterface property = xcontext.getWiki().getDocument(propertyReference, xcontext).getXClass().get(propertyReference.getName());
        if (property == null) {
            throw new XWikiRestException(String.format("Property [%s] not found.", this.entityReferenceSerializer.serialize(propertyReference)));
        } else if (getPropertyType().isInstance(property)) {
            return (T) property;
        } else {
            throw new XWikiRestException(String.format("This [%s] is not a [%s] property.", this.entityReferenceSerializer.serialize(propertyReference), getPropertyType().getSimpleName()));
        }
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : PropertyInterface(com.xpn.xwiki.objects.PropertyInterface) XWikiRestException(org.xwiki.rest.XWikiRestException) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException)

Example 48 with XWikiRestException

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

the class ClassPropertiesResourceImpl method getClassProperties.

@Override
public Properties getClassProperties(String wikiName, String className) 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);
        Properties properties = objectFactory.createProperties();
        properties.getProperties().addAll(clazz.getProperties());
        String classUri = Utils.createURI(uriInfo.getBaseUri(), ClassResource.class, wikiName, xwikiClass.getName()).toString();
        Link classLink = objectFactory.createLink();
        classLink.setHref(classUri);
        classLink.setRel(Relations.CLASS);
        properties.getLinks().add(classLink);
        return properties;
    } 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) Properties(org.xwiki.rest.model.jaxb.Properties) Link(org.xwiki.rest.model.jaxb.Link) XWikiException(com.xpn.xwiki.XWikiException)

Example 49 with XWikiRestException

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

the class ClassResourceImpl method getClass.

@Override
public Class getClass(String wikiName, String className) 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);
        }
        return this.utils.toRestClass(uriInfo.getBaseUri(), xwikiClass);
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    } finally {
        Utils.getXWikiContext(componentManager).setWikiId(database);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) XWikiRestException(org.xwiki.rest.XWikiRestException) XWikiException(com.xpn.xwiki.XWikiException)

Example 50 with XWikiRestException

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

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