Search in sources :

Example 11 with Objects

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

the class ObjectsAtPageVersionResourceImpl method getObjects.

@Override
public Objects getObjects(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();
        Objects objects = objectFactory.createObjects();
        List<com.xpn.xwiki.objects.BaseObject> objectList = getBaseObjects(doc);
        RangeIterable<com.xpn.xwiki.objects.BaseObject> ri = new RangeIterable<com.xpn.xwiki.objects.BaseObject>(objectList, start, number);
        for (com.xpn.xwiki.objects.BaseObject object : ri) {
            /* By deleting objects, some of them might become null, so we must check for this */
            if (object != null) {
                objects.getObjectSummaries().add(DomainObjectFactory.createObjectSummary(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, object, true, Utils.getXWikiApi(componentManager), withPrettyNames));
            }
        }
        return objects;
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : RangeIterable(org.xwiki.rest.internal.RangeIterable) XWikiRestException(org.xwiki.rest.XWikiRestException) Document(com.xpn.xwiki.api.Document) Objects(org.xwiki.rest.model.jaxb.Objects) XWikiException(com.xpn.xwiki.XWikiException)

Example 12 with Objects

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

the class ObjectsResourceImpl method getObjects.

@Override
public Objects getObjects(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();
        Objects objects = objectFactory.createObjects();
        List<BaseObject> objectList = getBaseObjects(doc);
        RangeIterable<BaseObject> ri = new RangeIterable<BaseObject>(objectList, start, number);
        for (BaseObject object : ri) {
            /* By deleting objects, some of them might become null, so we must check for this */
            if (object != null) {
                objects.getObjectSummaries().add(DomainObjectFactory.createObjectSummary(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, object, false, Utils.getXWikiApi(componentManager), withPrettyNames));
            }
        }
        return objects;
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : RangeIterable(org.xwiki.rest.internal.RangeIterable) XWikiRestException(org.xwiki.rest.XWikiRestException) Objects(org.xwiki.rest.model.jaxb.Objects) Document(com.xpn.xwiki.api.Document) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiException(com.xpn.xwiki.XWikiException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 13 with Objects

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

the class UIExtensionTest method testUIExtension.

@Test
public void testUIExtension() throws Exception {
    // Test Java UI extensions
    getUtil().rest().savePage(new LocalDocumentReference(getTestClassName(), HELLOWORLD_UIX_PAGE), "{{velocity}}\n" + "\n" + "{{html}}\n" + "#foreach($uix in $services.uix.getExtensions('hello', {'sortByParameter' : 'HelloWorldKey'}))" + "$services.rendering.render($uix.execute(), " + "'xhtml/1.0')#end\n" + "{{/html}}\n" + "\n" + "#foreach($uix in $services.uix.getExtensions('hello', {'sortByParameter' : 'HelloWorldKey'}))\n" + "$uix.parameters\n" + "#end\n" + "{{/velocity}}\n", "");
    // Test Wiki UI extension
    Page extensionsPage = getUtil().rest().page(new LocalDocumentReference(getTestClassName(), HELLOWIKIWORLD_UIX_PAGE));
    Objects objects = new Objects();
    extensionsPage.setObjects(objects);
    Object object = RestTestUtils.object(WikiUIExtensionConstants.CLASS_REFERENCE_STRING);
    object.setNumber(0);
    object.withProperties(RestTestUtils.property("name", "helloWikiWorld2"));
    object.withProperties(RestTestUtils.property("extensionPointId", "hello"));
    object.withProperties(RestTestUtils.property("content", "HelloWikiWorld2"));
    object.withProperties(RestTestUtils.property("parameters", "HelloWorldKey=zz2_$xcontext.user"));
    objects.withObjectSummaries(object);
    object = RestTestUtils.object(WikiUIExtensionConstants.CLASS_REFERENCE_STRING);
    object.setNumber(1);
    object.withProperties(RestTestUtils.property("name", "helloWikiWorld1"));
    object.withProperties(RestTestUtils.property("extensionPointId", "hello"));
    object.withProperties(RestTestUtils.property("content", "HelloWikiWorld1"));
    object.withProperties(RestTestUtils.property("parameters", "HelloWorldKey=zz1_$xcontext.user"));
    objects.withObjectSummaries(object);
    getUtil().rest().save(extensionsPage);
    ViewPage page = getUtil().gotoPage(getTestClassName(), HELLOWORLD_UIX_PAGE);
    Assert.assertEquals("HelloWorld\n" + "HelloWikiWorld1\n" + "HelloWikiWorld2\n" + "{HelloWorldKey=HelloWorldValue}\n" + "{HelloWorldKey=zz1_XWiki.superadmin}\n" + "{HelloWorldKey=zz2_XWiki.superadmin}", page.getContent());
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) Objects(org.xwiki.rest.model.jaxb.Objects) Page(org.xwiki.rest.model.jaxb.Page) ViewPage(org.xwiki.test.ui.po.ViewPage) Object(org.xwiki.rest.model.jaxb.Object) ViewPage(org.xwiki.test.ui.po.ViewPage) Test(org.junit.Test) AbstractTest(org.xwiki.test.ui.AbstractTest)

Aggregations

Objects (org.xwiki.rest.model.jaxb.Objects)13 Page (org.xwiki.rest.model.jaxb.Page)8 Test (org.junit.Test)6 Object (org.xwiki.rest.model.jaxb.Object)6 ObjectSummary (org.xwiki.rest.model.jaxb.ObjectSummary)6 GetMethod (org.apache.commons.httpclient.methods.GetMethod)5 Link (org.xwiki.rest.model.jaxb.Link)5 Document (com.xpn.xwiki.api.Document)4 XWikiRestException (org.xwiki.rest.XWikiRestException)4 Property (org.xwiki.rest.model.jaxb.Property)4 AbstractHttpTest (org.xwiki.test.rest.framework.AbstractHttpTest)4 XWikiException (com.xpn.xwiki.XWikiException)3 RangeIterable (org.xwiki.rest.internal.RangeIterable)3 ObjectResource (org.xwiki.rest.resources.objects.ObjectResource)3 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 BaseObject (com.xpn.xwiki.objects.BaseObject)2 PostMethod (org.apache.commons.httpclient.methods.PostMethod)2 PutMethod (org.apache.commons.httpclient.methods.PutMethod)2 Random (java.util.Random)1 JAXBContext (javax.xml.bind.JAXBContext)1