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());
}
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;
}
Aggregations