[Cubicweb] calling methods on remote objects [RFC]

Christophe de Vienne christophe at unlish.com
Thu Apr 2 15:33:01 CEST 2015


Hi Nicolas,

I faced this problem very recently for firing transitions on some
entities within my webservices.

The current hack I use that I can 'expose' adapter functions as
webservices. We can do, for example:

  POST /cwuser/xx/!IWorkflowable.fire_transition {'tr': 'deactivate'}

Making this generic is not really possible because every function has a
different signature, which means I need to manually define each function
I want to expose. (see https://www.cubicweb.org/patch/5100351)

Note that I am not really satisfied with this solution, but I have not a
better one for now. Still, it is some ideas to work on.

About the RQL-based proposition, mind that some adapters methods will
modify the entity, hence we do not want to call them in a 'Any' statement.

Another aspect is the cost of a request. You cannot decently to a GET
for each dc_* function on each entity. It will make your GUI sluggish.

My 2 cents

Christophe

Le 02/04/2015 09:10, Nicolas Chauvat a écrit :
> Hi List,
> 
> I am currently trying to develop a GUI in javascript that uses data
> stored in several CubicWeb apps.
> 
> A reccurent problem I have is that the views are never quite the ones
> I would like, but rewriting everything on the client side feels like
> reinventing the wheel.
> 
> A simple example is for dc_title() and dc_long_title(). The classes in
> entities on the server-side implement these methods, but I have no way
> to access their result as JSON unless I implement a view specifically
> to output it.
> 
> A better example is the cube timesheet and the method get_day_types()
> of the entity Resource. There is some computation going on in there to
> deal with calendar inheritance. There is even a json view that wraps
> that method to wrap a part of the output in JSON. But if I want the
> full result of that computation, I will have to add a new view and
> deploy it on the server.
> 
> Should I really double each entity method with a view?
> 
> I am wondering if we could have some generic mechanism to call methods
> on the entities of a resultset and return the output as JSON.
> 
> For example:
> 
> 'Any X WHERE X is Version' with a call to dc_title() would output
> { [123, 'projectA 0.1.0'], [456, 'projectB 0.2.0'] }
> 
> 'Any X WHERE X is Resource' with a call to get_day_types would output
> { [789, { '2015-01-01': ['dt_nonworking', 'validated'],
>           '2015-01-02': ['dt_working', 'validated']}],
>   [912, { '2015-01-01': ['dt_nonworking', 'validated'],
>           '2015-01-02': ['dt_nonworking', 'pending]}],
> }
> 
> I am not sure what the signature of the call could be... maybe one of
>   /json?rql=...&method=dc_title
>   /view?rql=...&vid=method&method=dc_title
> unless we want to try to include it in RQL and write something like
>   Any X, Version.dc_title(X) WHERE X is Version
>   Any X, Resource.get_day_types(X) WHERE X is Resource
> or even
>   Any X, X.dc_title() WHERE X is Version
>   Any X, X.get_day_types() WHERE X is Resource
> 
> What do you think?
> 
> PS: You may note that the same kind of question can arise for
> adapters: if I have an adapter on the server that can prepare my data
> for a specific view, I may want to get its output directly instead of
> reimplementing it on the client side. Maybe we do not have the right
> set of concepts here and need some kind of generic filter/transform
> functions callable directly from RQL. Maybe I am just looking for the
> equivalent of SQL's stored procedures mixed with generic functions (hence
> a matching of the signature/type to pick the right one depending on
> the arguments) /me wonders...
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <http://lists.cubicweb.org/pipermail/cubicweb/attachments/20150402/c5fc6c79/attachment-0093.sig>


More information about the Cubicweb mailing list