use of org.alfresco.service.cmr.calendar.CalendarEntry in project alfresco-remote-api by Alfresco.
the class CalendarEntriesListGet method executeImpl.
@Override
protected Map<String, Object> executeImpl(SiteInfo site, String eventName, WebScriptRequest req, JSONObject json, Status status, Cache cache) {
// Evil format needed for compatibility with old API...
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
// Decide on date ranges and repeating rules
Date fromDate = parseDate(req.getParameter("from"));
Date toDate = parseDate(req.getParameter("to"));
boolean resortNeeded = false;
boolean repeatingFirstOnly = true;
String repeatingEvents = req.getParameter("repeating");
if (repeatingEvents != null) {
if ("first".equals(repeatingEvents)) {
repeatingFirstOnly = true;
} else if ("all".equals(repeatingEvents)) {
repeatingFirstOnly = false;
resortNeeded = true;
}
}
// Get the entries for the list
PagingRequest paging = buildPagingRequest(req);
PagingResults<CalendarEntry> entries = calendarService.listCalendarEntries(new String[] { site.getShortName() }, fromDate, toDate, paging);
// For each one in our page, grab details of any ignored instances
List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
for (CalendarEntry entry : entries.getPage()) {
Map<String, Object> result = new HashMap<String, Object>();
result.put(RESULT_EVENT, entry);
result.put(RESULT_NAME, entry.getSystemName());
result.put(RESULT_TITLE, entry.getTitle());
boolean isAllDay = CalendarEntryDTO.isAllDay(entry);
boolean removeTimezone = isAllDay && !entry.isOutlook();
result.put(RESULT_START, removeTimeZoneIfRequired(entry.getStart(), isAllDay, removeTimezone));
result.put(RESULT_END, removeTimeZoneIfRequired(entry.getEnd(), isAllDay, removeTimezone));
if (isAllDay) {
long dayLong = 86400000;
Date newDay = new Date(entry.getEnd().getTime() + dayLong);
result.put("allDayEnd", newDay);
}
String legacyDateFormat = "M/d/yyyy";
String legacyTimeFormat = "HH:mm";
result.put("legacyDateFrom", removeTimeZoneIfRequired(entry.getStart(), isAllDay, removeTimezone, legacyDateFormat));
result.put("legacyTimeFrom", removeTimeZoneIfRequired(entry.getStart(), isAllDay, removeTimezone, legacyTimeFormat));
result.put("legacyDateTo", removeTimeZoneIfRequired(entry.getEnd(), isAllDay, removeTimezone, legacyDateFormat));
result.put("legacyTimeTo", removeTimeZoneIfRequired(entry.getEnd(), isAllDay, removeTimezone, legacyTimeFormat));
result.put("fromDate", entry.getStart());
result.put("tags", entry.getTags());
List<ChildAssociationRef> ignores = nodeService.getChildAssocs(entry.getNodeRef(), CalendarModel.TYPE_IGNORE_EVENT, ContentModel.ASSOC_CONTAINS, true);
List<String> ignoreEvents = new ArrayList<String>();
List<Date> ignoreEventDates = new ArrayList<Date>();
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);
// For repeating events, push forward if needed
boolean orderChanged = handleRecurring(entry, result, results, fromDate, toDate, repeatingFirstOnly);
if (orderChanged) {
resortNeeded = true;
}
// All done with this one
results.add(result);
}
// If they asked for repeating events to be expanded, then do so
if (resortNeeded) {
Collections.sort(results, getEventDetailsSorter());
}
// All done
Map<String, Object> model = new HashMap<String, Object>();
model.put("events", results);
model.put("siteId", site.getShortName());
model.put("site", site);
return model;
}
use of org.alfresco.service.cmr.calendar.CalendarEntry in project alfresco-remote-api by Alfresco.
the class CalendarEntryPut 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 = calendarService.getCalendarEntry(site.getShortName(), eventName);
if (entry == null) {
String message = rb.getString(MSG_EVENT_NOT_FOUND);
return buildError(MessageFormat.format(message, eventName));
}
// TODO Handle All Day events properly, including timezones
boolean isAllDay = false;
try {
// Doc folder is a bit special
String docFolder = (String) json.get("docfolder");
// Editing recurring events is special and a little bit odd...
if (entry.getRecurrenceRule() != null && !json.containsKey("recurrenceRule")) {
// Have an ignored event generated
// Will allow us to override this one instance
createIgnoreEvent(req, entry);
// Create a new entry for this one case
CalendarEntry newEntry = new CalendarEntryDTO();
newEntry.setOutlook(true);
if ("*NOT_CHANGE*".equals(docFolder)) {
newEntry.setSharePointDocFolder(entry.getSharePointDocFolder());
}
// From here on, "edit" the new version
entry = newEntry;
}
// Doc folder is a bit special
if ("*NOT_CHANGE*".equals(docFolder)) {
// Nothing to change
} else {
entry.setSharePointDocFolder(docFolder);
}
// Grab the properties
entry.setTitle(getOrNull(json, "what"));
entry.setDescription(getOrNull(json, "desc"));
entry.setLocation(getOrNull(json, "where"));
// Handle the dates
isAllDay = extractDates(entry, json);
// Recurring properties, only changed if keys present
if (json.containsKey("recurrenceRule")) {
if (json.get("recurrenceRule") == null) {
entry.setRecurrenceRule(null);
} else {
entry.setRecurrenceRule((String) json.get("recurrenceRule"));
}
}
if (json.containsKey("recurrenceLastMeeting")) {
if (json.get("recurrenceLastMeeting") == null) {
entry.setLastRecurrence(null);
} else {
entry.setLastRecurrence(parseDate((String) json.get("recurrenceLastMeeting")));
}
}
// Handle tags
if (json.containsKey("tags")) {
entry.getTags().clear();
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 edited
entry = calendarService.updateCalendarEntry(entry);
// Generate the activity feed for this
String dateOpt = addActivityEntry("updated", entry, site, req, json);
// Build the return object
Map<String, Object> result = new HashMap<String, Object>();
result.put("summary", entry.getTitle());
result.put("description", entry.getDescription());
result.put("location", entry.getLocation());
boolean removeTimezone = isAllDay && !entry.isOutlook();
result.put("dtstart", removeTimeZoneIfRequired(entry.getStart(), isAllDay, removeTimezone));
result.put("dtend", removeTimeZoneIfRequired(entry.getEnd(), isAllDay, removeTimezone));
String legacyDateFormat = "yyyy-MM-dd";
String legacyTimeFormat = "HH:mm";
result.put("legacyDateFrom", removeTimeZoneIfRequired(entry.getStart(), isAllDay, removeTimezone, legacyDateFormat));
result.put("legacyTimeFrom", removeTimeZoneIfRequired(entry.getStart(), isAllDay, removeTimezone, legacyTimeFormat));
result.put("legacyDateTo", removeTimeZoneIfRequired(entry.getEnd(), isAllDay, removeTimezone, legacyDateFormat));
result.put("legacyTimeTo", removeTimeZoneIfRequired(entry.getEnd(), isAllDay, removeTimezone, 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;
}
use of org.alfresco.service.cmr.calendar.CalendarEntry in project alfresco-remote-api by Alfresco.
the class UserCalendarEntriesGet method executeImpl.
@Override
protected Map<String, Object> executeImpl(SiteInfo singleSite, String eventName, WebScriptRequest req, JSONObject json, Status status, Cache cache) {
// Did they restrict by date?
Date fromDate = parseDate(req.getParameter("from"));
Date toDate = parseDate(req.getParameter("to"));
// What should we do about repeating events? First or all?
boolean repeatingFirstOnly = true;
String repeatingEvents = req.getParameter("repeating");
if (repeatingEvents != null) {
if ("first".equals(repeatingEvents)) {
repeatingFirstOnly = true;
} else if ("all".equals(repeatingEvents)) {
repeatingFirstOnly = false;
}
} else {
// the format of the from date, which differs between uses!
if (fromDate != null) {
String fromDateS = req.getParameter("from");
if (fromDateS.indexOf('-') != -1) {
// Apparently this is the site calendar dashlet...
repeatingFirstOnly = true;
}
if (fromDateS.indexOf('/') != -1) {
// This is something else, wants all events in range
repeatingFirstOnly = false;
}
}
}
// One site, or all the user's ones?
List<SiteInfo> sites = new ArrayList<SiteInfo>();
if (singleSite != null) {
// Just one
sites.add(singleSite);
} else {
// All their sites (with optional limit)
int max = 0;
String strMax = req.getParameter("size");
if (strMax != null && strMax.length() != 0) {
max = Integer.parseInt(strMax);
}
sites = siteService.listSites(AuthenticationUtil.getRunAsUser(), max);
}
// We need to know the Site Names, and the NodeRefs of the calendar containers
String[] siteShortNames = new String[sites.size()];
Map<NodeRef, SiteInfo> containerLookup = new HashMap<NodeRef, SiteInfo>();
for (int i = 0; i < sites.size(); i++) {
SiteInfo site = sites.get(i);
siteShortNames[i] = site.getShortName();
try {
containerLookup.put(siteService.getContainer(site.getShortName(), CalendarServiceImpl.CALENDAR_COMPONENT), site);
} catch (AccessDeniedException e) {
// You can see the site, but not the calendar, so skip it
// This means you won't have any events in it anyway
}
}
// Get the entries for the list
PagingRequest paging = buildPagingRequest(req);
PagingResults<CalendarEntry> entries = calendarService.listCalendarEntries(siteShortNames, fromDate, toDate, paging);
boolean resortNeeded = false;
List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
for (CalendarEntry entry : entries.getPage()) {
// Build the object
Map<String, Object> result = new HashMap<String, Object>();
boolean isAllDay = CalendarEntryDTO.isAllDay(entry);
boolean removeTimezone = isAllDay && !entry.isOutlook();
result.put(RESULT_EVENT, entry);
result.put(RESULT_NAME, entry.getSystemName());
result.put(RESULT_TITLE, entry.getTitle());
result.put("description", entry.getDescription());
result.put("where", entry.getLocation());
result.put(RESULT_START, removeTimeZoneIfRequired(entry.getStart(), isAllDay, removeTimezone));
result.put(RESULT_END, removeTimeZoneIfRequired(entry.getEnd(), isAllDay, removeTimezone));
String legacyDateFormat = "yyyy-MM-dd";
String legacyTimeFormat = "HH:mm";
result.put("legacyDateFrom", removeTimeZoneIfRequired(entry.getStart(), isAllDay, removeTimezone, legacyDateFormat));
result.put("legacyTimeFrom", removeTimeZoneIfRequired(entry.getStart(), isAllDay, removeTimezone, legacyTimeFormat));
result.put("legacyDateTo", removeTimeZoneIfRequired(entry.getEnd(), isAllDay, removeTimezone, legacyDateFormat));
result.put("legacyTimeTo", removeTimeZoneIfRequired(entry.getEnd(), isAllDay, removeTimezone, legacyTimeFormat));
result.put("duration", buildDuration(entry));
result.put("tags", entry.getTags());
result.put("isoutlook", entry.isOutlook());
result.put("allday", CalendarEntryDTO.isAllDay(entry));
// Identify the site
SiteInfo site = containerLookup.get(entry.getContainerNodeRef());
result.put("site", site);
result.put("siteName", site.getShortName());
result.put("siteTitle", site.getTitle());
// Check the permissions the user has on the entry
AccessStatus canEdit = permissionService.hasPermission(entry.getNodeRef(), PermissionService.WRITE);
AccessStatus canDelete = permissionService.hasPermission(entry.getNodeRef(), PermissionService.DELETE);
result.put("canEdit", (canEdit == AccessStatus.ALLOWED));
result.put("canDelete", (canDelete == AccessStatus.ALLOWED));
// Replace nulls with blank strings for the JSON
for (String key : result.keySet()) {
if (result.get(key) == null) {
result.put(key, "");
}
}
// Save this one
results.add(result);
// Handle recurring as needed
boolean orderChanged = handleRecurring(entry, result, results, fromDate, toDate, repeatingFirstOnly);
if (orderChanged) {
resortNeeded = true;
}
}
// If the recurring events meant dates changed, re-sort
if (resortNeeded) {
Collections.sort(results, getEventDetailsSorter());
}
// All done
Map<String, Object> model = new HashMap<String, Object>();
model.put("events", results);
return model;
}
use of org.alfresco.service.cmr.calendar.CalendarEntry in project alfresco-remote-api by Alfresco.
the class CalendarEntryDelete method executeImpl.
@Override
protected Map<String, Object> executeImpl(SiteInfo site, String eventName, WebScriptRequest req, JSONObject json, Status status, Cache cache) {
CalendarEntry entry = calendarService.getCalendarEntry(site.getShortName(), eventName);
if (entry == null) {
status.setCode(Status.STATUS_NOT_FOUND);
return null;
}
// Special case for "deleting" an instance of a recurring event
if (req.getParameter("date") != null && entry.getRecurrenceRule() != null) {
// Have an ignored event generated
createIgnoreEvent(req, entry);
// Mark as ignored
status.setCode(Status.STATUS_NO_CONTENT, "Recurring entry ignored");
return null;
}
// Delete the calendar entry
calendarService.deleteCalendarEntry(entry);
// Record this in the activity feed
addActivityEntry("deleted", entry, site, req, json);
// All done
status.setCode(Status.STATUS_NO_CONTENT, "Entry deleted");
return null;
}
use of org.alfresco.service.cmr.calendar.CalendarEntry in project alfresco-remote-api by Alfresco.
the class CalendarEntryGet 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 = calendarService.getCalendarEntry(site.getShortName(), eventName);
if (entry == null) {
String message = rb.getString(MSG_EVENT_NOT_FOUND);
return buildError(MessageFormat.format(message, eventName));
}
Date date = parseDate(req.getParameter("date"));
if (date != null) {
// if some instances were updated
SimpleDateFormat fdt = new SimpleDateFormat("yyyyMMdd");
Set<QName> childNodeTypeQNames = new HashSet<QName>();
childNodeTypeQNames.add(CalendarModel.TYPE_UPDATED_EVENT);
List<ChildAssociationRef> updatedEventList = nodeService.getChildAssocs(entry.getNodeRef(), childNodeTypeQNames);
for (ChildAssociationRef updatedEvent : updatedEventList) {
NodeRef nodeRef = updatedEvent.getChildRef();
Date updatedDate = (Date) nodeService.getProperty(nodeRef, CalendarModel.PROP_UPDATED_EVENT_DATE);
if (fdt.format(updatedDate).equals(fdt.format(date))) {
entry.setStart((Date) nodeService.getProperty(nodeRef, CalendarModel.PROP_UPDATED_START));
entry.setEnd((Date) nodeService.getProperty(nodeRef, CalendarModel.PROP_UPDATED_END));
entry.setTitle((String) nodeService.getProperty(nodeRef, CalendarModel.PROP_UPDATED_WHAT));
entry.setLocation((String) nodeService.getProperty(nodeRef, CalendarModel.PROP_UPDATED_WHERE));
break;
}
}
}
// 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());
boolean isAllDay = CalendarEntryDTO.isAllDay(entry);
boolean removeTimezone = isAllDay && !entry.isOutlook();
result.put("from", removeTimeZoneIfRequired(entry.getStart(), isAllDay, removeTimezone));
result.put("to", removeTimeZoneIfRequired(entry.getEnd(), isAllDay, removeTimezone));
String legacyDateFormat = "M/d/yyyy";
String legacyTimeFormat = "HH:mm";
result.put("legacyDateFrom", removeTimeZoneIfRequired(entry.getStart(), isAllDay, removeTimezone, legacyDateFormat));
result.put("legacyTimeFrom", removeTimeZoneIfRequired(entry.getStart(), isAllDay, removeTimezone, legacyTimeFormat));
result.put("legacyDateTo", removeTimeZoneIfRequired(entry.getEnd(), isAllDay, removeTimezone, legacyDateFormat));
result.put("legacyTimeTo", removeTimeZoneIfRequired(entry.getEnd(), isAllDay, removeTimezone, legacyTimeFormat));
result.put("tags", entry.getTags());
result.put("isoutlook", entry.isOutlook());
result.put("outlookuid", entry.getOutlookUID());
result.put("allday", isAllDay);
result.put("docfolder", entry.getSharePointDocFolder());
result.put("recurrence", buildRecurrenceString(entry));
// Replace nulls with blank strings for the JSON
for (String key : result.keySet()) {
if (result.get(key) == null) {
result.put(key, "");
}
}
// Check the permissions the user has on the entry
AccessStatus canEdit = permissionService.hasPermission(entry.getNodeRef(), PermissionService.WRITE);
AccessStatus canDelete = permissionService.hasPermission(entry.getNodeRef(), PermissionService.DELETE);
result.put("canEdit", (canEdit == AccessStatus.ALLOWED));
result.put("canDelete", (canDelete == AccessStatus.ALLOWED));
// All done
Map<String, Object> model = new HashMap<String, Object>();
model.put("result", result);
return model;
}
Aggregations