Sakai/OSPortfolio

ID #1050

Using Sakai Web Services -- from Perl

Sakai offers a wide range of web services -- you can use an external script that creates course worksites, sets up each with distinct arrangements of pages and tools, creates student users and faculty users, assigns each user to the appropriate course worksites as a student or as faculty... and much more!

You might try Serensoft's OSP.pm first -- see below -- it may save you a ton of work!

Using standard Perl modules, you can prepare some quick SOAP like this:

use SOAP::Lite;

my $loginsoap = SOAP::Lite->new( proxy => &LOGINPROXY( $host ));
my $sessionid = $loginsoap->login( $userid, $passwd )->result();
my $session = SOAP::Data->value( $sessionid )->type( 'string' );

my $soap = SOAP::Lite->new(proxy => &SCRIPTPROXY($host));
sub LOGINPROXY {
my $host = shift;
return "$host/sakai-axis/SakaiLogin.jws?wsdl";
}
sub SCRIPTPROXY {
my $host = shift;
return "$host/sakai-axis/SakaiScript.jws?wsdl";
}

Once that's all set up, you can do neat stuff like this:

$soap->addNewSite( $session,
'CS151', # worksite id
'CS151 -- Intro to Perl', # worksite title
'Introduction to Perl and Web Services', # desription
'Web services and Perl', # short description
'', #icon url
'', #info url
'', #joinable
'', #joiner-role
'Yes', #published
'', #public-view
'sakai-horiz', # skin
'project', # type
);
# compare with the java declaration for webservice 'addNewSite' is:
# public String addNewSite( String sessionid, String siteid, String title, String description, String shortdesc, String iconurl, String infourl, boolean joinable, String joinerrole, boolean published, boolean publicview, String skin, String type) throws AxisFault

Above, the "addNewSite" is one of the declared webservices in SakaiScript.jws, and you just make sure to hand it the right arguments in the right order, and you're all set.

Mostly. Okay, we lied. Anywhere the original .jws (Java Web Services) file expects a BOOLEAN, you must make sure the data-type is properly set; so, above, "YES" and "" are both strings by default, but Java needs us to convert those to BOOLEANS.

Here's the trick to do just that:

# set datatype of the incoming $val, to be that of $typ
$outval = SOAP::Data->value( $val )->type( $typ );

Serensoft's OSP.pm perl module

But instead of you having to worry about all that -- and to make things generally a bit easier -- Serensoft has put together a perl module (OSP.pm) at http://www.serensoft.com/OSP/ which takes care of a great deal of the backstage glue, including the data-type enforcement.

In particular, it takes the actual Java source -- where each web-services method is defined -- and uses the argument-types to enforce properly data-typed output. So you can do convenient stuff like this:

use OSP; # Serensoft's "OSP.pm" for Open Source Portfolio / Sakai webservices

my $osp = OSP->new('localhost:8080')
->login('admin','kahunaPasswordHere');

# create a course, three users, and assign student/access and
# faculty/maintain roles all-at-once:
my $course_results = $osp->course(
title => 'CS 352: XML/RPC with Sakai/OSP via Perl',
descr => 'Using Perl w/SOAP for Sakai and OSPortfolio',
short => 'Perl, SOAP::Lite and OSP',
skin => 'computer-science',
studentry => {
tomthumb => { # student key IS the username/login-id
fname => 'Thomas',
lname => 'Thumb',
email => 'tiny@tom.not',
passwd=> 'BigManOnCampus',
},
beginner => {
fname => 'Green',
lname => 'Horn',
email => 'noob@nowhere.not',
passwd=> 'TeachMeSeymour',
},
},
faculty => {
arand=>{ # faculty key == id (username/login)
fname=>'Alisa',
lname=>'Rosenbaum',
email=>'galt@gulch.not',
passwd=>'IsbMl,&Mloi,tIwnl4tsoam,naam2l4m',
},
},
);

To see how easy it is to work with Sakai web services from Perl, check out Serensoft's OSP.pm (our main focus is on OSPortfolio, so that's why we gave it the OSP name -- sorry about that!).


Sakai is an open-source LMS (learning management system) or CLE (collaborative learning environment); OSP is an electronic portfolio built on top of Sakai.

Categories for this entry

Last update: 2008-04-03 21:17
Author: will trillich
Revision: 1.1

Print this record Print this record
Send to a friend Send to a friend
Show this as PDF file Show this as PDF file
Export as XML-File Export as XML-File

Please rate this entry:

Average rating: 4.71 out of 5 (31 Votes )

completely useless 1 2 3 4 5 most valuable

You cannot comment on this entry