Hi Bernardo, First thing to say here... if you have the choice, don`t use XML-RPC (not that well maintained) and use REST (better supported, the way to go) instead. http://platform.xwiki.org/xwiki/bin/view/Features/XWikiRESTfulAPI for REST API reference. Read below for another small mention... On 06/16/2011 05:54 PM, Riveira Faraldo, Bernardo wrote:
Hi there!
We are trying to use XWiki 3.0 enterprise, trying to create via XML-RPC thousands of users, groups and membership programmatically so we can keep updated AD, Liferay, other sources of users, other apps, all with CAS integration, etc.
As there is still no confluence 2.0 API compatibility but we need to create users& groups in XWiki from an external software, we have been collecting pieces of code from messages and FAQs about how to implement it.
We try to create users, their pages, and add them to the XWikiAllGroup with :
Page page = new Page();
page.setSpace("XWiki");
page.setTitle("username01");
page.setId("XWiki.username01");
page.setContent("{{include document=\"XWiki.XWikiUserSheet\"/}}");
rpc.storePage(page);
XWikiObject xobj = new XWikiObject();
xobj.setClassName("XWiki.XWikiUsers");
xobj.setPageId("XWiki.username01");
xobj.setProperty("first_name", "name");
xobj.setProperty("last_name", "last name");
xobj.setProperty("email", "email@email.com");
xobj.setProperty("password","##########");
rpc.storeObject(xobj);
XWikiObject xobjgrp = new XWikiObject();
xobjgrp.setClassName("XWiki.XWikiGroups");
xobjgrp.setPageId("XWiki.XWikiAllGroup");
xobjgrp.setProperty("member","XWiki.username01");
rpc.storeObject(xobjgrp);
(Suppose we run that with username01 to username99)
Although first time we run this, the page gets created, the user gets created but the properties not! :-o
If we run again the import, then every user gets their properties. :-?
Then, only the LAST user created gets correctly added to XWiki.XWikiAllGroup. If we stop/debug the program between each user creation process, always the last one appears at XWiki.XWikiAllGroup when checking via UI. So they are all there for a moment, until they are replaced by the last one. Like if the rpc.storeObject(xobjgrp) deleted previously any other user in that XWiki.XWikiAllGroup page.
Then we try to create groups using this:
// create group 01
Page page = new Page();
page.setSpace("XWiki");
page.setTitle("group01");
page.setContent("{{include document='XWiki.XWikiGroupSheet' /}}");
rpc.storePage(page);
// create group 02
Page page = new Page();
page.setSpace("XWiki");
page.setTitle("group02");
page.setContent("{{include document='XWiki.XWikiGroupSheet' /}}");
rpc.storePage(page);
...
Those "Groups" get created as Pages with XWikiGroupSheet app that allows us to see/edit the users via UI, but we need to add them via XML-RPC.
ALSO, they are Pages, but they are NOT EXACTLY the same as if they where created via the Admin UI, where when you create a "Group" it shows slightly differently:
Autocreated via XML-RPC:
[cid:image001.png@01CC2C45.659F3540]
Versus when a group is created via Admin UI, it shows up differently, just like this:
[cid:image002.png@01CC2C45.659F3540]
SO, we suppose the way we create a Group via XML-RPC (just a Page with a special Sheet) is NOT ENOUGH.
You also need to set the page's parent if you want the breadcrumbs to show up nicely for the current page. The UI adds the parent automatically. Thanks, Eduard
And finally we try to add existing users to newly created groups with code like this:
// user 01 to group 01
XWikiObject xobjgrp = new XWikiObject();
xobjgrp.setClassName("XWiki.XWikiGroups");
xobjgrp.setPageId("group01");
xobjgrp.setProperty("member","XWiki.username01");
rpc.storeObject(xobjgrp);
// user 01 to group 02
XWikiObject xobjgrp = new XWikiObject();
xobjgrp.setClassName("XWiki.XWikiGroups");
xobjgrp.setPageId("group02");
xobjgrp.setProperty("member","XWiki.username01");
rpc.storeObject(xobjgrp);
// user 02 to group 01
XWikiObject xobjgrp = new XWikiObject();
xobjgrp.setClassName("XWiki.XWikiGroups");
xobjgrp.setPageId("group01");
xobjgrp.setProperty("member","XWiki.username02");
rpc.storeObject(xobjgrp);
// user 03 to group 01
XWikiObject xobjgrp = new XWikiObject();
xobjgrp.setClassName("XWiki.XWikiGroups");
xobjgrp.setPageId("group01");
xobjgrp.setProperty("member","XWiki.username02");
rpc.storeObject(xobjgrp);
...
If now we check the group via UI, we can find Pages named XWiki.group01 , XWiki.group02, and with only one user each (although in the code up there username 01, 02 and 03 should be members of group01 !!! only THE LAST ONE (username03) remains.
Also we tried to add also some users to the default (pre-created) XWiki.XWikiAdminGroup so they can act as administrators:
XWikiObject xobjgrp = new XWikiObject();
xobjgrp.setClassName("XWiki.XWikiGroups");
xobjgrp.setPageId("XWiki.XWikiAdminGroup");
xobjgrp.setProperty("member","XWiki.username01");
rpc.storeObject(xobjgrp);
XWikiObject xobjgrp = new XWikiObject();
xobjgrp.setClassName("XWiki.XWikiGroups");
xobjgrp.setPageId("XWiki.XWikiAdminGroup");
xobjgrp.setProperty("member","XWiki.username02");
rpc.storeObject(xobjgrp);
As before only XWiki.username02 stays as member of XWiki.XWikiAdminGroup.
We tried this with a fresh install of XWikiEnt3.0+Jetty+HSQLDB, then in Tomcat+MySQL, same problem in all of them.
So, are we doing something wrong? Maybe something must be done with every user or group before you can add membership via XML-RPC?
Sorry for the long post and thanks in advance!
Bernardo Riveira
***** Este mensaje se dirige exclusivamente a su destinatario. Puede contener información privilegiada, confidencial o legalmente protegida. Si ha recibido este mensaje por error le rogamos que lo borre inmediatamente, así como todas sus copias, y lo comunique al remitente. En virtud de la legislación vigente está prohibida la utilización, divulgación copia o impresión sin autorización. No existe renuncia a la confidencialidad o privilegio por causa de una transmisión errónea. *****
_______________________________________________ devs mailing list devs@xwiki.org http://lists.xwiki.org/mailman/listinfo/devs