Search in sources :

Example 6 with CalendarEntry

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;
}
Also used : CalendarEntryDTO(org.alfresco.service.cmr.calendar.CalendarEntryDTO) StringTokenizer(java.util.StringTokenizer) CalendarEntry(org.alfresco.service.cmr.calendar.CalendarEntry) HashMap(java.util.HashMap) JSONException(org.json.JSONException) ResourceBundle(java.util.ResourceBundle) JSONObject(org.json.simple.JSONObject)

Aggregations

CalendarEntry (org.alfresco.service.cmr.calendar.CalendarEntry)6 HashMap (java.util.HashMap)5 JSONObject (org.json.simple.JSONObject)5 Date (java.util.Date)3 ResourceBundle (java.util.ResourceBundle)3 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 StringTokenizer (java.util.StringTokenizer)2 PagingRequest (org.alfresco.query.PagingRequest)2 CalendarEntryDTO (org.alfresco.service.cmr.calendar.CalendarEntryDTO)2 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 AccessStatus (org.alfresco.service.cmr.security.AccessStatus)2 JSONException (org.json.JSONException)2 HashSet (java.util.HashSet)1 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)1 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)1 QName (org.alfresco.service.namespace.QName)1