use of org.alfresco.service.cmr.calendar.CalendarEntry in project alfresco-remote-api by Alfresco.
the class CalendarEntryPost method executeImpl.
@Override
protected Map<String, Object> executeImpl(SiteInfo site, String eventName, WebScriptRequest req, JSONObject json, Status status, Cache cache) {
final ResourceBundle rb = getResources();
CalendarEntry entry = new CalendarEntryDTO();
// TODO Handle All Day events properly, including timezones
boolean isAllDay = false;
try {
// Grab the properties
entry.setTitle(getOrNull(json, "what"));
entry.setDescription(getOrNull(json, "desc"));
entry.setLocation(getOrNull(json, "where"));
entry.setSharePointDocFolder(getOrNull(json, "docfolder"));
// Handle the dates
isAllDay = extractDates(entry, json);
// Handle tags
if (json.containsKey("tags")) {
StringTokenizer st = new StringTokenizer((String) json.get("tags"), ",");
while (st.hasMoreTokens()) {
entry.getTags().add(st.nextToken());
}
}
} catch (JSONException je) {
String message = rb.getString(MSG_INVALID_JSON);
return buildError(MessageFormat.format(message, je.getMessage()));
}
// Have it added
entry = calendarService.createCalendarEntry(site.getShortName(), entry);
// Generate the activity feed for this
String dateOpt = addActivityEntry("created", entry, site, req, json);
// Build the return object
Map<String, Object> result = new HashMap<String, Object>();
result.put("name", entry.getTitle());
result.put("desc", entry.getDescription());
result.put("where", entry.getLocation());
result.put("from", removeTimeZoneIfRequired(entry.getStart(), isAllDay, isAllDay));
result.put("to", removeTimeZoneIfRequired(entry.getEnd(), isAllDay, isAllDay));
String legacyDateFormat = "yyyy-MM-dd";
String legacyTimeFormat = "HH:mm";
result.put("legacyDateFrom", removeTimeZoneIfRequired(entry.getStart(), isAllDay, isAllDay, legacyDateFormat));
result.put("legacyTimeFrom", removeTimeZoneIfRequired(entry.getStart(), isAllDay, isAllDay, legacyTimeFormat));
result.put("legacyDateTo", removeTimeZoneIfRequired(entry.getEnd(), isAllDay, isAllDay, legacyDateFormat));
result.put("legacyTimeTo", removeTimeZoneIfRequired(entry.getEnd(), isAllDay, isAllDay, legacyTimeFormat));
result.put("uri", "calendar/event/" + site.getShortName() + "/" + entry.getSystemName() + dateOpt);
result.put("tags", entry.getTags());
result.put("allday", isAllDay);
result.put("docfolder", entry.getSharePointDocFolder());
// 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>();
model.put("result", result);
return model;
}
Aggregations