[Building Sakai] EntityBroker and posting JSON

Aaron Zeckoski aaronz at vt.edu
Fri Feb 5 04:11:35 PST 2010


You do not, however, you will need an empty constructor. It tends to
work best if you export the entity (GET) as json and then use the same
structure for the import. The system tries hard to interpret the
incoming data but adhering to the structure that is returned is the
safest option.
-AZ


On Fri, Feb 5, 2010 at 11:23 AM, Adrian Fish <a.fish at lancaster.ac.uk> wrote:
> Hi Lovemore,
>
> Thanks a bunch for replying so quickly. Do you have to setup keys in the
> json for every field in your POJO, even if the values are empty?
>
> Cheers,
>
> Adrian.
>
> Lovemore Nalube wrote:
>>
>> Dear Adrian
>>  Yes it is possible and very easy too!
>> Your jQuery code seems to work, though you do not need the .json in the
>> url and the dataType in this case is not necessary as well. A meaningful
>> error reason will come from xmlHttpRequest.statustext as that will return
>> the error headers eg: Forbidden (403).
>>  On the EntityProvider side, you will need to do the following (in this
>> example SmsAccount is a POJO):
>> 1. specify a public Object getSampleEntity() that returns new SmsAccount()
>> 2. in createEntity ensure you have: SmsAccount smsAccount = (SmsAccount)
>> entity; //entity in this case entity is the createEntity method parameter.
>> 3. throw appropriate service/validation errors in createEntity so that the
>> jQuery code can respond appropriately.
>>  That's it. Make sure the parameter names (ie object keys in jsonData) are
>> the same as in your POJO definition.
>>  :)
>>  --
>> Lovemore Nalube
>> Online Learning Environments Developer (Vula)
>> PASS Transformation Committee REP
>> Centre for Educational Technology
>> CHED
>> University of Cape Town
>> www.cet.uct.ac.za
>>
>> /* Work Email: lovemore.nalube at uct.ac.za
>> /* Cell: 076 186 1244
>> /* GTalk: lovenalube at gmail.com
>>
>>
>> >>> On 05/02/2010 at 12:47, in message <4B6BF72E.6050702 at lancaster.ac.uk>,
>> >>> Adrian Fish <a.fish at lancaster.ac.uk> wrote:
>> Can you post  a json string to the EB direct handler and have it decoded
>> into a POJO? Anybody know ? I was hoping to be able to post JSON to EB
>> with code like this:
>>
>> jQuery.ajax(
>>        {
>>            url : "/direct/bbb-meeting/new.json",
>>            dataType : "text",
>>            type : 'POST',
>>            data : jsonData,
>>            success : function(meeting)
>>            {
>>                switchState('currentMeetings');
>>            },
>>            error : function(xmlHttpRequest,status,error)
>>            {
>>                alert("Failed to create meeting. Reason: " + error);
>>            }
>>        });
>>
>> ... but am having no success. The entity in my createEntity method is
>> uninitialised.
>>
>> Any ideas? Anyone?
>>
>> Thanks,
>>
>> Adrian.
>>
>> --
>> ==================================
>> Adrian Fish
>> Software Engineer
>> Centre for e-Science
>> Bowland Tower South C Floor
>> Lancaster University
>> Lancaster
>> LA1 4YW
>> email: a.fish at lancaster.ac.uk
>>
>> http://confluence.sakaiproject.org/display/YAFT/Yaft
>> http://confluence.sakaiproject.org/display/BLOG/Home
>> http://confluence.sakaiproject.org/display/AGORA/Home
>>
>
> --
> ==================================
> Adrian Fish
> Software Engineer
> Centre for e-Science
> Bowland Tower South C Floor
> Lancaster University
> Lancaster
> LA1 4YW
> email: a.fish at lancaster.ac.uk
>
> http://confluence.sakaiproject.org/display/YAFT/Yaft
> http://confluence.sakaiproject.org/display/BLOG/Home
> http://confluence.sakaiproject.org/display/AGORA/Home
>
>
> _______________________________________________
> sakai-dev mailing list
> sakai-dev at collab.sakaiproject.org
> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>
> TO UNSUBSCRIBE: send email to sakai-dev-unsubscribe at collab.sakaiproject.org
> with a subject of "unsubscribe"
>



-- 
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