Search in sources :

Example 26 with Object

use of org.xwiki.rest.model.jaxb.Object 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)

Example 27 with Object

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

the class ModelFactory method toDocument.

public boolean toDocument(Document doc, org.xwiki.rest.model.jaxb.Page restPage) throws XWikiException {
    boolean modified = false;
    if (restPage.getContent() != null) {
        doc.setContent(restPage.getContent());
        modified = true;
    }
    if (restPage.getTitle() != null) {
        doc.setTitle(restPage.getTitle());
        modified = true;
    }
    if (restPage.getParent() != null) {
        doc.setParent(restPage.getParent());
        modified = true;
    }
    if (restPage.getSyntax() != null) {
        doc.setSyntaxId(restPage.getSyntax());
        modified = true;
    }
    doc.setHidden(restPage.isHidden());
    // Set objects
    if (restPage.getObjects() != null) {
        Set<ObjectReference> newReferences = new HashSet<>();
        // Add/update objects
        for (ObjectSummary restObjectSummary : restPage.getObjects().getObjectSummaries()) {
            if (restObjectSummary != null) {
                org.xwiki.rest.model.jaxb.Object restObject = (org.xwiki.rest.model.jaxb.Object) restObjectSummary;
                com.xpn.xwiki.api.Object xwikiObject = doc.getObject(restObject.getClassName(), restObject.getNumber());
                if (xwikiObject == null) {
                    xwikiObject = doc.newObject(restObject.getClassName());
                }
                toObject(xwikiObject, restObject);
                modified = true;
                newReferences.add(xwikiObject.getReference());
            }
        }
        // Remove objects
        List<com.xpn.xwiki.api.Object> toRemove = new ArrayList<>();
        for (Vector<com.xpn.xwiki.api.Object> objects : doc.getxWikiObjects().values()) {
            for (com.xpn.xwiki.api.Object object : objects) {
                if (!newReferences.contains(object.getReference())) {
                    toRemove.add(object);
                }
            }
        }
        for (com.xpn.xwiki.api.Object obj : toRemove) {
            doc.removeObject(obj);
            modified = true;
        }
    }
    return modified;
}
Also used : ArrayList(java.util.ArrayList) ObjectReference(org.xwiki.model.reference.ObjectReference) Object(org.xwiki.rest.model.jaxb.Object) BaseObject(com.xpn.xwiki.objects.BaseObject) Object(org.xwiki.rest.model.jaxb.Object) ObjectSummary(org.xwiki.rest.model.jaxb.ObjectSummary) HashSet(java.util.HashSet)

Aggregations

Object (org.xwiki.rest.model.jaxb.Object)27 Test (org.junit.Test)16 GetMethod (org.apache.commons.httpclient.methods.GetMethod)15 Property (org.xwiki.rest.model.jaxb.Property)15 AbstractHttpTest (org.xwiki.test.rest.framework.AbstractHttpTest)15 Link (org.xwiki.rest.model.jaxb.Link)11 PostMethod (org.apache.commons.httpclient.methods.PostMethod)8 Page (org.xwiki.rest.model.jaxb.Page)8 ObjectResource (org.xwiki.rest.resources.objects.ObjectResource)7 XWikiException (com.xpn.xwiki.XWikiException)6 Document (com.xpn.xwiki.api.Document)6 WebApplicationException (javax.ws.rs.WebApplicationException)6 PutMethod (org.apache.commons.httpclient.methods.PutMethod)6 ObjectSummary (org.xwiki.rest.model.jaxb.ObjectSummary)6 Objects (org.xwiki.rest.model.jaxb.Objects)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)5 XWikiRestException (org.xwiki.rest.XWikiRestException)5 BaseObject (com.xpn.xwiki.objects.BaseObject)3 NameValuePair (org.apache.commons.httpclient.NameValuePair)3 ArrayList (java.util.ArrayList)2