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
This commit is contained in:
Nick Burch
2011-07-06 17:14:52 +00:00
parent 5c1e37bb5c
commit e9003e53bd
5 changed files with 186 additions and 275 deletions

View File

@@ -1,260 +0,0 @@
<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/lib/calendar.lib.js">
/**
* 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();
}
}
);
}

View File

@@ -21,3 +21,149 @@ function getCalendarContainer(site)
return calendar; return calendar;
} }
// =====================================================================
// 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();
}
}
);
}

View File

@@ -1444,7 +1444,7 @@
</bean> </bean>
<!-- Fetches the details of one Calendar Event --> <!-- Fetches the details of one Calendar Event -->
<bean id="webscript.org.alfresco.repository.slingshot.calendar.event.get" <bean id="webscript.org.alfresco.slingshot.calendar.event.get"
class="org.alfresco.repo.web.scripts.calendar.CalendarEntryGet" class="org.alfresco.repo.web.scripts.calendar.CalendarEntryGet"
parent="abstractCalendarWebScript"> parent="abstractCalendarWebScript">
</bean> </bean>

View File

@@ -61,8 +61,13 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
*/ */
protected Map<String,Object> buildError(String message) protected Map<String,Object> buildError(String message)
{ {
HashMap<String, Object> result = new HashMap<String, Object>();
result.put("error", message);
HashMap<String, Object> model = new HashMap<String, Object>(); HashMap<String, Object> model = new HashMap<String, Object>();
model.put("error", message); model.put("error", message);
model.put("result", result);
return model; return model;
} }
@@ -76,7 +81,12 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
return buildError("No parameters supplied"); 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) if(siteName == null)
{ {
siteName = req.getParameter("site"); siteName = req.getParameter("site");
@@ -86,6 +96,7 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
return buildError("No site given"); return buildError("No site given");
} }
// Grab the requested site
SiteInfo site = siteService.getSite(siteName); SiteInfo site = siteService.getSite(siteName);
if(site == null) if(site == null)
{ {

View File

@@ -52,19 +52,33 @@ public class CalendarEntryGet extends AbstractCalendarWebScript
return buildError("Could not find event: " + eventName); return buildError("Could not find event: " + eventName);
} }
// Build the object
Map<String, Object> result = new HashMap<String, Object>();
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<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
model.put("name", entry.getSystemName()); model.put("result", result);
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
return model; return model;
} }
} }