Search in sources :

Example 16 with BwOrganizer

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

the class VFreeUtil method toVFreeBusy.

/**
 * Make a VFreeBusy object from a BwFreeBusy.
 */
/**
 * @param val
 * @return VFreeBusy
 * @throws CalFacadeException
 */
public static VFreeBusy toVFreeBusy(final BwEvent val) throws CalFacadeException {
    try {
        VFreeBusy vfb = new VFreeBusy(IcalUtil.makeDateTime(val.getDtstart()), IcalUtil.makeDateTime(val.getDtend()));
        PropertyList pl = vfb.getProperties();
        Property prop;
        /* ------------------- Attendees -------------------- */
        if (val.getNumAttendees() > 0) {
            for (BwAttendee att : val.getAttendees()) {
                pl.add(setAttendee(att));
            }
        }
        if (val.getNumComments() > 0) {
            for (BwString str : val.getComments()) {
                // LANG
                pl.add(new Comment(str.getValue()));
            }
        }
        if (val.getDtstamp() != null) {
            DtStamp dts = (DtStamp) pl.getProperty(Property.DTSTAMP);
            if (dts == null) {
                prop = new DtStamp(new DateTime(val.getDtstamp()));
                // if (pars.includeDateTimeProperty) {
                // prop.getParameters().add(Value.DATE_TIME);
                // }
                pl.add(prop);
            } else {
                dts.setDateTime(new DateTime(val.getDtstamp()));
            }
        }
        /* ------------------- freebusy -------------------- */
        Collection<BwFreeBusyComponent> times = val.getFreeBusyPeriods();
        if (times != null) {
            for (BwFreeBusyComponent fbc : times) {
                FreeBusy fb = new FreeBusy();
                int type = fbc.getType();
                if (type == BwFreeBusyComponent.typeBusy) {
                    addParameter(fb, FbType.BUSY);
                } else if (type == BwFreeBusyComponent.typeFree) {
                    addParameter(fb, FbType.FREE);
                } else if (type == BwFreeBusyComponent.typeBusyUnavailable) {
                    addParameter(fb, FbType.BUSY_UNAVAILABLE);
                } else if (type == BwFreeBusyComponent.typeBusyTentative) {
                    addParameter(fb, FbType.BUSY_TENTATIVE);
                } else {
                    throw new CalFacadeException("Bad free-busy type " + type);
                }
                PeriodList pdl = fb.getPeriods();
                for (Period p : fbc.getPeriods()) {
                    // XXX inverse.ca plugin cannot handle durations.
                    Period np = new Period(p.getStart(), p.getEnd());
                    pdl.add(np);
                }
                pl.add(fb);
            }
        }
        /* ------------------- Organizer -------------------- */
        BwOrganizer org = val.getOrganizer();
        if (org != null) {
            pl.add(setOrganizer(org));
        }
        if (val.getUid() != null) {
            pl.add(new Uid(val.getUid()));
        }
        return vfb;
    } catch (CalFacadeException cfe) {
        throw cfe;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : Comment(net.fortuna.ical4j.model.property.Comment) BwFreeBusyComponent(org.bedework.calfacade.BwFreeBusyComponent) VFreeBusy(net.fortuna.ical4j.model.component.VFreeBusy) FreeBusy(net.fortuna.ical4j.model.property.FreeBusy) VFreeBusy(net.fortuna.ical4j.model.component.VFreeBusy) PeriodList(net.fortuna.ical4j.model.PeriodList) Period(net.fortuna.ical4j.model.Period) BwString(org.bedework.calfacade.BwString) DateTime(net.fortuna.ical4j.model.DateTime) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) Uid(net.fortuna.ical4j.model.property.Uid) DtStamp(net.fortuna.ical4j.model.property.DtStamp) PropertyList(net.fortuna.ical4j.model.PropertyList) Property(net.fortuna.ical4j.model.Property) BwAttendee(org.bedework.calfacade.BwAttendee) BwOrganizer(org.bedework.calfacade.BwOrganizer)

Example 17 with BwOrganizer

use of org.bedework.calfacade.BwOrganizer 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 18 with BwOrganizer

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

the class InRequest method autoRespond.

/* ====================================================================
                      Private methods
     ==================================================================== */
private boolean autoRespond(final CalSvcI svci, final EventInfo ourCopy, final EventInfo inboxEi, final boolean doubleBookOk, final String uri) throws CalFacadeException {
    BwEvent inboxEv = inboxEi.getEvent();
    String owner = inboxEv.getOwnerHref();
    if (ourCopy == null) {
        // Error - deleted while we did this?
        if (debug) {
            trace("InSchedule - no event for auto respond for " + owner);
        }
        return false;
    }
    BwOrganizer org = new BwOrganizer();
    org.setOrganizerUri(uri);
    BwAttendee att = null;
    BwEvent ourEvent = ourCopy.getEvent();
    String now = DateTimeUtil.isoDateTimeUTC(new Date());
    if (!ourEvent.getRecurring()) {
        if (ourEvent.getDtend().getDate().compareTo(now) < 0) {
            return false;
        }
        att = ourEvent.findAttendee(uri);
        if (att == null) {
            // Error?
            if (debug) {
                trace("InSchedule - no attendee on our copy for auto respond for " + owner);
            }
            return false;
        }
        if (debug) {
            trace("send response event for " + owner + " " + inboxEv.getName());
        }
        // We're about to reply.
        att.setRsvp(false);
        String partStat = IcalDefs.partstatValAccepted;
        ourEvent.removeXproperties(BwXproperty.appleNeedsReply);
        if (!doubleBookOk) {
            // See if there are any events booked during this time.
            if (checkBusy(svci, ourEvent.getUid(), inboxEv.getDtstart(), inboxEv.getDtend(), org, inboxEv.getUid())) {
                partStat = IcalDefs.partstatValDeclined;
            } else {
                ourEvent.setTransparency(IcalDefs.transparencyOpaque);
            }
        }
        ourEvent.setScheduleMethod(ScheduleMethods.methodTypeReply);
        att = (BwAttendee) att.clone();
        ourEvent.removeAttendee(att);
        ourEvent.addAttendee(att);
        att.setPartstat(partStat);
        return true;
    }
    // Recurring event - do the above per recurrence
    AuthProperties authpars = svci.getAuthProperties();
    int maxYears = authpars.getMaxYears();
    int maxInstances = authpars.getMaxInstances();
    Collection<Recurrence> recurrences = RecurUtil.getRecurrences(inboxEi, maxYears, maxInstances, now, null);
    if (Util.isEmpty(recurrences)) {
        return false;
    }
    if (debug) {
        trace("autoRespond: " + recurrences.size() + " instances");
    }
    /* Assume accept and then override with declines - assuming we're in the
     * master
     */
    ourEvent.removeXproperties(BwXproperty.appleNeedsReply);
    boolean masterSupressed = true;
    if (!inboxEv.getSuppressed()) {
        masterSupressed = false;
        att = ourEvent.findAttendee(uri);
        if (att != null) {
            // It should never be null
            att.setRsvp(false);
            att.setPartstat(IcalDefs.partstatValAccepted);
        }
        ourEvent.setTransparency(IcalDefs.transparencyOpaque);
    }
    RecurInfo rinfo = checkBusy(svci, ourEvent.getUid(), recurrences, org, inboxEv.getUid(), doubleBookOk);
    /* If we have a master then we should set its status to cover the largest
     * number of overrides - if any.
     *
     * The easiest case is no overrides and all accepted or all declined.
     *
     * Otherwise we have to update or add overrides.
     */
    boolean allAcceptedOrDeclined = (rinfo.availCt == 0) || (rinfo.busyCt == 0);
    boolean masterAccept = rinfo.availCt >= rinfo.busyCt;
    String masterPartStat;
    if (masterAccept) {
        masterPartStat = IcalDefs.partstatValAccepted;
    } else {
        masterPartStat = IcalDefs.partstatValDeclined;
    }
    if (!masterSupressed) {
        att = ourEvent.findAttendee(uri);
        if (!masterPartStat.equals(att.getPartstat())) {
            att.setPartstat(masterPartStat);
        }
        if (masterAccept) {
            ourEvent.setTransparency(IcalDefs.transparencyOpaque);
        } else {
            ourEvent.setTransparency(IcalDefs.transparencyTransparent);
        }
    }
    if (allAcceptedOrDeclined) {
        // Ensure any overrides have the same status
        for (EventInfo oei : ourCopy.getOverrides()) {
            BwEvent override = oei.getEvent();
            att = override.findAttendee(uri);
            att = (BwAttendee) att.clone();
            // We're about to reply.
            att.setRsvp(false);
            override.removeAttendee(att);
            override.addAttendee(att);
            if (!masterPartStat.equals(att.getPartstat())) {
                att.setPartstat(masterPartStat);
            }
            if (masterAccept) {
                override.setTransparency(IcalDefs.transparencyOpaque);
            } else {
                override.setTransparency(IcalDefs.transparencyTransparent);
            }
            override.removeXproperties(BwXproperty.appleNeedsReply);
        }
        return true;
    }
    for (RecurrenceInfo ri : rinfo.ris) {
        Recurrence r = ri.r;
        // if (!masterSupressed && !ri.busy && (r.override == null)) {
        // // fine
        // continue;
        // }
        boolean mustOverride = masterAccept == ri.busy;
        EventInfo oei = ourCopy.findOverride(r.recurrenceId, mustOverride);
        if (oei == null) {
            continue;
        }
        BwEvent override = oei.getEvent();
        if (((BwEventProxy) override).getRef().unsaved()) {
            override.setDtstart(r.start);
            override.setDtend(r.end);
            override.setDuration(BwDateTime.makeDuration(r.start, r.end).toString());
        }
        att = override.findAttendee(uri);
        if (att == null) {
            // Guess we weren't invited
            continue;
        }
        att = (BwAttendee) att.clone();
        // We're about to reply.
        att.setRsvp(false);
        override.removeAttendee(att);
        override.addAttendee(att);
        if (!ri.busy) {
            att.setPartstat(IcalDefs.partstatValAccepted);
            override.setTransparency(IcalDefs.transparencyOpaque);
        } else {
            att.setPartstat(IcalDefs.partstatValDeclined);
            override.setTransparency(IcalDefs.transparencyTransparent);
        }
        override.removeXproperties(BwXproperty.appleNeedsReply);
    }
    return true;
}
Also used : Recurrence(org.bedework.icalendar.RecurUtil.Recurrence) AuthProperties(org.bedework.calfacade.configs.AuthProperties) EventInfo(org.bedework.calfacade.svc.EventInfo) BwEvent(org.bedework.calfacade.BwEvent) BwString(org.bedework.calfacade.BwString) Date(java.util.Date) BwAttendee(org.bedework.calfacade.BwAttendee) BwOrganizer(org.bedework.calfacade.BwOrganizer)

Aggregations

BwOrganizer (org.bedework.calfacade.BwOrganizer)18 BwAttendee (org.bedework.calfacade.BwAttendee)8 BwEvent (org.bedework.calfacade.BwEvent)8 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)8 EventInfo (org.bedework.calfacade.svc.EventInfo)8 Period (net.fortuna.ical4j.model.Period)5 PropertyList (net.fortuna.ical4j.model.PropertyList)5 VFreeBusy (net.fortuna.ical4j.model.component.VFreeBusy)5 BwFreeBusyComponent (org.bedework.calfacade.BwFreeBusyComponent)5 BwString (org.bedework.calfacade.BwString)5 PeriodList (net.fortuna.ical4j.model.PeriodList)4 Property (net.fortuna.ical4j.model.Property)4 FreeBusy (net.fortuna.ical4j.model.property.FreeBusy)4 ChangeTable (org.bedework.calfacade.util.ChangeTable)4 ParameterList (net.fortuna.ical4j.model.ParameterList)3 BwPrincipal (org.bedework.calfacade.BwPrincipal)3 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)3 VVoter (net.fortuna.ical4j.model.component.VVoter)2 BwAttachment (org.bedework.calfacade.BwAttachment)2 BwCategory (org.bedework.calfacade.BwCategory)2