mam-dev / cosmo

Cosmo Calendar Server implements the server side of the CalDAV protocol.
Apache License 2.0
79 stars 45 forks source link

incoming event interception via EventAddHandler #89

Open f1-outsourcing opened 3 weeks ago

f1-outsourcing commented 3 weeks ago

Hi @danielgrigore Daniel I am not sure if you read these old posts[1].

We implemented incoming event interception via EventAddHandler. We intercept it in beforeAdd. The wveint is successfully intercepted - we can see it in log. But when we try to update the description of event - it does not change. Why? Or is this successfully changed in the server, but just not synced to the client?

public boolean handleCalendarEvent(CollectionItem collection, ContentItem item) {
    // Get event
    EventStamp eventStamp = StampUtils.getEventStamp(item);
    VEvent masterEvent = eventStamp.getMasterEvent();
    if (isValidManagementEvent(masterEvent)) {
        boolean success = processEvent(masterEvent);
        if (success) {
            // TODO
            item.addStamp(eventStamp);
        }
        return success;
    } else {
        return false;
    }
}

private boolean processEvent(VEvent event) {
    // Based on the event's SUMMARY, process the management command
    String summary = event.getSummary().getValue().trim();
    switch (summary) {
        case COMMAND:
            // Process sharing read permissions
            LOG.info("Processing event");
            java.util.Calendar calendar = java.util.Calendar.getInstance();
            SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            try {
                event.getProperty(Property.DESCRIPTION).setValue("======= update (" + format.format(calendar.getTime()) + ") =======");
            } catch (Exception e) {
                LOG.error(e.toString());
                return false;
            }
            break;

[1] https://github.com/mam-dev/cosmo/issues/84

f1-outsourcing commented 7 hours ago

@danielgrigore are you still here?