[Building Sakai] Writing an EntityProvider

Aaron Zeckoski aaronz at vt.edu
Thu Oct 15 12:48:46 PDT 2009


We solved this for similar cases before one of two ways:
1) The easiest way is to encode the URL like id (group/id) into
something without slashes (group:id or whatever). The system won't
have any trouble parsing something like that. Then you decode the
values once they reach your provider. This has the disadvantage that
the URLs are probably not really ideal.

2) Use an interceptor to parse the url yourself and update the view so
that it has valid data in it before it continues on. This allows you a
lot of flexibility in the urls you deal with and is probably the next
easiest solution. You would want to update the id in the EntityView so
that it is something your provider understands a little more logically
and in that case it can probably contain slashes since it will not be
parsed again (have not tested that though).
https://source.sakaiproject.org/svn/entitybroker/trunk/api/src/java/org/sakaiproject/entitybroker/entityprovider/capabilities/RequestInterceptor.java

A third option is to use the URL redirect handling part of EB. This
only works with gets of course but it might meet your needs.
https://source.sakaiproject.org/svn/entitybroker/trunk/api/src/java/org/sakaiproject/entitybroker/entityprovider/capabilities/Redirectable.java

There is another option which I have not ever used which may help as well here.
ReferenceParseable should allow you handle the parsing of entity
references yourself instead of using the default parser which
basically deals with prefix/id/** only. I never really wrote any tests
for this or tried using it but the code for it is pretty simple. Your
parser is used whenever the path needs to be parsed instead of the
default one.
https://source.sakaiproject.org/svn/entitybroker/trunk/api/src/java/org/sakaiproject/entitybroker/entityprovider/capabilities/ReferenceParseable.java

Hope that helps!
-AZ


On Thu, Oct 15, 2009 at 5:47 PM, Jim Eng <jimeng at umich.edu> wrote:
> Hi Aaron,
>
> I hope you (or anyone else who reads this message) can help me with an issue
> I'm having in writing an EntityProvider to serve up JSON views of
> ContentEntity objects (ContentCollection's and ContentResources's).
>
> On a sakai instance running my laptop, I have a resource with this
> resourceId:
>
> /group/d6759b23-39e1-48a3-beb7-fc0cc54cc18a/pothole.jpg
>
> The prefix of the entity provider is "resources-list-item", so the URL to
> request this item from the direct servlet is:
>
> http://localhost:8080/direct/resources-list-item/group/d6759b23-39e1-48a3-beb7-fc0cc54cc18a/pothole.jpg.json
>
> When this request arrives at EntityHandlerImpl.handleEntityAccess(), the
> path is shown in the debugger as:
>
> /resources-list-item/group/d6759b23-39e1-48a3-beb7-fc0cc54cc18a/pothole.jpg.json
>
> It appears that EntityHandlerImpl.handleEntityAccess() correctly identifies
> the format as "json" and creates an EntityReference object with prefix of
> "resources-list-item", but it assigns an entityId of "group" in the
> EntityReference.  That is the EntityReference passed to my EntityProvider's
> getEntity() method. This results in an error and I do not get any JSON.
>
> Have I done something wrong, or is there a problem upstream from my code?
>
> I'm also wondering how to deal with entityId's that being and end with a
> slash. EntityID's for ContentCollection's and ContentResources's generally
> begin with a slash, and have one or more internal slashes.  For
> ContentCollection's, they end with a slash.  I'm wondering how to create a
> URL to identify such entityId's to the direct servlet so my EntityProvider
> can get the full entityId, including leading and trailing slashes.  Is that
> possible?
>
> Thanks.
>
> Jim
>
>
>
>



-- 
Aaron Zeckoski (azeckoski (at) vt.edu)
Senior Research Engineer - CARET - University of Cambridge
https://twitter.com/azeckoski - http://www.linkedin.com/in/azeckoski
http://aaronz-sakai.blogspot.com/ - http://tinyurl.com/azprofile


More information about the sakai-dev mailing list