Index: axis/src/webapp/SakaiScript.jws =================================================================== --- axis/src/webapp/SakaiScript.jws (revision 2658) +++ axis/src/webapp/SakaiScript.jws (working copy) @@ -5,6 +5,7 @@ import java.util.Date; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Iterator; import java.util.Set; @@ -15,6 +16,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.commons.lang.StringUtils; import org.sakaiproject.authz.api.AuthzGroup; import org.sakaiproject.authz.api.Role; @@ -33,6 +35,8 @@ import org.sakaiproject.authz.cover.SecurityService; import org.sakaiproject.site.api.SiteService.SelectionType; import org.sakaiproject.site.api.SiteService.SortType; +import org.sakaiproject.javax.PagingPosition; +import org.sakaiproject.component.cover.ServerConfigurationService; import org.sakaiproject.entity.api.ResourceProperties; import org.sakaiproject.entity.api.ResourcePropertiesEdit; @@ -2030,58 +2034,151 @@ - - -/** - * Copy the calendar events from one site to another - * - * @param sessionid the id of a valid session - * @param sourceSiteId the id of the site containing the calendar entries you want copied - * @param targetSiteId the roles that you want to filter on (string with spaces as delimiters) - * @return success or exception - * @throws AxisFault - * - */ -public String copyCalendarEvents(String sessionid, String sourceSiteId, String targetSiteId) throws AxisFault { - - Session session = establishSession(sessionid); + /** + * Copy the calendar events from one site to another + * + * @param sessionid the id of a valid session + * @param sourceSiteId the id of the site containing the calendar entries you want copied + * @param targetSiteId the roles that you want to filter on (string with spaces as delimiters) + * @return success or exception + * @throws AxisFault + * + */ + public String copyCalendarEvents(String sessionid, String sourceSiteId, String targetSiteId) throws AxisFault { - //setup source and target calendar strings - String calId1 = "/calendar/calendar/"+sourceSiteId+"/main"; - String calId2 = "/calendar/calendar/"+targetSiteId+"/main"; + Session session = establishSession(sessionid); + + //setup source and target calendar strings + String calId1 = "/calendar/calendar/"+sourceSiteId+"/main"; + String calId2 = "/calendar/calendar/"+targetSiteId+"/main"; + + try { + //get calendars + Calendar calendar1 = CalendarService.getCalendar(calId1); + CalendarEdit calendar2 = CalendarService.editCalendar(calId2); + + //for every event in calendar1, add it to calendar2 + List eventsList = calendar1.getEvents(null, null); + + for (Iterator i = eventsList.iterator(); i.hasNext();) { + CalendarEvent cEvent = (CalendarEvent) i.next(); + CalendarEventEdit cedit = calendar2.addEvent(); + cedit.setRange(cEvent.getRange()); + cedit.setDisplayName(cEvent.getDisplayName()); + cedit.setDescription(cEvent.getDescription()); + cedit.setType(cEvent.getType()); + cedit.setLocation(cEvent.getLocation()); + cedit.setDescriptionFormatted(cEvent.getDescriptionFormatted()); + cedit.setRecurrenceRule(cEvent.getRecurrenceRule()); + calendar2.commitEvent(cedit); + //LOG.warn(cEvent.getDisplayName()); + } + //save calendar 2 + CalendarService.commitCalendar(calendar2); + + } catch (Exception e) { + LOG.error("WS copyCalendarEvents(): error " + e.getClass().getName() + " : " + e.getMessage()); + return e.getClass().getName() + " : " + e.getMessage(); + } + return "success"; + } - try { - //get calendars - Calendar calendar1 = CalendarService.getCalendar(calId1); - CalendarEdit calendar2 = CalendarService.editCalendar(calId2); - - //for every event in calendar1, add it to calendar2 - List eventsList = calendar1.getEvents(null, null); - - for (Iterator i = eventsList.iterator(); i.hasNext();) { - CalendarEvent cEvent = (CalendarEvent) i.next(); - CalendarEventEdit cedit = calendar2.addEvent(); - cedit.setRange(cEvent.getRange()); - cedit.setDisplayName(cEvent.getDisplayName()); - cedit.setDescription(cEvent.getDescription()); - cedit.setType(cEvent.getType()); - cedit.setLocation(cEvent.getLocation()); - cedit.setDescriptionFormatted(cEvent.getDescriptionFormatted()); - cedit.setRecurrenceRule(cEvent.getRecurrenceRule()); - calendar2.commitEvent(cedit); - //LOG.warn(cEvent.getDisplayName()); + /** + * Adds a tool page to all My Workspace sites + * + * @param sessionid the id of a valid session for the admin user + * @param toolid the id of the tool you want to add (ie sakai.profile2) + * @param pagetitle the title of the page shown in the site navigation + * @param tooltitle the title of the tool shown in the main portlet + * @param pagelayout single or double column (0 or 1). Any other value will revert to 0. + * @param position integer specifying the position within other pages on the site (0 means top, for right at the bottom a large enough number, ie 99) + * @param popup boolean for if it should be a popup window or not + * + * @return success or exception + * @throws AxisFault + * + * + */ + public String addNewToolToAllMyWorkspaces(String sessionid, String toolid, String pagetitle, String tooltitle, int pagelayout, int position, boolean popup) throws AxisFault + { + Session session = establishSession(sessionid); + + String exclusionList = "!admin,mercury,citationsAdmin,PortfolioAdmin"; + String[] items = StringUtils.split(exclusionList, ','); + List excludedSites = Arrays.asList(items); + + //check that ONLY admin is accessing this + if(!session.getUserId().equals(UserDirectoryService.ADMIN_ID)) { + LOG.warn("WS addNewToolToAllWorkspaces() failed. Restricted to admin user."); + throw new AxisFault("WS failed. Restricted to admin user."); } - //save calendar 2 - CalendarService.commitCalendar(calendar2); + + try { + // Get a list of every site + List siteList = SiteService.getSites( + org.sakaiproject.site.api.SiteService.SelectionType.ANY, + null, "", null, + org.sakaiproject.site.api.SiteService.SortType.TITLE_ASC, + null); + + + siteList.removeAll(excludedSites); + + //now add a page to each site, and the tool to that page + for (Iterator j = siteList.iterator(); j.hasNext();) { + Site site = (Site) j.next(); + + // If it is a 'My Workspace' site. Add the page/tool + if (SiteService.isUserSite(site.getId())) { + String siteId = site.getId(); + LOG.info("Processing site:" + siteId); + + Site siteEdit = null; + SitePage sitePageEdit = null; + + try { + siteEdit = SiteService.getSite(siteId); + } catch (IdUnusedException e) { + LOG.error("No site for Id: " + siteId + ", skipping..."); + continue; + } + + sitePageEdit = siteEdit.addPage(); + sitePageEdit.setTitle(pagetitle); + sitePageEdit.setLayout(pagelayout); + + int numPages = siteEdit.getPages().size(); + if(position > numPages) { + position = numPages-1; + } + + sitePageEdit.setPosition(position); + sitePageEdit.setPopup(popup); + + ToolConfiguration tool = sitePageEdit.addTool(); + Tool t = tool.getTool(); + + tool.setTool(toolid, ToolManager.getTool(toolid)); + tool.setTitle(tooltitle); + try { + SiteService.save(siteEdit); + } + catch (Exception e) { + e.printStackTrace(); + return "fail"; + } + + LOG.info("Page added to site:" + siteId); + + } + } + return "success"; + } + catch (Exception e) { + LOG.error("WS addNewToolToAllSites(): " + e.getClass().getName() + " : " + e.getMessage()); + return e.getClass().getName() + " : " + e.getMessage(); + } - } catch (Exception e) { - LOG.error("WS copyCalendarEvents(): error " + e.getClass().getName() + " : " + e.getMessage()); - return e.getClass().getName() + " : " + e.getMessage(); } - return "success"; -} - - - }