[Building Sakai] New web service for site membership status

Noah Botimer botimer at umich.edu
Tue Apr 13 13:55:29 PDT 2010


Nicola,

You'll need to pass the site back to the site service to commit the changes. That is, something like this:

		if (membership.isActive() && !active) {
			LOG.error("membership is active but we want it to be inactive");
			membership.setActive(false);
		} else if (!membership.isActive() && active) {
			LOG.error("membership is inactive, but we want it to be active");
			membership.setActive(true);
		}
		siteService.save(site);

Thanks,
-Noah

On Apr 13, 2010, at 4:18 PM, Nicola Monat-Jacobs wrote:

> Hi -
> 
> I'm working on a new simple sakai web service that would allow me to remotely get and set the status of a user's enrollment in a site - active or inactive. The get method works great, however the set method doesn't seem to be working - the status of the user's enrollment doesn't change. I'd love to know if anyone has any thoughts on why this might not be working. Oh, this is a sakai 2-6-x install. Thanks!
> 
> Here's my jws code:
> 
> /** 
>  * Get the status (active vs inactive) of a user's enrollment (membership) in a site
>  *
>  * @param	sessionid	the id of a valid session
>  * @param	siteId		the id of the site you want to check 
>  * @param	eid			the userid of the person you want to check
>  * @return		        active, inactive, blank or error
>  * @throws	AxisFault		
>  *
>  */
> public String getMemberStatus(String sessionid, String siteid, String eid) throws AxisFault { 
> 	
> 	Session s = establishSession(sessionid); 
> 	
> 	String status = "";
> 	
> 	try {
> 		Site site = SiteService.getSite(siteid);
> 
> 		String userid = UserDirectoryService.getUserByEid(eid).getId();
> 		Member membership = site.getMember(userid);
> 
> 		if (membership.isActive()) {
> 			status = "active";
> 		} else {
> 			status = "inactive";
> 		}
> 		
> 	} catch (Exception e) {
> 		LOG.error("WS getMemberStatus(): "+ e.getClass().getName() + " : "+ e.getMessage());
> 		return "";
> 	}
> 	
> 	return status;
> }
> 
> 
> /** 
>  * Set the status of a user's enrollment (membership) in a site to either active or inactive
>  *
>  * @param	sessionid	the id of a valid session
>  * @param	siteId		the id of the site 
>  * @param	eid			the userid of the person whose status you want to set
>  * @param	active		true = active, false = inactive
>  * @return		        success or exception
>  * @throws	AxisFault		
>  *
>  */
> public String setMemberStatus(String sessionid, String siteid, String eid, boolean active) throws AxisFault { 
> 	
> 	Session s = establishSession(sessionid); 
> 	
> 	try {
> 		Site site = SiteService.getSite(siteid);
> 
> 		String userid = UserDirectoryService.getUserByEid(eid).getId();
> 		Member membership = site.getMember(userid);
> 
> 		if (membership.isActive() && !active) {
> 			LOG.error("membership is active but we want it to be inactive");
> 			membership.setActive(false);
> 		} else if (!membership.isActive() && active) {
> 			LOG.error("membership is inactive, but we want it to be active");
> 			membership.setActive(true);
> 		}
> 		
> 	} catch (Exception e) {
> 		LOG.error("WS setMemberStatus(): "+ e.getClass().getName() + " : "+ e.getMessage());
> 		return "";
> 	}
> 	
> 	return "success";
> }
> 
> 
> And here's the demo perl script that I'm using to test it:
> 
> !/usr/bin/perl
> use SOAP::Lite;
> my $host='http://localhost:8080';
> 
> my $soap = SOAP::Lite -> proxy("$host/sakai-axis/SakaiLogin.jws?wsdl");
> my $result =$soap->login("admin","admin");
> my $session=$result->result();
> print $session."\n\n";
> 
> my $true = SOAP::Data->value('true')->type('boolean');
> my $false = SOAP::Data->value('')->type('boolean');
> 
> my $soap2 = SOAP::Lite -> proxy("$host/sakai-axis/WSLongsight.jws?wsdl");
> 
> my $result2 = $soap2->setMemberStatus($session,
> 	"39760797-6184-4b84-892f-e93041e2bcf1",
> 	"joe",
> 	$true);
> 	
> print $result2->result();
> 
> 
> _______________________________________________
> 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"

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20100413/b592edc9/attachment.html 


More information about the sakai-dev mailing list