Search in sources :

Example 1 with ResourceChangeType

use of org.bedework.caldav.util.notifications.ResourceChangeType in project bw-calendar-engine by Bedework.

the class NotificationsInfo method updated.

/**
 * @param currentAuth
 * @param ev
 * @return Info for single updated event.
 * @throws CalFacadeException
 */
public static String updated(final String currentAuth, final BwEvent ev) throws CalFacadeException {
    ResourceChangeType rc = getUpdated(currentAuth, ev);
    if (rc == null) {
        return null;
    }
    NotificationType note = getNotification();
    note.setNotification(rc);
    try {
        return note.toXml(true);
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : ResourceChangeType(org.bedework.caldav.util.notifications.ResourceChangeType) NotificationType(org.bedework.caldav.util.notifications.NotificationType) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 2 with ResourceChangeType

use of org.bedework.caldav.util.notifications.ResourceChangeType in project bw-calendar-engine by Bedework.

the class NotificationsInfo method getDeleted.

/**
 * Call for a deleted event
 *
 * @param currentAuth
 * @param ev
 * @return resource deleted notification.
 * @throws CalFacadeException
 */
public static ResourceChangeType getDeleted(final String currentAuth, final BwEvent ev) throws CalFacadeException {
    try {
        ResourceChangeType rc = new ResourceChangeType();
        DeletedType del = new DeletedType();
        del.setHref(getHref(ev));
        del.setChangedBy(getChangedBy(currentAuth));
        DeletedDetailsType dd = new DeletedDetailsType();
        dd.setDeletedComponent(getType(ev));
        dd.setDeletedSummary(ev.getSummary());
        if (ev.isRecurringEntity()) {
        // TODO: Set these correctly.
        // dd.setDeletedNextInstance(val);
        // dd.setDeletedNextInstanceTzid(val);
        // dd.setDeletedHadMoreInstances(val);
        }
        if (ev.getDtstart() != null) {
            ChangedPropertyType start = new ChangedPropertyType();
            start.setName(PropertyInfoIndex.DTSTART.name());
            start.setDataFrom(String.valueOf(ev.getDtstart()));
            dd.getDeletedProps().add(start);
        }
        if (ev.getDtend() != null) {
            ChangedPropertyType end = new ChangedPropertyType();
            end.setName(PropertyInfoIndex.DTEND.name());
            end.setDataFrom(String.valueOf(ev.getDtend()));
            dd.getDeletedProps().add(end);
        }
        if (ev.getDuration() != null && !ev.getDuration().isEmpty()) {
            ChangedPropertyType dur = new ChangedPropertyType();
            dur.setName(PropertyInfoIndex.DURATION.name());
            dur.setDataFrom(ev.getDuration());
            dd.getDeletedProps().add(dur);
        }
        if (ev.getLocation() != null) {
            ChangedPropertyType loc = new ChangedPropertyType();
            loc.setName(PropertyInfoIndex.LOCATION.name());
            loc.setDataFrom(ev.getLocation().getAddress().getValue());
            dd.getDeletedProps().add(loc);
        }
        if (ev.getDescription() != null) {
            ChangedPropertyType desc = new ChangedPropertyType();
            desc.setName(PropertyInfoIndex.DESCRIPTION.name());
            desc.setDataFrom(ev.getDescription());
            dd.getDeletedProps().add(desc);
        }
        del.setDeletedDetails(dd);
        rc.setDeleted(del);
        return rc;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : ResourceChangeType(org.bedework.caldav.util.notifications.ResourceChangeType) ChangedPropertyType(org.bedework.caldav.util.notifications.ChangedPropertyType) DeletedType(org.bedework.caldav.util.notifications.DeletedType) DeletedDetailsType(org.bedework.caldav.util.notifications.DeletedDetailsType) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 3 with ResourceChangeType

use of org.bedework.caldav.util.notifications.ResourceChangeType in project bw-calendar-engine by Bedework.

the class Notifier method processAliasInfo.

private boolean processAliasInfo(final AliasesInfo ai, final String authHref, final ResourceChangeType rc) throws CalFacadeException {
    /* We have to notify the sharee of the change. We do not notify the
       * sharee that made the change.
       */
    final String shareeHref = ai.getPrincipalHref();
    if (shareeHref.equals(authHref) || !ai.getVisible()) {
        // This sharee made the change or the event is not visible to this alias. Do not notify, but process other aliases.
        return checkAliases(ai, authHref, rc);
    }
    boolean processed = false;
    // We need this a lot
    final String colHref = ai.getCollection().getPath();
    // We need to push if this is not the current user
    final boolean doPushPrincipal = !shareeHref.equals(getPrincipalHref());
    try {
        if (doPushPrincipal) {
            pushPrincipal(shareeHref);
        }
        if (debug) {
            trace("Change notification for principal " + shareeHref + " and href " + colHref);
        }
        final BwPreferences p = getSvc().getPrefsHandler().get();
        if ((p != null) && (p.getNoNotifications())) {
            if (debug) {
                trace("Notification for principal " + shareeHref + " is suppressed");
            }
            return checkAliases(ai, authHref, rc);
        }
        /* See if we have any notifications for this entity referenced
       * by the href for the current alias
       *
       */
        NotificationType storedNote = null;
        final String resourceHref = Util.buildPath(false, colHref, "/", ai.getEntityName());
        for (final NotificationType n : getNotes().getMatching(AppleServerTags.resourceChange)) {
            final BaseNotificationType bnt = n.getNotification();
            if (!(bnt instanceof ResourceChangeType)) {
                // Don't know what to do with that
                continue;
            }
            // SCHEMA: encoding is the base 64 encoded href
            if (((ResourceChangeType) bnt).sameHref(resourceHref)) {
                storedNote = n;
                break;
            }
        }
        process: {
            if (storedNote == null) {
                // Choice 1 - Just save a copy of this one with our href
                final ResourceChangeType rcCopy = rc.copyForAlias(colHref);
                rcCopy.setHref(resourceHref);
                final NotificationType note = new NotificationType();
                note.setNotification(rcCopy);
                note.setName(getEncodedUuid());
                getNotes().add(note);
                processed = true;
                break process;
            }
            final ResourceChangeType storedRc = (ResourceChangeType) storedNote.getNotification();
            if (rc.getCreated() != null) {
                // Choice 2 above - update the old one
                storedRc.setCollectionChanges(null);
                storedRc.setDeleted(null);
                storedRc.setCreated(rc.getCreated().copyForAlias(colHref));
                getNotes().update(storedNote);
                processed = true;
                break process;
            }
            if (rc.getDeleted() != null) {
                if (storedRc.getCreated() != null) {
                    // Choice 3 above - discard both
                    getNotes().remove(storedNote);
                    processed = true;
                    break process;
                }
                // Choice 4 above - discard updates
                storedRc.setCollectionChanges(null);
                storedRc.setDeleted(rc.getDeleted().copyForAlias(colHref));
                storedRc.clearUpdated();
                getNotes().update(storedNote);
                processed = true;
                break process;
            }
            if (storedRc.getCreated() != null) {
                // Choice 5 above - discard new updates
                break process;
            }
            if (!Util.isEmpty(rc.getUpdated())) {
                // Choices 6 and 7 above
                storedRc.setDeleted(null);
                storedRc.setCreated(null);
                storedRc.setCollectionChanges(null);
                for (final UpdatedType u : rc.getUpdated()) {
                    storedRc.addUpdate(u.copyForAlias(colHref));
                }
                getNotes().update(storedNote);
                processed = true;
            }
        }
    // process:
    } finally {
        if (doPushPrincipal) {
            popPrincipal();
        }
    }
    if (checkAliases(ai, authHref, rc)) {
        processed = true;
    }
    return processed;
}
Also used : BaseNotificationType(org.bedework.caldav.util.notifications.BaseNotificationType) SuggestBaseNotificationType(org.bedework.caldav.util.notifications.suggest.SuggestBaseNotificationType) BwPreferences(org.bedework.calfacade.svc.BwPreferences) ResourceChangeType(org.bedework.caldav.util.notifications.ResourceChangeType) UpdatedType(org.bedework.caldav.util.notifications.UpdatedType) AdminNotificationType(org.bedework.caldav.util.notifications.admin.AdminNotificationType) BaseNotificationType(org.bedework.caldav.util.notifications.BaseNotificationType) SuggestResponseNotificationType(org.bedework.caldav.util.notifications.suggest.SuggestResponseNotificationType) NotificationType(org.bedework.caldav.util.notifications.NotificationType) ApprovalResponseNotificationType(org.bedework.caldav.util.notifications.admin.ApprovalResponseNotificationType) SuggestNotificationType(org.bedework.caldav.util.notifications.suggest.SuggestNotificationType) AwaitingApprovalNotificationType(org.bedework.caldav.util.notifications.admin.AwaitingApprovalNotificationType) SuggestBaseNotificationType(org.bedework.caldav.util.notifications.suggest.SuggestBaseNotificationType)

Example 4 with ResourceChangeType

use of org.bedework.caldav.util.notifications.ResourceChangeType in project bw-calendar-engine by Bedework.

the class Notifier method doChangeNotification.

private ProcessMessageResult doChangeNotification(final OwnedHrefEvent msg, final NotificationType note) throws CalFacadeException {
    try {
        getSvci(msg.getOwnerHref());
        // Normalized
        final String ownerHref = getPrincipalHref();
        final String href = msg.getHref();
        if (debug) {
            trace(msg.toString());
            trace("Notification for entity " + href + " owner principal " + ownerHref);
        }
        final String[] split = Util.splitName(href);
        final AliasesInfo ai = getCols().getAliasesInfo(split[0], split[1]);
        if (ai == null) {
            // path pointing to non-existent collection
            return ProcessMessageResult.PROCESSED;
        }
        if (!ai.getShared()) {
            return ProcessMessageResult.PROCESSED;
        }
        if (!(note.getNotification() instanceof ResourceChangeType)) {
            // Don't know what to do with that
            return ProcessMessageResult.PROCESSED;
        }
        final ResourceChangeType rc = (ResourceChangeType) note.getNotification();
        // SCHEMA - encoding is the base64 encoded name
        if (rc.getEncoding() == null) {
            // No changes were added
            return ProcessMessageResult.PROCESSED;
        }
        if (processAliasInfo(ai, msg.getAuthPrincipalHref(), rc)) {
            return ProcessMessageResult.PROCESSED;
        }
        return ProcessMessageResult.IGNORED;
    } finally {
        closeSvci(getSvc());
    }
}
Also used : AliasesInfo(org.bedework.calfacade.AliasesInfo) ResourceChangeType(org.bedework.caldav.util.notifications.ResourceChangeType)

Example 5 with ResourceChangeType

use of org.bedework.caldav.util.notifications.ResourceChangeType in project bw-calendar-engine by Bedework.

the class NotificationsInfo method getUpdated.

/**
 * Call for an updated event.
 *
 * @param currentAuth
 * @param ev
 * @return resource updated notification.
 * @throws CalFacadeException
 */
public static ResourceChangeType getUpdated(final String currentAuth, final BwEvent ev) throws CalFacadeException {
    try {
        ChangeTable changes = ev.getChangeset(currentAuth);
        if (changes.isEmpty()) {
            return null;
        }
        ResourceChangeType rc = new ResourceChangeType();
        UpdatedType upd = new UpdatedType();
        upd.setHref(getHref(ev));
        upd.setChangedBy(getChangedBy(currentAuth));
        upd.getCalendarChanges().add(instanceChanges(currentAuth, ev));
        rc.addUpdate(upd);
        return rc;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : ResourceChangeType(org.bedework.caldav.util.notifications.ResourceChangeType) UpdatedType(org.bedework.caldav.util.notifications.UpdatedType) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

ResourceChangeType (org.bedework.caldav.util.notifications.ResourceChangeType)6 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)4 NotificationType (org.bedework.caldav.util.notifications.NotificationType)2 UpdatedType (org.bedework.caldav.util.notifications.UpdatedType)2 BaseNotificationType (org.bedework.caldav.util.notifications.BaseNotificationType)1 ChangedPropertyType (org.bedework.caldav.util.notifications.ChangedPropertyType)1 CreatedType (org.bedework.caldav.util.notifications.CreatedType)1 DeletedDetailsType (org.bedework.caldav.util.notifications.DeletedDetailsType)1 DeletedType (org.bedework.caldav.util.notifications.DeletedType)1 AdminNotificationType (org.bedework.caldav.util.notifications.admin.AdminNotificationType)1 ApprovalResponseNotificationType (org.bedework.caldav.util.notifications.admin.ApprovalResponseNotificationType)1 AwaitingApprovalNotificationType (org.bedework.caldav.util.notifications.admin.AwaitingApprovalNotificationType)1 SuggestBaseNotificationType (org.bedework.caldav.util.notifications.suggest.SuggestBaseNotificationType)1 SuggestNotificationType (org.bedework.caldav.util.notifications.suggest.SuggestNotificationType)1 SuggestResponseNotificationType (org.bedework.caldav.util.notifications.suggest.SuggestResponseNotificationType)1 AliasesInfo (org.bedework.calfacade.AliasesInfo)1 BwPreferences (org.bedework.calfacade.svc.BwPreferences)1