Search in sources :

Example 1 with Properties

use of org.xwiki.rest.model.jaxb.Properties in project xwiki-platform by xwiki.

the class ObjectPropertiesResourceImpl method getObjectProperties.

@Override
public Properties getObjectProperties(String wikiName, String spaceName, String pageName, String className, Integer objectNumber, Boolean withPrettyNames) throws XWikiRestException {
    try {
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
        Document doc = documentInfo.getDocument();
        com.xpn.xwiki.objects.BaseObject baseObject = getBaseObject(doc, className, objectNumber);
        if (baseObject == null) {
            throw new WebApplicationException(Status.NOT_FOUND);
        }
        Object object = DomainObjectFactory.createObject(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, baseObject, false, Utils.getXWikiApi(componentManager), withPrettyNames);
        Properties properties = objectFactory.createProperties();
        properties.getProperties().addAll(object.getProperties());
        String objectUri = Utils.createURI(uriInfo.getBaseUri(), ObjectResource.class, doc.getWiki(), Utils.getSpacesFromSpaceId(doc.getSpace()), doc.getName(), object.getClassName(), object.getNumber()).toString();
        Link objectLink = objectFactory.createLink();
        objectLink.setHref(objectUri);
        objectLink.setRel(Relations.OBJECT);
        properties.getLinks().add(objectLink);
        return properties;
    } 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) Properties(org.xwiki.rest.model.jaxb.Properties) Object(org.xwiki.rest.model.jaxb.Object) ObjectResource(org.xwiki.rest.resources.objects.ObjectResource) Link(org.xwiki.rest.model.jaxb.Link) XWikiException(com.xpn.xwiki.XWikiException)

Example 2 with Properties

use of org.xwiki.rest.model.jaxb.Properties 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 3 with Properties

use of org.xwiki.rest.model.jaxb.Properties in project xwiki-platform by xwiki.

the class ObjectPropertiesAtPageVersionResourceImpl method getObjectProperties.

@Override
public Properties getObjectProperties(String wikiName, String spaceName, String pageName, String version, String className, Integer objectNumber, Boolean withPrettyNames) 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);
        }
        Object object = DomainObjectFactory.createObject(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, baseObject, true, Utils.getXWikiApi(componentManager), withPrettyNames);
        Properties properties = objectFactory.createProperties();
        properties.getProperties().addAll(object.getProperties());
        String objectUri = Utils.createURI(uriInfo.getBaseUri(), ObjectAtPageVersionResource.class, doc.getWiki(), Utils.getSpacesFromSpaceId(doc.getSpace()), doc.getName(), version, object.getClassName(), object.getNumber()).toString();
        Link objectLink = objectFactory.createLink();
        objectLink.setHref(objectUri);
        objectLink.setRel(Relations.OBJECT);
        properties.getLinks().add(objectLink);
        return properties;
    } 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) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Properties(org.xwiki.rest.model.jaxb.Properties) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Object(org.xwiki.rest.model.jaxb.Object) ObjectAtPageVersionResource(org.xwiki.rest.resources.objects.ObjectAtPageVersionResource) Link(org.xwiki.rest.model.jaxb.Link) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

XWikiException (com.xpn.xwiki.XWikiException)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 XWikiRestException (org.xwiki.rest.XWikiRestException)3 Link (org.xwiki.rest.model.jaxb.Link)3 Properties (org.xwiki.rest.model.jaxb.Properties)3 Document (com.xpn.xwiki.api.Document)2 Object (org.xwiki.rest.model.jaxb.Object)2 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 Class (org.xwiki.rest.model.jaxb.Class)1 ClassResource (org.xwiki.rest.resources.classes.ClassResource)1 ObjectAtPageVersionResource (org.xwiki.rest.resources.objects.ObjectAtPageVersionResource)1 ObjectResource (org.xwiki.rest.resources.objects.ObjectResource)1