From e9003e53bda2999e531d0c11f5014eddd3d35aa4 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 6 Jul 2011 17:14:52 +0000 Subject: [PATCH] ALF-9156 Calendar Java API tagging support, and convert the Event Get webscript to be java backed git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28840 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/slingshot/calendar/event.get.js | 260 ------------------ .../slingshot/calendar/lib/calendar.lib.js | 148 +++++++++- .../web-scripts-application-context.xml | 2 +- .../calendar/AbstractCalendarWebScript.java | 13 +- .../scripts/calendar/CalendarEntryGet.java | 38 ++- 5 files changed, 186 insertions(+), 275 deletions(-) delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/event.get.js diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/event.get.js b/config/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/event.get.js deleted file mode 100644 index 6dd7ccb162..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/event.get.js +++ /dev/null @@ -1,260 +0,0 @@ - -/** - * Update event properties - * - * NOTE: Known issue; the recurrence rule strings are not localized. See ALF-6173 - * - * @method GET - * @param uri {string} /calendar/event/{siteid}/{eventname} - */ - -/* Format and return error object */ -function jsonError(errorString) -{ - return ( - { - error: errorString - }); -} - -// TODO: refactor as this method is used in several places -function getTemplateParams() -{ - // Grab the URI parameters - var siteid = "" + url.templateArgs.siteid, - eventname = "" + url.templateArgs.eventname; - - if (siteid === null || siteid.length === 0) - { - return null; - } - - if (eventname === null || eventname.length === 0) - { - return null; - } - - return ( - { - siteid: siteid, - eventname: eventname - }); -} - -function main() -{ - var params = getTemplateParams(); - if (params === null) - { - return jsonError("No parameters supplied"); - } - - // Get the site - var site = siteService.getSite(params.siteid); - if (site === null) - { - return jsonError("Could not find site: " + siteid); - } - - var eventsFolder = getCalendarContainer(site); - if (eventsFolder === null) - { - return jsonError("Could not locate events container"); - } - - var event = eventsFolder.childByNamePath(params.eventname); - if (event === null) - { - return jsonError("Could not find event: " + params.eventname); - } - - var docfolder = ""; - if (event.properties["ia:docFolder"] != null) - { - docfolder = event.properties["ia:docFolder"]; - } - - var recurrence = ""; - if (event.properties["ia:recurrenceRule"] != null) - { - recurrence = buildRecurrenceString(event.properties["ia:recurrenceRule"], event); - } - - var isoutlook = (event.properties["ia:isOutlook"] != null && event.properties["ia:isOutlook"]); - - return ( - { - name: event.name, - what: event.properties["ia:whatEvent"], - description: event.properties["ia:descriptionEvent"], - location: event.properties["ia:whereEvent"] == null ? "" : event.properties["ia:whereEvent"], - from: event.properties["ia:fromDate"], - to: event.properties["ia:toDate"], - tags: event.tags, - allday: isAllDayEvent(event), - docfolder: docfolder, - recurrence: recurrence, - isoutlook: isoutlook - }); -} - -model.result = main(); - -/** - * NOTE: Another option would be to add an "all day" property to the - * existing calendar model. - */ -function isAllDayEvent(event) -{ - var startDate = event.properties["ia:fromDate"], - endDate = event.properties["ia:toDate"], - startTime = startDate.getHours() + ":" + startDate.getMinutes(), - endTime = endDate.getHours() + ":" + endDate.getMinutes(); - - if (logger.isLoggingEnabled()) - { - logger.log("STARTTIME: " + startTime + " " + endTime + " " + (startTime == endTime)); - } - - return (startTime == "0:0" && (startTime == endTime)); -} - -/** - * Build recurrence string for share presentation - - * @param {String} The recurrence rule - * @param {Event} The recurrence event - */ -function buildRecurrenceString(recurrence, event) -{ - var i18n = new Packages.org.springframework.extensions.surf.util.I18NUtil, - dfs = new java.text.DateFormatSymbols(i18n.locale), - weekdays = dfs.getWeekdays(), - days = - { - SU: weekdays[1], - MO: weekdays[2], - TU: weekdays[3], - WE: weekdays[4], - TH: weekdays[5], - FR: weekdays[6], - SA: weekdays[7] - }; - - var finalString = "", - parts = recurrence.split(";"), - eventParam = {}, - part; - - for (var i = 0; i < parts.length; i++) - { - part = parts[i].split("="); - eventParam[part[0]] = part[1]; - } - - if (eventParam['FREQ'] == "WEEKLY") - { - if (eventParam['INTERVAL'] == 1) - { - finalString = "Occurs each week on "; - // finalString = utils.toLocalizedString('occurs.each.week.on'); - } - else - { - finalString = "Occurs every " + eventParam['INTERVAL'] + " weeks on "; - // finalString = utils.toLocalizedString('occurs.every.weeks.on', eventParam['INTERVAL']); - } - - currentDays = eventParam['BYDAY'].split(","); - for (var i = 0; i < currentDays.length; i++) - { - finalString += days[currentDays[i]] + ", "; - } - } - - if (eventParam['FREQ'] == "DAILY") - { - finalString += "Occurs every day "; - // finalString += utils.toLocalizedString('occurs.every.day'); - } - - if (eventParam['FREQ'] == "MONTHLY") - { - if (eventParam['BYMONTHDAY'] != null) - { - finalString += "Occurs day " + eventParam['BYMONTHDAY']; - // finalString += utils.toLocalizedString('occurs.day', eventParam['BYMONTHDAY']); - } - - if (eventParam['BYSETPOS'] != null) - { - finalString += "Occurs the" + eventParam['BYSETPOS'] + " " + days[currentDays[i]]; - // finalString += utils.toLocalizedString('occurs.the', eventParam['BYMONTHDAY'], days[currentDays[i]]); - } - finalString += " of every " + eventParam['INTERVAL'] + " month(s) "; - // finalString += utils.toLocalizedString('of.every.month', eventParam['INTERVAL']); - } - - if (eventParam['FREQ'] == "YEARLY") - { - if (eventParam['BYMONTHDAY'] != null) - { - finalString += "Occurs every " + eventParam['BYMONTHDAY'] + "." + eventParam['BYMONTH'] + " "; - // finalString += utils.toLocalizedString('occurs.every', eventParam['BYMONTHDAY'], eventParam['BYMONTH']); - } - else - { - finalString += "Occurs the " + eventParam['BYSETPOS'] + " " + days[currentDays[i]] + " of " + eventParam['BYMONTH'] + " month "; - // finalString += utils.toLocalizedString('occurs.the.of.month', eventParam['BYSETPOS'], days[currentDays[i]], eventParam['BYMONTH']); - } - } - - finalString += "effective " + format(event.properties["ia:fromDate"]); - // finalString += utils.toLocalizedString('effective', format(event.properties["ia:fromDate"], "dd.mm.yyyy")); - - if (eventParam['COUNT'] != null) - { - finalString += " until " + format(event.properties["ia:recurrenceLastMeeting"]); - // finalString += utils.toLocalizedString('until', format(event.properties["ia:recurrenceLastMeeting"], "dd.mm.yyyy")); - } - - finalString += " from " + format(event.properties["ia:fromDate"], "hh:nn") + " to " + format(event.properties["ia:toDate"], "hh:nn"); - // finalString += utils.toLocalizedString('from.to', format(event.properties["ia:fromDate"], "hh:nn"), format(event.properties["ia:toDate"], "hh:nn")); - - return finalString; -} - -/** - * Format the date by pattern - - * @param date {Date} The date object for format - * @param pattern {String} [Optional] An optional date pattern. Defaults to DateFormat.DEFAULT otherwise - * @return {String} Formated date by pattern - */ -function format(date, pattern) -{ - if (!date.valueOf()) - { - return ' '; - } - - if (pattern == undefined) - { - var i18n = new Packages.org.springframework.extensions.surf.util.I18NUtil; - return java.text.SimpleDateFormat.getDateInstance(java.text.SimpleDateFormat.MEDIUM, i18n.locale).format(date); - } - - return pattern.replace(/(yyyy|mm|dd|hh|nn)/gi, - function($1) - { - switch ($1.toLowerCase()) - { - case 'yyyy': return date.getFullYear(); - case 'mm': return (date.getMonth() < 9 ? '0' : '') + (date.getMonth() + 1); - case 'dd': return (date.getDate() < 10 ? '0' : '') + date.getDate(); - case 'hh': return (date.getHours() < 10 ? '0' : '') + date.getHours(); - case 'nn': return (date.getMinutes() < 10 ? '0' : '') + date.getMinutes(); - } - } - ); -} \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/lib/calendar.lib.js b/config/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/lib/calendar.lib.js index 42d9d893ee..6bfeec02ce 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/lib/calendar.lib.js +++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/lib/calendar.lib.js @@ -20,4 +20,150 @@ function getCalendarContainer(site) } return calendar; -} \ No newline at end of file +} + + +// ===================================================================== +// Helper functions from the old event.get.js file, preserved for +// now while we decide if they need to be ported to Java or not +// ===================================================================== + +/** + * Build recurrence string for share presentation + + * @param {String} The recurrence rule + * @param {Event} The recurrence event + */ +function buildRecurrenceString(recurrence, event) +{ + var i18n = new Packages.org.springframework.extensions.surf.util.I18NUtil, + dfs = new java.text.DateFormatSymbols(i18n.locale), + weekdays = dfs.getWeekdays(), + days = + { + SU: weekdays[1], + MO: weekdays[2], + TU: weekdays[3], + WE: weekdays[4], + TH: weekdays[5], + FR: weekdays[6], + SA: weekdays[7] + }; + + var finalString = "", + parts = recurrence.split(";"), + eventParam = {}, + part; + + for (var i = 0; i < parts.length; i++) + { + part = parts[i].split("="); + eventParam[part[0]] = part[1]; + } + + if (eventParam['FREQ'] == "WEEKLY") + { + if (eventParam['INTERVAL'] == 1) + { + finalString = "Occurs each week on "; + // finalString = utils.toLocalizedString('occurs.each.week.on'); + } + else + { + finalString = "Occurs every " + eventParam['INTERVAL'] + " weeks on "; + // finalString = utils.toLocalizedString('occurs.every.weeks.on', eventParam['INTERVAL']); + } + + currentDays = eventParam['BYDAY'].split(","); + for (var i = 0; i < currentDays.length; i++) + { + finalString += days[currentDays[i]] + ", "; + } + } + + if (eventParam['FREQ'] == "DAILY") + { + finalString += "Occurs every day "; + // finalString += utils.toLocalizedString('occurs.every.day'); + } + + if (eventParam['FREQ'] == "MONTHLY") + { + if (eventParam['BYMONTHDAY'] != null) + { + finalString += "Occurs day " + eventParam['BYMONTHDAY']; + // finalString += utils.toLocalizedString('occurs.day', eventParam['BYMONTHDAY']); + } + + if (eventParam['BYSETPOS'] != null) + { + finalString += "Occurs the" + eventParam['BYSETPOS'] + " " + days[currentDays[i]]; + // finalString += utils.toLocalizedString('occurs.the', eventParam['BYMONTHDAY'], days[currentDays[i]]); + } + finalString += " of every " + eventParam['INTERVAL'] + " month(s) "; + // finalString += utils.toLocalizedString('of.every.month', eventParam['INTERVAL']); + } + + if (eventParam['FREQ'] == "YEARLY") + { + if (eventParam['BYMONTHDAY'] != null) + { + finalString += "Occurs every " + eventParam['BYMONTHDAY'] + "." + eventParam['BYMONTH'] + " "; + // finalString += utils.toLocalizedString('occurs.every', eventParam['BYMONTHDAY'], eventParam['BYMONTH']); + } + else + { + finalString += "Occurs the " + eventParam['BYSETPOS'] + " " + days[currentDays[i]] + " of " + eventParam['BYMONTH'] + " month "; + // finalString += utils.toLocalizedString('occurs.the.of.month', eventParam['BYSETPOS'], days[currentDays[i]], eventParam['BYMONTH']); + } + } + + finalString += "effective " + format(event.properties["ia:fromDate"]); + // finalString += utils.toLocalizedString('effective', format(event.properties["ia:fromDate"], "dd.mm.yyyy")); + + if (eventParam['COUNT'] != null) + { + finalString += " until " + format(event.properties["ia:recurrenceLastMeeting"]); + // finalString += utils.toLocalizedString('until', format(event.properties["ia:recurrenceLastMeeting"], "dd.mm.yyyy")); + } + + finalString += " from " + format(event.properties["ia:fromDate"], "hh:nn") + " to " + format(event.properties["ia:toDate"], "hh:nn"); + // finalString += utils.toLocalizedString('from.to', format(event.properties["ia:fromDate"], "hh:nn"), format(event.properties["ia:toDate"], "hh:nn")); + + return finalString; +} + +/** + * Format the date by pattern + + * @param date {Date} The date object for format + * @param pattern {String} [Optional] An optional date pattern. Defaults to DateFormat.DEFAULT otherwise + * @return {String} Formated date by pattern + */ +function format(date, pattern) +{ + if (!date.valueOf()) + { + return ' '; + } + + if (pattern == undefined) + { + var i18n = new Packages.org.springframework.extensions.surf.util.I18NUtil; + return java.text.SimpleDateFormat.getDateInstance(java.text.SimpleDateFormat.MEDIUM, i18n.locale).format(date); + } + + return pattern.replace(/(yyyy|mm|dd|hh|nn)/gi, + function($1) + { + switch ($1.toLowerCase()) + { + case 'yyyy': return date.getFullYear(); + case 'mm': return (date.getMonth() < 9 ? '0' : '') + (date.getMonth() + 1); + case 'dd': return (date.getDate() < 10 ? '0' : '') + date.getDate(); + case 'hh': return (date.getHours() < 10 ? '0' : '') + date.getHours(); + case 'nn': return (date.getMinutes() < 10 ? '0' : '') + date.getMinutes(); + } + } + ); +} diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index 6e5c4237b9..80e788a2a4 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -1444,7 +1444,7 @@ - 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 d67127b70d..b9a1bb18af 100644 --- a/source/java/org/alfresco/repo/web/scripts/calendar/AbstractCalendarWebScript.java +++ b/source/java/org/alfresco/repo/web/scripts/calendar/AbstractCalendarWebScript.java @@ -61,8 +61,13 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript */ protected Map buildError(String message) { + HashMap result = new HashMap(); + result.put("error", message); + HashMap model = new HashMap(); model.put("error", message); + model.put("result", result); + return model; } @@ -76,7 +81,12 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript return buildError("No parameters supplied"); } - String siteName = templateVars.get("site"); + // Get the site short name. Try quite hard to do so... + String siteName = templateVars.get("siteid"); + if(siteName == null) + { + siteName = templateVars.get("site"); + } if(siteName == null) { siteName = req.getParameter("site"); @@ -86,6 +96,7 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript return buildError("No site given"); } + // Grab the requested site SiteInfo site = siteService.getSite(siteName); if(site == null) { diff --git a/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntryGet.java b/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntryGet.java index c6beaa1c68..d355276a28 100644 --- a/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntryGet.java +++ b/source/java/org/alfresco/repo/web/scripts/calendar/CalendarEntryGet.java @@ -52,19 +52,33 @@ public class CalendarEntryGet extends AbstractCalendarWebScript return buildError("Could not find event: " + eventName); } + // Build the object + Map result = new HashMap(); + result.put("name", entry.getSystemName()); + result.put("what", entry.getTitle()); + result.put("description", entry.getDescription()); + result.put("location", entry.getLocation()); + result.put("from", entry.getStart()); + result.put("to", entry.getEnd()); + result.put("tags", entry.getTags()); + result.put("isoutlook", entry.isOutlook()); + result.put("outlookuid", entry.getOutlookUID()); + result.put("allday", CalendarEntryDTO.isAllDay(entry)); + result.put("recurrence", null); // TODO + result.put("docfolder", null); // TODO + + // Replace nulls with blank strings for the JSON + for(String key : result.keySet()) + { + if(result.get(key) == null) + { + result.put(key, ""); + } + } + + // All done 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("isoutlook", entry.isOutlook()); - model.put("outlookuid", entry.getOutlookUID()); - model.put("allday", CalendarEntryDTO.isAllDay(entry)); - model.put("recurrence", null); // TODO - model.put("docfolder", null); // TODO + model.put("result", result); return model; } }