Search in sources :

Example 11 with ChangeTable

use of org.bedework.calfacade.util.ChangeTable in project bw-calendar-engine by Bedework.

the class Events method checkChanges.

@SuppressWarnings("unchecked")
private boolean checkChanges(final EventInfo ei, final boolean organizerSchedulingObject, final boolean attendeeSchedulingObject) throws CalFacadeException {
    final UpdateResult updResult = ei.getUpdResult();
    if (ei.getChangeset(getPrincipalHref()).isEmpty()) {
        // Forced update?
        updResult.hasChanged = true;
        if (attendeeSchedulingObject) {
            // Attendee replying?
            /* XXX We should really check to see if the value changed here -
         */
            updResult.reply = true;
        }
        return true;
    }
    if (debug) {
        ei.getChangeset(getPrincipalHref()).dumpEntries();
    }
    final ChangeTable ct = ei.getChangeset(getPrincipalHref());
    final Collection<ChangeTableEntry> ctes = ct.getEntries();
    updResult.sequenceChange = ct.getSequenceChangeNeeded();
    for (final ChangeTableEntry cte : ctes) {
        if (!cte.getChanged()) {
            continue;
        }
        updResult.hasChanged = true;
        final PropertyInfoIndex pi = cte.getIndex();
        if (!organizerSchedulingObject && pi.equals(PropertyInfoIndex.ORGANIZER)) {
            final BwOrganizer oldOrg = (BwOrganizer) cte.getOldVal();
            final BwOrganizer newOrg = (BwOrganizer) cte.getNewVal();
            if ((oldOrg == null) || (newOrg == null) || !oldOrg.getOrganizerUri().equals(newOrg.getOrganizerUri())) {
                // Never valid
                throw new CalFacadeForbidden(CaldavTags.attendeeAllowed, "Cannot change organizer");
            }
        }
        if (pi.equals(PropertyInfoIndex.ATTENDEE) || pi.equals(PropertyInfoIndex.VOTER)) {
            updResult.addedAttendees = cte.getAddedValues();
            updResult.deletedAttendees = cte.getRemovedValues();
            if (attendeeSchedulingObject) {
                // Attendee replying?
                /* XXX We should really check to see if the value changed here -
           */
                updResult.reply = true;
            } else {
                if (!Util.isEmpty(updResult.deletedAttendees)) {
                    // Bump sequence as we are sending out cancels
                    updResult.sequenceChange = true;
                }
            }
        }
        if (pi.equals(PropertyInfoIndex.POLL_WINNER)) {
            if (!attendeeSchedulingObject) {
                // Attendee replying?
                /* XXX We should really check to see if the value changed here -
           */
                updResult.pollWinner = ei.getEvent().getPollWinner();
            }
        }
        if (pi.equals(PropertyInfoIndex.POLL_ITEM)) {
            if (attendeeSchedulingObject) {
                // Attendee replying?
                /* XXX We should really check to see if the value changed here -
           */
                updResult.reply = true;
            }
        }
        if (organizerSchedulingObject) {
            final BwIcalPropertyInfoEntry pie = BwIcalPropertyInfo.getPinfo(cte.getIndex());
            if (pie.getReschedule()) {
                updResult.doReschedule = true;
            }
        }
    }
    return updResult.hasChanged;
}
Also used : PropertyInfoIndex(org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex) BwIcalPropertyInfoEntry(org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry) ChangeTable(org.bedework.calfacade.util.ChangeTable) CalFacadeForbidden(org.bedework.calfacade.exc.CalFacadeForbidden) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) UpdateResult(org.bedework.calfacade.svc.EventInfo.UpdateResult) BwOrganizer(org.bedework.calfacade.BwOrganizer)

Example 12 with ChangeTable

use of org.bedework.calfacade.util.ChangeTable in project bw-calendar-engine by Bedework.

the class Events method doCats.

private void doCats(final RealiasResult resp, final String colHref, final BwEvent ev) {
    try {
        final Set<BwCategory> cats = getCols().getCategorySet(colHref);
        if (Util.isEmpty(cats)) {
            return;
        }
        resp.getCats().addAll(cats);
        for (final BwCategory cat : cats) {
            if (ev.addCategory(cat)) {
                final ChangeTable changes = ev.getChangeset(getPrincipalHref());
                final ChangeTableEntry cte = changes.getEntry(PropertyInfoIndex.CATEGORIES);
                cte.addAddedValue(cat);
            }
        }
    } catch (final Throwable t) {
        Response.error(new RealiasResult(null), t.getMessage());
    }
}
Also used : ChangeTable(org.bedework.calfacade.util.ChangeTable) BwCategory(org.bedework.calfacade.BwCategory) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry)

Example 13 with ChangeTable

use of org.bedework.calfacade.util.ChangeTable in project bw-calendar-engine by Bedework.

the class EventInfo method getDeletedOverrideProxies.

/**
 * @param userHref
 * @return Collection of deleted override proxy events or null
 * @throws CalFacadeException
 */
public Collection<BwEventProxy> getDeletedOverrideProxies(final String userHref) throws CalFacadeException {
    TreeSet<BwEventProxy> proxies = new TreeSet<>();
    if ((retrievedOverrides == null) || instanceOnly) {
        return proxies;
    }
    for (EventOverride eo : retrievedOverrides) {
        if (overrides.contains(eo)) {
            continue;
        }
        BwEventProxy proxy = (BwEventProxy) eo.getEvent();
        if (proxy.getRef().unsaved()) {
            throw new RuntimeException("Unsaved override in delete list");
        }
        if (proxy.getXproperty(BwXproperty.peruserInstance) == null) {
            /* Not peruser - remove it. */
            proxies.add(proxy);
            continue;
        }
        BwXproperty pu = proxy.findPeruserXprop(userHref, BwXproperty.peruserPropTransp);
        if (pu != null) {
            /* remove it */
            proxy.removeXproperty(pu);
        }
        /* Remove any alarm(s) */
        List<BwAlarm> toRemove = new ArrayList<>();
        for (BwAlarm a : proxy.getAlarms()) {
            if (a.getOwnerHref().equals(userHref)) {
                toRemove.add(a);
            }
        }
        for (BwAlarm a : toRemove) {
            proxy.removeAlarm(a);
        }
        if (Util.isEmpty(proxy.getXproperties(BwXproperty.peruserPropTransp)) && Util.isEmpty(proxy.getAlarms())) {
            /* No more peruser data - add to remove list */
            proxies.add(proxy);
        }
        /* Update the changes */
        ChangeTable chg = getChangeset(userHref);
        if (pu != null) {
            chg.addValue(PropertyInfoIndex.XPROP, pu);
        }
        if (!Util.isEmpty(toRemove)) {
            for (BwAlarm a : toRemove) {
                chg.addValue(PropertyInfoIndex.VALARM, a);
            }
        }
    }
    return proxies;
}
Also used : BwXproperty(org.bedework.calfacade.BwXproperty) TreeSet(java.util.TreeSet) ChangeTable(org.bedework.calfacade.util.ChangeTable) ArrayList(java.util.ArrayList) BwEventProxy(org.bedework.calfacade.BwEventProxy) BwAlarm(org.bedework.calfacade.BwAlarm)

Example 14 with ChangeTable

use of org.bedework.calfacade.util.ChangeTable in project bw-calendar-engine by Bedework.

the class InProcessor method pendingToInbox.

/**
 * Update the inbox according to it's owners wishes (what if owner and proxy
 * have different wishes)
 *
 * @param ei - the pending inbox event
 * @param inboxOwnerHref href of
 * @param attendeeAccepting - is this the result of a REPLY with PARTSTAT accept?
 * @param forceDelete - it's inbox noise, delete it
 * @throws CalFacadeException
 */
public void pendingToInbox(final EventInfo ei, final String inboxOwnerHref, final boolean attendeeAccepting, final boolean forceDelete) throws CalFacadeException {
    boolean delete = forceDelete;
    if (!delete) {
        final BwPrincipal principal = getSvc().getUsersHandler().getPrincipal(inboxOwnerHref);
        if (principal == null) {
            delete = true;
        } else {
            final BwPreferences prefs = getSvc().getPrefsHandler().get(principal);
            final int sapr = prefs.getScheduleAutoProcessResponses();
            if (sapr == BwPreferences.scheduleAutoProcessResponsesNoNotify) {
                delete = true;
            } else if (sapr == BwPreferences.scheduleAutoProcessResponsesNoAcceptNotify) {
                delete = attendeeAccepting;
            }
        }
    }
    final BwEvent ev = ei.getEvent();
    final boolean vpoll = ev.getEntityType() == IcalDefs.entityTypeVpoll;
    if (delete) {
        getSvc().getEventsHandler().delete(ei, false);
    } else {
        final BwCalendar inbox = getSvc().getCalendarsHandler().getSpecial(BwCalendar.calTypeInbox, false);
        if (inbox == null) {
            return;
        }
        // if (vpoll) {
        /* Delete other notifications for the same event
         * NOTE: DON'T for non-vpoll - this was deleting changes that had to
         * be processed. Still an opportunity to improve this though.
         */
        final Collection<EventInfo> inevs = getEventsByUid(inbox.getPath(), ev.getUid());
        for (final EventInfo inei : inevs) {
            final BwEvent inev = inei.getEvent();
            if (inev.getScheduleState() != BwEvent.scheduleStateProcessed) {
                continue;
            }
            if (debug) {
                trace("delete earlier? event from inbox: " + inev.getName());
            }
            deleteEvent(inei, true, false);
        }
        if (debug) {
            trace("set event to scheduleStateProcessed: " + ev.getName());
        }
        final ChangeTable chg = ei.getChangeset(inboxOwnerHref);
        chg.changed(PropertyIndex.PropertyInfoIndex.SCHEDULE_STATE, ev.getScheduleState(), BwEvent.scheduleStateProcessed);
        ev.setScheduleState(BwEvent.scheduleStateProcessed);
        chg.changed(PropertyIndex.PropertyInfoIndex.COLPATH, ev.getColPath(), inbox.getPath());
        ev.setColPath(inbox.getPath());
        getSvc().getEventsHandler().update(ei, true, null);
    }
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) BwPreferences(org.bedework.calfacade.svc.BwPreferences) EventInfo(org.bedework.calfacade.svc.EventInfo) ChangeTable(org.bedework.calfacade.util.ChangeTable) BwEvent(org.bedework.calfacade.BwEvent) BwCalendar(org.bedework.calfacade.BwCalendar)

Example 15 with ChangeTable

use of org.bedework.calfacade.util.ChangeTable in project bw-calendar-engine by Bedework.

the class InRequest method updateAttendeePollCopy.

private boolean updateAttendeePollCopy(final EventInfo ourCopy, final EventInfo inCopy, final String attUri) throws CalFacadeException {
    try {
        final BwEvent ourEv = ourCopy.getEvent();
        final BwEvent inEv = inCopy.getEvent();
        final boolean statusUpdate;
        if (inEv.getScheduleMethod() == ScheduleMethods.methodTypeRequest) {
            if (debug) {
                trace("Update the poll common fields");
            }
            if (!updateAttendeeFields(ourCopy, inCopy, attUri)) {
                return false;
            }
            statusUpdate = false;
        } else if (inEv.getScheduleMethod() != ScheduleMethods.methodTypePollStatus) {
            if (debug) {
                debug("Bad method " + inEv.getScheduleMethod());
            }
            return false;
        } else {
            statusUpdate = true;
        }
        // Now update the vpoll items.
        final ChangeTable chg = ourCopy.getChangeset(getPrincipalHref());
        chg.changed(PropertyInfoIndex.STATUS, ourEv.getStatus(), inEv.getStatus());
        ourEv.setStatus(inEv.getStatus());
        final Integer pw = inEv.getPollWinner();
        if (pw != null) {
            chg.changed(PropertyInfoIndex.POLL_WINNER, ourEv.getPollWinner(), inEv.getPollWinner());
            ourEv.setPollWinner(pw);
        }
        ourEv.clearVvoters();
        for (final String s : inEv.getVvoters()) {
            ourEv.addVvoter(s);
            chg.addValue(PropertyInfoIndex.VVOTER, s);
        }
        if (!statusUpdate) {
            ourEv.clearPollItems();
            for (final String s : inEv.getPollItems()) {
                ourEv.addPollItem(s);
                chg.addValue(PropertyInfoIndex.POLL_ITEM, s);
            }
        }
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
    return true;
}
Also used : ChangeTable(org.bedework.calfacade.util.ChangeTable) BwEvent(org.bedework.calfacade.BwEvent) BwString(org.bedework.calfacade.BwString) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

ChangeTable (org.bedework.calfacade.util.ChangeTable)15 BwEvent (org.bedework.calfacade.BwEvent)10 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)7 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)7 BwDateTime (org.bedework.calfacade.BwDateTime)6 EventInfo (org.bedework.calfacade.svc.EventInfo)5 PropertyInfoIndex (org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex)5 Date (net.fortuna.ical4j.model.Date)4 DtStart (net.fortuna.ical4j.model.property.DtStart)4 BwAttendee (org.bedework.calfacade.BwAttendee)4 BwOrganizer (org.bedework.calfacade.BwOrganizer)4 BwXproperty (org.bedework.calfacade.BwXproperty)4 Dur (net.fortuna.ical4j.model.Dur)3 Period (net.fortuna.ical4j.model.Period)3 PropertyList (net.fortuna.ical4j.model.PropertyList)3 DtEnd (net.fortuna.ical4j.model.property.DtEnd)3 BwCategory (org.bedework.calfacade.BwCategory)3 BwEventProxy (org.bedework.calfacade.BwEventProxy)3 Iterator (java.util.Iterator)2 TreeSet (java.util.TreeSet)2