Search in sources :

Example 6 with NotificationType

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

the class BwCalDAVResource method setBinaryContent.

@Override
public void setBinaryContent(final InputStream val) throws WebdavException {
    BwResource r = getRsrc();
    BwResourceContent rc = r.getContent();
    if (rc == null) {
        if (!isNew()) {
            intf.getFileContent(this);
            rc = r.getContent();
        }
        if (rc == null) {
            rc = new BwResourceContent();
            r.setContent(rc);
        }
    }
    try {
        /* If this is a notification we need to unprefix the data */
        final InputStream str;
        if (!isNotification()) {
            str = val;
        } else {
            final NotificationType note = Parser.fromXml(val);
            note.getNotification().unprefixHrefs(intf.getUrlHandler());
            str = new ByteArrayInputStream(note.toXml(true).getBytes());
        }
        final ByteArrayOutputStream outBuff = new ByteArrayOutputStream();
        byte[] inBuffer = new byte[1000];
        long clen = 0;
        int chunkSize;
        int maxSize = intf.getAuthProperties().getMaxUserEntitySize();
        long oldSize = r.getContentLength();
        while (clen <= maxSize) {
            chunkSize = str.read(inBuffer);
            if (chunkSize < 0) {
                break;
            }
            outBuff.write(inBuffer, 0, chunkSize);
            clen += chunkSize;
        }
        if (clen > maxSize) {
            throw new WebdavForbidden(CaldavTags.maxResourceSize);
        }
        rc.setValue(intf.getBlob(outBuff.toByteArray()));
        r.setContentLength(clen);
        if (!intf.updateQuota(getOwner(), clen - oldSize)) {
            throw new WebdavForbidden(WebdavTags.quotaNotExceeded);
        }
    } catch (WebdavException wde) {
        throw wde;
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BwResource(org.bedework.calfacade.BwResource) NotificationType(org.bedework.caldav.util.notifications.NotificationType) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwResourceContent(org.bedework.calfacade.BwResourceContent) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 7 with NotificationType

use of org.bedework.caldav.util.notifications.NotificationType 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 8 with NotificationType

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

the class NotificationsInfo method deleted.

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

Example 9 with NotificationType

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

the class NotificationsInfo method getNotification.

private static NotificationType getNotification() {
    NotificationType note = new NotificationType();
    note.setDtstamp(DateTimeUtil.rfcDateTime());
    return note;
}
Also used : NotificationType(org.bedework.caldav.util.notifications.NotificationType)

Example 10 with NotificationType

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

the class NotificationsInfo method added.

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

Aggregations

NotificationType (org.bedework.caldav.util.notifications.NotificationType)14 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)6 InviteNotificationType (org.bedework.caldav.util.sharing.InviteNotificationType)4 DateTime (net.fortuna.ical4j.model.DateTime)3 DtStamp (net.fortuna.ical4j.model.property.DtStamp)3 BaseNotificationType (org.bedework.caldav.util.notifications.BaseNotificationType)3 AdminNotificationType (org.bedework.caldav.util.notifications.admin.AdminNotificationType)3 ApprovalResponseNotificationType (org.bedework.caldav.util.notifications.admin.ApprovalResponseNotificationType)3 AwaitingApprovalNotificationType (org.bedework.caldav.util.notifications.admin.AwaitingApprovalNotificationType)3 SuggestBaseNotificationType (org.bedework.caldav.util.notifications.suggest.SuggestBaseNotificationType)3 SuggestNotificationType (org.bedework.caldav.util.notifications.suggest.SuggestNotificationType)3 SuggestResponseNotificationType (org.bedework.caldav.util.notifications.suggest.SuggestResponseNotificationType)3 InviteType (org.bedework.caldav.util.sharing.InviteType)3 UserType (org.bedework.caldav.util.sharing.UserType)3 BwCalendar (org.bedework.calfacade.BwCalendar)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 QName (javax.xml.namespace.QName)2 ResourceChangeType (org.bedework.caldav.util.notifications.ResourceChangeType)2 InviteReplyType (org.bedework.caldav.util.sharing.InviteReplyType)2