[Building Sakai] Create a site by Sakai API

Phuc Bui phucbui2006 at yahoo.com.vn
Mon Jul 13 07:17:17 PDT 2009


Dear Steven,

Thanks so much, it's helpful !!! I've done it successfully.

I also found these links

http://www.unicon.net/node/1000 - add Tool to Page

http://www.unicon.net/support/sakai/modules - Tool ID.

About what we are doing:

Because we are trying and studying Sakai so that we can apply Sakai in
future, so we try many ways :)

 

Thanks for your helps.

Phuc Bui

 

From: Steve Swinsburg [mailto:s.swinsburg at lancaster.ac.uk] 
Sent: Monday, July 13, 2009 7:06 PM
To: Phuc Bui
Cc: 'Sakai Mailing List'
Subject: Re: [Building Sakai] Create a site by Sakai API

 

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

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


More information about the sakai-dev mailing list