[Building Sakai] Updating a Resource through Tool

Stuart Childs stuart.childs at scorm.com
Wed Aug 3 12:52:47 PDT 2011


Hello,

I'm working on a Sakai Tool that allows users to create resources in their Sakai instance that link to external content through our service. I'm trying to add a feature to allow the user to update the reference to that external content through the resource manager tool. It's "working" but I've run into a locking issue that I can't seem to figure out.

The relevant section of code (for reference, the full source for the tool is available on GitHub, package-update branch at https://github.com/RusticiSoftware/SCORMCloud_SakaiPlugin/tree/package-update):

	private void updateResourceForScormCloudEntity(String contentEntityId, ScormCloudPackage pkg) throws Exception {
		log.debug("updateResource contentEntityId = " + contentEntityId);
		getContentHostingService().removeAllLocks(contentEntityId);
		ContentResourceEdit resource = getContentHostingService().editResource(contentEntityId);
		
		ResourcePropertiesEdit properties = resource.getPropertiesEdit();
		properties.removeProperty(ResourceProperties.PROP_DISPLAY_NAME);
		properties.addProperty(ResourceProperties.PROP_DISPLAY_NAME, pkg.getTitle());
		getContentHostingService().commitResource(resource);
	}

The update process works without apparent error the first time it is run (either for a resource, or after restarting Tomcat) but if it is run again, an InUseException is thrown by ContentHostingService.editResource. An example exception with stack trace:

org.sakaiproject.exception.InUseException id=/group/a156b4f3-79d0-40fc-af4b-96430a67d8cd/sakai-61a2d4d7-9942-4ec9-a7e2-06f533837eaa.scormcloud 
	org.sakaiproject.content.impl.BaseContentService.editResource(BaseContentService.java:4082)
	com.rusticisoftware.scormcloud.tool.RequestController.updateResourceForScormCloudEntity(RequestController.java:951)
	com.rusticisoftware.scormcloud.tool.RequestController.processUpdatePackageRequest(RequestController.java:926)
	com.rusticisoftware.scormcloud.tool.RequestController.doGet(RequestController.java:179)
	com.rusticisoftware.scormcloud.tool.RequestController.doPost(RequestController.java:820)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	org.sakaiproject.util.RequestFilter.doFilter(RequestFilter.java:646)

From what I've been able to determine, this is caused by a lock on that entity. However, the problem still arises even after I added the silly removeAllLocks line above. Digging a bit into the Sakai source, it seems that commitResource should be enough to free that lock but obviously I must be doing something wrong. If it makes a difference, the Sakai instance this is running on was compiled from 2.7.0 sources with the 1.1.8 kernel.

I'd really appreciate any comments or suggestions you might have about this.

Thanks,
Stuart Childs


More information about the sakai-dev mailing list