[xwiki-users] How to correctly use the bridge apis ?
Hello, I'm wondering if I'm on the good path ... I'm trying to move out some "old core" api usage, and replace them using the DocumentAccessBridge (3.5.1), in a java component. Considering a very simple use-case : setting property value of an object. Here the document containing object is not in same space as the class. 1- With old core: XWikiDocument doc = context.getWiki().getDocument("Prefs.Document", context); BaseObject obj = serverDoc.getObject("Code.Class"); obj.set("property", value, context); 2- With DAB, using deprecated method: dab.setProperty("Prefs.Document", "Code.Class", "property", value); 3- With DAB, using non-deprecated methods: SpaceReference prefsSpaceRef = new SpaceReference(new EntityReference("Prefs", EntityType.SPACE)); DocumentReference prefsDocRef = new DocumentReference("Document", prefsSpaceRef); SpaceReference codeSpaceRef = new SpaceReference(new EntityReference("Code", EntityType.SPACE)); DocumentReference classDocRef = new DocumentReference("Class", codeSpaceRef); dab.setProperty(prefsDocRef, classDocRef, "property", value); Questions: a- the code with 3- is, IMO, quite verbose compared to the others. Is it really the best way to do this ? Of course I could store the SpaceReference objects to factorize their use and simplify the code. I'd better be sure before recoding all this ... b- what's the best practice, for a component, to properly manage the targeted wiki, in order to be single/multi-wiki/workspaces proof ? Here I didn't bother specifying the targeted wiki, if I do it will add more "*Reference" creations. c- is there any facility method to convert an oldish xwiki document reference (as "wiki:Space.Page" or "Space.Page") to a DocumentReference ? By the way, is the bridge API representative of the future new xwiki data model that will replace old core, or is it only representative of the current bridge api ? Thanks, Jeremie
On Wed, May 30, 2012 at 4:46 PM, Jeremie BOUSQUET <jeremie.bousquet@gmail.com> wrote:
Hello,
I'm wondering if I'm on the good path ... I'm trying to move out some "old core" api usage, and replace them using the DocumentAccessBridge (3.5.1), in a java component.
Considering a very simple use-case : setting property value of an object. Here the document containing object is not in same space as the class.
1- With old core:
XWikiDocument doc = context.getWiki().getDocument("Prefs.Document", context); BaseObject obj = serverDoc.getObject("Code.Class"); obj.set("property", value, context);
2- With DAB, using deprecated method:
dab.setProperty("Prefs.Document", "Code.Class", "property", value);
3- With DAB, using non-deprecated methods:
SpaceReference prefsSpaceRef = new SpaceReference(new EntityReference("Prefs", EntityType.SPACE)); DocumentReference prefsDocRef = new DocumentReference("Document", prefsSpaceRef); SpaceReference codeSpaceRef = new SpaceReference(new EntityReference("Code", EntityType.SPACE)); DocumentReference classDocRef = new DocumentReference("Class", codeSpaceRef); dab.setProperty(prefsDocRef, classDocRef, "property", value);
Questions: a- the code with 3- is, IMO, quite verbose compared to the others. Is it really the best way to do this ? Of course I could store the SpaceReference objects to factorize their use and simplify the code. I'd better be sure before recoding all this ... b- what's the best practice, for a component, to properly manage the targeted wiki, in order to be single/multi-wiki/workspaces proof ? Here I didn't bother specifying the targeted wiki, if I do it will add more "*Reference" creations. c- is there any facility method to convert an oldish xwiki document reference (as "wiki:Space.Page" or "Space.Page") to a DocumentReference ?
By the way, is the bridge API representative of the future new xwiki data model that will replace old core, or is it only representative of the current bridge api ?
The bridge is just temporary and crappy API allowing to not technically trigger a dependency on oldcore module and nothing more, if you have to depend on oldcore for other reason you'd better directly use old APis IMO. The new model will look nothing like that hopefully.
Thanks, Jeremie _______________________________________________ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne
On Wed, May 30, 2012 at 5:46 PM, Jeremie BOUSQUET <jeremie.bousquet@gmail.com> wrote:
Hello,
I'm wondering if I'm on the good path ... I'm trying to move out some "old core" api usage, and replace them using the DocumentAccessBridge (3.5.1), in a java component.
Considering a very simple use-case : setting property value of an object. Here the document containing object is not in same space as the class.
1- With old core:
XWikiDocument doc = context.getWiki().getDocument("Prefs.Document", context); BaseObject obj = serverDoc.getObject("Code.Class"); obj.set("property", value, context);
2- With DAB, using deprecated method:
dab.setProperty("Prefs.Document", "Code.Class", "property", value);
3- With DAB, using non-deprecated methods:
SpaceReference prefsSpaceRef = new SpaceReference(new EntityReference("Prefs", EntityType.SPACE)); DocumentReference prefsDocRef = new DocumentReference("Document", prefsSpaceRef); SpaceReference codeSpaceRef = new SpaceReference(new EntityReference("Code", EntityType.SPACE)); DocumentReference classDocRef = new DocumentReference("Class", codeSpaceRef); dab.setProperty(prefsDocRef, classDocRef, "property", value);
Questions:
a- the code with 3- is, IMO, quite verbose compared to the others. Is it really the best way to do this ? Of course I could store the SpaceReference objects to factorize their use and simplify the code. I'd better be sure before recoding all this ...
I believe you can also write new DocumentReference("wiki", "space", "page") and you can pass null for wiki part if you don't care about it.
b- what's the best practice, for a component, to properly manage the targeted wiki, in order to be single/multi-wiki/workspaces proof ? Here I didn't bother specifying the targeted wiki, if I do it will add more "*Reference" creations.
c- is there any facility method to convert an oldish xwiki document reference (as "wiki:Space.Page" or "Space.Page") to a DocumentReference ?
Yes, DocumentReferenceResolver. Thanks, Marius
By the way, is the bridge API representative of the future new xwiki data model that will replace old core, or is it only representative of the current bridge api ?
Thanks, Jeremie _______________________________________________ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
On Wed, May 30, 2012 at 4:46 PM, Jeremie BOUSQUET <jeremie.bousquet@gmail.com> wrote:
Hello,
I'm wondering if I'm on the good path ... I'm trying to move out some "old core" api usage, and replace them using the DocumentAccessBridge (3.5.1), in a java component.
Considering a very simple use-case : setting property value of an object. Here the document containing object is not in same space as the class.
1- With old core:
XWikiDocument doc = context.getWiki().getDocument("Prefs.Document", context); BaseObject obj = serverDoc.getObject("Code.Class"); obj.set("property", value, context);
2- With DAB, using deprecated method:
dab.setProperty("Prefs.Document", "Code.Class", "property", value);
3- With DAB, using non-deprecated methods:
SpaceReference prefsSpaceRef = new SpaceReference(new EntityReference("Prefs", EntityType.SPACE)); DocumentReference prefsDocRef = new DocumentReference("Document", prefsSpaceRef); SpaceReference codeSpaceRef = new SpaceReference(new EntityReference("Code", EntityType.SPACE)); DocumentReference classDocRef = new DocumentReference("Class", codeSpaceRef); dab.setProperty(prefsDocRef, classDocRef, "property", value);
Did you tested that ? Having a null WikiReference is actually forbidden in SpaceReference. DocumentReference is supposed to be a valid and complete document reference which mean including the wiki reference.
Questions: a- the code with 3- is, IMO, quite verbose compared to the others. Is it really the best way to do this ? Of course I could store the SpaceReference objects to factorize their use and simplify the code. I'd better be sure before recoding all this ... b- what's the best practice, for a component, to properly manage the targeted wiki, in order to be single/multi-wiki/workspaces proof ? Here I didn't bother specifying the targeted wiki, if I do it will add more "*Reference" creations. c- is there any facility method to convert an oldish xwiki document reference (as "wiki:Space.Page" or "Space.Page") to a DocumentReference ?
By the way, is the bridge API representative of the future new xwiki data model that will replace old core, or is it only representative of the current bridge api ?
Thanks, Jeremie _______________________________________________ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne
On Wed, May 30, 2012 at 6:21 PM, Thomas Mortagne <thomas.mortagne@xwiki.com> wrote:
On Wed, May 30, 2012 at 4:46 PM, Jeremie BOUSQUET <jeremie.bousquet@gmail.com> wrote:
Hello,
I'm wondering if I'm on the good path ... I'm trying to move out some "old core" api usage, and replace them using the DocumentAccessBridge (3.5.1), in a java component.
Considering a very simple use-case : setting property value of an object. Here the document containing object is not in same space as the class.
1- With old core:
XWikiDocument doc = context.getWiki().getDocument("Prefs.Document", context); BaseObject obj = serverDoc.getObject("Code.Class"); obj.set("property", value, context);
2- With DAB, using deprecated method:
dab.setProperty("Prefs.Document", "Code.Class", "property", value);
3- With DAB, using non-deprecated methods:
SpaceReference prefsSpaceRef = new SpaceReference(new EntityReference("Prefs", EntityType.SPACE)); DocumentReference prefsDocRef = new DocumentReference("Document", prefsSpaceRef); SpaceReference codeSpaceRef = new SpaceReference(new EntityReference("Code", EntityType.SPACE)); DocumentReference classDocRef = new DocumentReference("Class", codeSpaceRef); dab.setProperty(prefsDocRef, classDocRef, "property", value);
Did you tested that ? Having a null WikiReference is actually forbidden in SpaceReference. DocumentReference is supposed to be a valid and complete document reference which mean including the wiki reference.
Sorry, I was thinking at the script service, which allows you to pass null but resolves the created entity reference. So yes, you need to pass a non-null wiki name. Thanks, Marius
Questions: a- the code with 3- is, IMO, quite verbose compared to the others. Is it really the best way to do this ? Of course I could store the SpaceReference objects to factorize their use and simplify the code. I'd better be sure before recoding all this ... b- what's the best practice, for a component, to properly manage the targeted wiki, in order to be single/multi-wiki/workspaces proof ? Here I didn't bother specifying the targeted wiki, if I do it will add more "*Reference" creations. c- is there any facility method to convert an oldish xwiki document reference (as "wiki:Space.Page" or "Space.Page") to a DocumentReference ?
By the way, is the bridge API representative of the future new xwiki data model that will replace old core, or is it only representative of the current bridge api ?
Thanks, Jeremie _______________________________________________ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne _______________________________________________ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
participants (3)
-
Jeremie BOUSQUET -
Marius Dumitru Florea -
Thomas Mortagne