[Building Sakai] SakaiScripts.jws - why don't they return id's rather than just 'success'?

Patrick Haggood phaggood at umich.edu
Fri Jun 8 08:07:28 PDT 2012


Working on a jira (https://jira.sakaiproject.org/browse/UMICH-485)  to
automatically insert a tool onto user sites, I found that the methods for
creating pages and properties only return 'success'.  When adding a page,
it'd be good to receive the newly generated unique id rather than the name
of the created element which *might* not be unique.  In the jira SAK-22206
I propose extending a few of the methods in SakaiScripts.jws into
SakaiWS.jws thus:

 public HashMap addNewPageToSite( String sessionid, String siteid, String
pagetitle, int pagelayout) throws AxisFault

{

  successMessage = new HashMap<String,String>();

Session session = establishSession(sessionid);

 try {

 Site siteEdit = null;

 SitePage sitePageEdit = null;

 siteEdit = siteService.getSite(siteid);

 sitePageEdit = siteEdit.addPage();

 sitePageEdit.setTitle(pagetitle);

 sitePageEdit.setLayout(pagelayout);

 siteService.save(siteEdit);

 successMessage.put("pageid",sitePageEdit.getId());

 successMessage.put("siteid",siteEdit.getId());

 successMessage.put("result","success");

}

catch (Exception e) {

 LOG.error("WS addNewPageToSite(): " + e.getClass().getName() + " : " +
e.getMessage());

 throw new AxisFault("WS addNewPageToSite(): Unable to sadd page " +
pagetitle + " to site id " +siteid);

}

LOG.info("generated pageid " + successMessage.get("pageid"));

return successMessage;

}


In this manner, if I check the map key 'result' 's value for 'success', I
can use the key 'pageid' to get the unique pageid for use in subsequent WS
calls like

addConfigPropertyToPage( String sessionid, String siteid, String pageid,
String propname, String propvalue)

rather than the existing script in SakaiScript which uses pagetitle

addConfigPropertyToPage( String sessionid, String siteid, String pagetitle,
String propname, String propvalue)


Any concerns or suggestions on this approach?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20120608/35f5e8a1/attachment.html 


More information about the sakai-dev mailing list