diff --git a/source/java/org/alfresco/repo/web/scripts/calendar/AbstractCalendarWebScript.java b/source/java/org/alfresco/repo/web/scripts/calendar/AbstractCalendarWebScript.java index d7c683bd79..c44b5db8fd 100644 --- a/source/java/org/alfresco/repo/web/scripts/calendar/AbstractCalendarWebScript.java +++ b/source/java/org/alfresco/repo/web/scripts/calendar/AbstractCalendarWebScript.java @@ -18,10 +18,18 @@ */ package org.alfresco.repo.web.scripts.calendar; +import java.util.HashMap; +import java.util.Map; + import org.alfresco.repo.model.Repository; +import org.alfresco.service.cmr.calendar.CalendarService; import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.site.SiteInfo; import org.alfresco.service.cmr.site.SiteService; +import org.springframework.extensions.webscripts.Cache; import org.springframework.extensions.webscripts.DeclarativeWebScript; +import org.springframework.extensions.webscripts.Status; +import org.springframework.extensions.webscripts.WebScriptRequest; /** * @author Nick Burch @@ -33,6 +41,7 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript protected Repository repository; protected NodeService nodeService; protected SiteService siteService; + protected CalendarService calendarService; public void setRepository(Repository repository) { @@ -48,4 +57,55 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript { this.siteService = siteService; } + + public void setCalendarService(CalendarService calendarService) + { + this.calendarService = calendarService; + } + + /** + * Equivalent of jsonError in the old JavaScript controllers + */ + protected Map buildError(String message) + { + HashMap model = new HashMap(); + model.put("error", message); + return model; + } + + @Override + protected Map executeImpl(WebScriptRequest req, + Status status, Cache cache) + { + Map templateVars = req.getServiceMatch().getTemplateVars(); + if(templateVars == null) + { + return buildError("No parameters supplied"); + } + + String siteName = templateVars.get("site"); + if(siteName == null) + { + siteName = req.getParameter("site"); + } + if(siteName == null) + { + return buildError("No site given"); + } + + SiteInfo site = siteService.getSite(siteName); + if(site == null) + { + return buildError("Could not find site: " + siteName); + } + + // Event name is optional + String eventName = templateVars.get("eventname"); + + // Have the real work done + return executeImpl(site, eventName, req, status, cache); + } + + protected abstract Map executeImpl(SiteInfo site, + String eventName, WebScriptRequest req, Status status, Cache cache); } diff --git a/source/java/org/alfresco/repo/web/scripts/calendar/AllCalendarTests.java b/source/java/org/alfresco/repo/web/scripts/calendar/AllCalendarTests.java new file mode 100644 index 0000000000..4eb5bdfc74 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/calendar/AllCalendarTests.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2005-2011 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.repo.web.scripts.calendar; + +import org.alfresco.repo.calendar.CalendarServiceImplTest; +import org.alfresco.service.cmr.calendar.CalendarService; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * This class is a holder for the various test classes associated with the {@link CalendarService}. + * It is not (at the time of writing) intended to be incorporated into the automatic build + * which will find the various test classes and run them individually. + * + * @author Nick Burch + * @since 4.0 + */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ + CalendarServiceImplTest.class, + CalendarRestApiTest.class +}) +public class AllCalendarTests +{ + // Intentionally empty +} diff --git a/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntryGet.java b/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntryGet.java new file mode 100644 index 0000000000..b65a08acef --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntryGet.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2005-2011 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.repo.web.scripts.calendar; + +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.repo.model.Repository; +import org.alfresco.service.cmr.calendar.CalendarEntry; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.site.SiteInfo; +import org.alfresco.service.cmr.site.SiteService; +import org.springframework.extensions.webscripts.Cache; +import org.springframework.extensions.webscripts.DeclarativeWebScript; +import org.springframework.extensions.webscripts.Status; +import org.springframework.extensions.webscripts.WebScriptRequest; + +/** + * This class is the controller for the slingshot calendar event.get webscript. + * + * @author Nick Burch + * @since 4.0 + */ +public class CalendarEntryGet extends AbstractCalendarWebScript +{ + @Override + protected Map executeImpl(SiteInfo site, String eventName, + WebScriptRequest req, Status status, Cache cache) { + CalendarEntry entry = calendarService.getCalendarEntry( + site.getShortName(), eventName + ); + + if(entry == null) + { + return buildError("Could not find event: " + eventName); + } + + Map model = new HashMap(); + model.put("name", entry.getSystemName()); + model.put("what", entry.getTitle()); + model.put("description", entry.getDescription()); + model.put("location", entry.getLocation()); + model.put("from", entry.getStart()); + model.put("to", entry.getEnd()); + model.put("tags", entry.getTags()); + model.put("allday", null); // TODO + model.put("docfolder", null); // TODO + model.put("recurrence", null); // TODO + model.put("isoutlook", null); // TODO + return model; + } +}