diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/eventList.get.js b/config/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/eventList.get.js deleted file mode 100644 index 59712fdd28..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/eventList.get.js +++ /dev/null @@ -1,52 +0,0 @@ - - -var siteId = args["site"]; - -model.events = getEvents(siteId); -model.siteId = siteId; - -function getEvents(siteId) -{ - var site = siteService.getSite(siteId); - if (site === null) - { - return []; - } - - var calendar = getCalendarContainer(site); - if (calendar === null) - { - return []; - } - - var query = "+PATH:\"/app:company_home/st:sites/cm:" + search.ISO9075Encode(site.shortName) + "/cm:calendar/*\" " + - "+TYPE:\"{http\://www.alfresco.org/model/calendar}calendarEvent\""; - - var results = search.luceneSearch(query, "ia:fromDate", true); - var e, events = []; - - for (var i=0; i < results.length; i++) - { - e = results[i]; - var ignoreEvents = []; - if (e.children != null) - { - var childrenEvents = e.children; - for (var j=0; j +<#-- <#escape x as jsonUtils.encodeJSONString(x)> --> { <#if events?exists && events?size > 0> <#assign prev = ""> - <#-- We do the sort here as the sort in the JavaScript doesn't seem to work as expected! --> - <#list events?sort_by(["fromDate"]) as item> + <#list events as item> <#assign event = item.event> - <#assign date = event.properties["ia:fromDate"]?string("M/d/yyyy")> + <#assign date = event.start?string("M/d/yyyy")> <#if date != prev> <#assign counter = 0> <#if item_index > 0>], @@ -13,18 +12,18 @@ <#if counter > 0>, { - "name": "${event.properties["ia:whatEvent"]}", - "from": "${event.properties["ia:fromDate"]?string("M/d/yyyy")}", - "start": "${event.properties["ia:fromDate"]?string("HH:mm")}", - "to": "${event.properties["ia:toDate"]?string("M/d/yyyy")}", - "end": "${event.properties["ia:toDate"]?string("HH:mm")}", - "uri": "calendar/event/${siteId}/${event.name}", + "name": "${event.title}", + "from": "${event.start?string("M/d/yyyy")}", + "start": "${event.start?string("HH:mm")}", + "to": "${event.end?string("M/d/yyyy")}", + "end": "${event.end?string("HH:mm")}", + "uri": "calendar/event/${siteId}/${event.systemName}", "tags": [<#list item.tags as tag>"${tag}"<#if tag_has_next>,], - <#if event.properties["ia:recurrenceRule"]??> - "recurrenceRule": "${event.properties["ia:recurrenceRule"]}", + <#if event.recurrenceRule??> + "recurrenceRule": "${event.recurrenceRule}", - <#if event.properties["ia:recurrenceLastMeeting"]??> - "recurrenceLastMeeting": "${event.properties["ia:recurrenceLastMeeting"]?string("M/d/yyyy")}", + <#if event.lastRecurrence??> + "recurrenceLastMeeting": "${event.lastRecurrence?string("M/d/yyyy")}", "ignoreEvents": [<#list item.ignoreEvents as ignoreEvent>"${ignoreEvent}"<#if ignoreEvent_has_next>,] } @@ -34,4 +33,4 @@ } - +<#-- --> diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index fe0922f02b..6c1cd17587 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -1511,4 +1511,10 @@ parent="abstractCalendarWebScript"> - \ No newline at end of file + + + + + 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 2970eeb5c8..2f9951fa3f 100644 --- a/source/java/org/alfresco/repo/web/scripts/calendar/AbstractCalendarWebScript.java +++ b/source/java/org/alfresco/repo/web/scripts/calendar/AbstractCalendarWebScript.java @@ -26,6 +26,7 @@ import java.util.Date; import java.util.HashMap; import java.util.Map; +import org.alfresco.query.PagingRequest; import org.alfresco.repo.calendar.CalendarModel; import org.alfresco.repo.content.MimetypeMap; import org.alfresco.service.cmr.activities.ActivityService; @@ -54,6 +55,11 @@ import org.springframework.extensions.webscripts.WebScriptRequest; public abstract class AbstractCalendarWebScript extends DeclarativeWebScript { public static final String CALENDAR_SERVICE_ACTIVITY_APP_NAME = "calendar"; + + /** + * When no maximum or paging info is given, what should we use? + */ + protected static final int MAX_QUERY_ENTRY_COUNT = 1000; // Injected services protected NodeService nodeService; @@ -177,6 +183,18 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript return null; } + /** + * Builds up a listing Paging request, either using the defaults or + * the paging options specified + */ + protected PagingRequest buildPagingRequest(WebScriptRequest req) + { + // TODO Check the request for standard paging options + PagingRequest paging = new PagingRequest(MAX_QUERY_ENTRY_COUNT); + paging.setRequestTotalCountMax(MAX_QUERY_ENTRY_COUNT); + return paging; + } + /** * Normally the Calendar webscripts return a 200 with JSON * containing the error message. Override this to switch to diff --git a/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntriesListGet.java b/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntriesListGet.java new file mode 100644 index 0000000000..9705cf4ff0 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntriesListGet.java @@ -0,0 +1,97 @@ +/* + * 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.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.alfresco.model.ContentModel; +import org.alfresco.query.PagingRequest; +import org.alfresco.query.PagingResults; +import org.alfresco.repo.calendar.CalendarModel; +import org.alfresco.service.cmr.calendar.CalendarEntry; +import org.alfresco.service.cmr.repository.ChildAssociationRef; +import org.alfresco.service.cmr.site.SiteInfo; +import org.json.JSONObject; +import org.springframework.extensions.webscripts.Cache; +import org.springframework.extensions.webscripts.Status; +import org.springframework.extensions.webscripts.WebScriptRequest; + +/** + * This class is the controller for the slingshot calendar eventList.get webscript. + * + * TODO Improve what we give to the FTL, and have the FTL include iso8601 dates too + * + * @author Nick Burch + * @since 4.0 + */ +public class CalendarEntriesListGet extends AbstractCalendarWebScript +{ + @Override + protected Map executeImpl(SiteInfo site, String eventName, + WebScriptRequest req, JSONObject json, Status status, Cache cache) { + SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy"); // Evil... + + // Get the entries for the list + PagingRequest paging = buildPagingRequest(req); + PagingResults entries = + calendarService.listCalendarEntries(site.getShortName(), paging); + + // For each one in our page, grab details of any ignored instances + List> results = new ArrayList>(); + for (CalendarEntry entry : entries.getPage()) + { + Map result = new HashMap(); + result.put("event", entry); + result.put("fromDate", entry.getStart()); + result.put("tags", entry.getTags()); + + List ignores = nodeService.getChildAssocs( + entry.getNodeRef(), CalendarModel.TYPE_IGNORE_EVENT, + ContentModel.ASSOC_CONTAINS, true + ); + List ignoreEvents = new ArrayList(); + List ignoreEventDates = new ArrayList(); + for (ChildAssociationRef ref : ignores) + { + Date date = (Date)nodeService.getProperty(ref.getChildRef(), CalendarModel.PROP_IGNORE_EVENT_DATE); + if (date != null) + { + ignoreEventDates.add(date); + ignoreEvents.add(formatter.format(date)); + } + } + result.put("ignoreEvents", ignoreEvents); + result.put("ignoreEventDates", ignoreEventDates); + + results.add(result); + } + + // All done + Map model = new HashMap(); + model.put("events", results); + model.put("siteId", site.getShortName()); + model.put("site", site); + return model; + } +}