[Building Sakai] Create a site by Sakai API

Steve Swinsburg s.swinsburg at lancaster.ac.uk
Mon Jul 13 05:06:11 PDT 2009


Hi Phuc,

What do you mean there is no effect? The site isn't published?

The 'Site Unavailable' issue you are getting is because you have no  
pages, as you rightly deduce. Again, check the webservices for some  
neat code:

public String addNewPageToSite( String sessionid, String siteid,  
String pagetitle, int pagelayout) throws AxisFault
{
	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);
	
	}
	catch (Exception e) {
		LOG.error("WS addNewPageToSite(): " + e.getClass().getName() + " : "  
+ e.getMessage());
	 	return e.getClass().getName() + " : " + e.getMessage();
	}
	return "success";
}

public String addNewToolToPage( String sessionid, String siteid,  
String pagetitle, String tooltitle, String toolid, String layouthints)  
throws AxisFault
{
	Session session = establishSession(sessionid);
	
	try {

		Site siteEdit = SiteService.getSite(siteid);
		List pageEdits = siteEdit.getPages();
		for (Iterator i = pageEdits.iterator(); i.hasNext();)
		{
			SitePage pageEdit = (SitePage) i.next();
			if (pageEdit.getTitle().equals(pagetitle))
			{
				ToolConfiguration tool = pageEdit.addTool();
				Tool t = tool.getTool();
				
				tool.setTool(toolid, ToolManager.getTool(toolid));
				tool.setTitle(tooltitle);
				//toolEdit.setTitle(tooltitle);
				//toolEdit.setToolId(toolid);
				//tool.setLayoutHints(layouthints);
			}
		}
		SiteService.save(siteEdit);
	
	}
	catch (Exception e) {
		LOG.error("WS addNewToolToPage(): " + e.getClass().getName() + " : "  
+ e.getMessage());
	 	return e.getClass().getName() + " : " + e.getMessage();
	}
	return "success";
}

Of course these will need to be adapted for the Sakai API as they are  
webservice based (hint: drop the session param, session check, 'throws  
AxisFault' and change return type to be a boolean or something.

The *better* solution is to use the other constructor when you are  
making the site in the first place, which takes the id of an existing  
site and all tools are copied across so you get a fully functioning  
site instantly and don't need to add pages. No content is copied  
though, just the structure and tools.

SiteService.addSite(String id, Site other)
- where 'other' is the Site object of the other site.

I have to ask, how come you are doing this and not using/extending the  
existing tools to make a site?




cheers,
Steve

---
Steve Swinsburg
Portal Systems Developer
Centre for e-Science
Lancaster University
Lancaster
LA1 4YT

email: s.swinsburg at lancaster.ac.uk
phone: +44 (0) 1524 594870







On 12 Jul 2009, at 18:11, Phuc Bui wrote:

> That’s great !!!
> But why there’s no effect ?
> I’ll try again. J
> Would you please tell me how to add some default tools (Home,  
> SiteInfo, Announcement, Schedule…) ? Because when I’ve created a  
> site, it displayed “SiteUnavailable” on the left panel where is the  
> location of tools, until I added some tools (edit that site in Admin  
> Workspace).
>
> Thanks,
> Phuc Bui
>
> From: Steve Swinsburg [mailto:s.swinsburg at lancaster.ac.uk]
> Sent: Sunday, July 12, 2009 5:09 PM
> To: Phuc Bui
> Cc: 'Sakai Mailing List'
> Subject: Re: [Building Sakai] Create a site by Sakai API
>
> Hi Phuc,
>
> This all looks good. You want:
>
> addedSite.setPublished(true);
>
> to publish the site.
>
> You could take a look at how the webservices do it, they are a  
> pretty good example of some clean concise code. Reproduced below:
>
>                         Site siteEdit = null;
>                         siteEdit = SiteService.addSite(siteid, type);
>                         siteEdit.setTitle(title);
>                         siteEdit.setDescription(description);
>                         siteEdit.setShortDescription(shortdesc);
>                         siteEdit.setIconUrl(iconurl);
>                         siteEdit.setInfoUrl(infourl);
>                         siteEdit.setJoinable(joinable);
>                         siteEdit.setJoinerRole(joinerrole);
>                         siteEdit.setPublished(published);
>                         siteEdit.setPubView(publicview);
>                         siteEdit.setSkin(skin);
>                         siteEdit.setType(type);
>                         SiteService.save(siteEdit);
>
> cheers,
> Steve
>
>
>
> On 11 Jul 2009, at 22:05, Phuc Bui wrote:
>
>
> Dear all,
> I use class org.sakaiproject.site.api.SiteService to create a site.
> But I do not know how to publish this site, and add some default  
> tool for it (ex: Home, SiteInfo, Announcement …) (of course, all  
> works should be done by Sakai API). I tried this class -  
> org.sakaiproject.tool.api.ToolManager, and see the  
> methodregister(Tool tool), but I don’t know how to use it ?
> I have a part of code:
>
> Site addedSite = siteService.addSite(siteId, siteType);
> addedSite.setDescription("create by NLU Tool as a demo");
> addedSite.setJoinable(true);
> addedSite.setJoinerRole("student");
> addedSite.setTitle("Demo site created by NLU Tool");
>
> siteService.allowAccessSite(addedSite.getId());
> siteService.save(addedSite);
>
> I did it, but the site that was created by this method did not have  
> the title and description like this ?
>
> Looking forward to your replies,
> Thanks,
> Phuc Bui

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


More information about the sakai-dev mailing list