Search in sources :

Example 21 with BwAttendee

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

the class SchedulingBase method initScheduleEvent.

protected boolean initScheduleEvent(final EventInfo ei, final boolean response, final boolean iSchedule) throws CalFacadeException {
    BwEvent event = ei.getEvent();
    if (!iSchedule) {
        if (!Util.isEmpty(event.getRecipients())) {
            event.getRecipients().clear();
        }
        if (response) {
            event.addRecipient(event.getOrganizer().getOrganizerUri());
        } else {
            getRecipients(event, event);
            if (ei.getNumOverrides() > 0) {
                for (EventInfo oei : ei.getOverrides()) {
                    getRecipients(event, oei.getEvent());
                }
            }
        }
    }
    setupSharableEntity(event, getPrincipal().getPrincipalRef());
    event.setDtstamps(getCurrentTimestamp());
    // no-op if already set
    assignGuid(event);
    /* Ensure attendees have sequence and dtstamp of event */
    if (event.getNumAttendees() > 0) {
        for (BwAttendee att : event.getAttendees()) {
            if (att.getScheduleAgent() != IcalDefs.scheduleAgentServer) {
                continue;
            }
            att.setSequence(event.getSequence());
            att.setDtstamp(event.getDtstamp());
            if (response) {
                att.setScheduleStatus(IcalDefs.deliveryStatusSuccess);
            }
        }
    }
    return true;
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) BwEvent(org.bedework.calfacade.BwEvent) BwAttendee(org.bedework.calfacade.BwAttendee)

Example 22 with BwAttendee

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

the class SchedulingBase method findUserAttendee.

/**
 * Find the attendee in this event which corresponds to the current user
 *
 * @param ev
 * @return attendee or null.
 * @throws CalFacadeException
 */
protected BwAttendee findUserAttendee(final BwEvent ev) throws CalFacadeException {
    Directories dir = getSvc().getDirectories();
    String thisPref = getPrincipal().getPrincipalRef();
    for (BwAttendee att : ev.getAttendees()) {
        BwPrincipal p = dir.caladdrToPrincipal(att.getAttendeeUri());
        if (p == null) {
            continue;
        }
        if (thisPref.equals(p.getPrincipalRef())) {
            return att;
        }
    }
    return null;
}
Also used : Directories(org.bedework.calfacade.ifs.Directories) BwPrincipal(org.bedework.calfacade.BwPrincipal) BwAttendee(org.bedework.calfacade.BwAttendee)

Example 23 with BwAttendee

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

the class FreeAndBusyHandler method getFreeBusy.

/* (non-Javadoc)
   * @see org.bedework.calsvci.SchedulingI#getFreeBusy(java.util.Collection, org.bedework.calfacade.BwPrincipal, org.bedework.calfacade.BwDateTime, org.bedework.calfacade.BwDateTime, org.bedework.calfacade.BwOrganizer, java.lang.String)
   */
@Override
public BwEvent getFreeBusy(final Collection<BwCalendar> fbset, final BwPrincipal who, final BwDateTime start, final BwDateTime end, final BwOrganizer org, final String uid, final String exceptUid) throws CalFacadeException {
    CalendarsI colHandler = getSvc().getCalendarsHandler();
    Collection<BwCalendar> cals = null;
    if (fbset != null) {
        /* Don't check - we do so at the fetch of events
      getCal().checkAccess(cal, PrivilegeDefs.privReadFreeBusy, false);
      */
        cals = addToFreeBusySet(cals, fbset);
    } else if (getPrincipal().equals(who)) {
        cals = getFreebusySet();
    } else {
        /* CalDAV uses Inbox to determine scheduling acccess */
        try {
            getSpecialCalendar(who, BwCalendar.calTypeInbox, true, PrivilegeDefs.privReadFreeBusy);
        } catch (CalFacadeAccessException cae) {
            getSpecialCalendar(who, BwCalendar.calTypeInbox, true, PrivilegeDefs.privScheduleFreeBusy);
        }
        cals = addToFreeBusySet(cals, colHandler.getChildren(colHandler.getHome(who, true)));
    }
    if (cals == null) {
        throw new CalFacadeAccessException();
    }
    BwEvent fb = new BwEventObj();
    fb.setEntityType(IcalDefs.entityTypeFreeAndBusy);
    fb.setOwnerHref(who.getPrincipalRef());
    fb.setDtstart(start);
    fb.setDtend(end);
    fb.setEndType(StartEndComponent.endTypeDate);
    if (uid == null) {
        assignGuid(fb);
    } else {
        fb.setUid(uid);
    }
    fb.setDtstamps(getCurrentTimestamp());
    String uri = getSvc().getDirectories().principalToCaladdr(who);
    BwAttendee att = new BwAttendee();
    att.setAttendeeUri(uri);
    fb.addAttendee(att);
    fb.setOrganizer((BwOrganizer) org.clone());
    Collection<EventInfo> events = new TreeSet<EventInfo>();
    /* Only events and freebusy for freebusy reports. */
    FilterBase filter = new OrFilter();
    try {
        filter.addChild(EntityTypeFilter.makeEntityTypeFilter(null, "event", false));
        filter.addChild(EntityTypeFilter.makeEntityTypeFilter(null, "freeAndBusy", false));
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
    String userHref = who.getPrincipalRef();
    for (BwCalendar c : cals) {
        if (!c.getAffectsFreeBusy()) {
            continue;
        }
        // XXX If it's an external subscription we probably just get free busy and
        // merge it in.
        RecurringRetrievalMode rrm = new RecurringRetrievalMode(Rmode.expanded, start, end);
        Collection<BwCalendar> cs = new ArrayList<BwCalendar>();
        cs.add(c);
        Collection<EventInfo> evs = getEvents(cs, filter, start, end, // retrieveList
        null, rrm, true);
        // Filter out transparent events
        for (EventInfo ei : evs) {
            BwEvent ev = ei.getEvent();
            if ((exceptUid != null) && exceptUid.equals(ev.getUid())) {
                continue;
            }
            if (!c.getIgnoreTransparency() && IcalDefs.transparencyTransparent.equals(ev.getPeruserTransparency(userHref))) {
                // Ignore this one.
                continue;
            }
            if (BwEvent.statusCancelled.equals(ev.getStatus())) {
                // Ignore this one.
                continue;
            }
            if (ev.getAttendeeSchedulingObject()) {
                att = ev.findAttendee(uri);
                if (att != null) {
                    int pstat = IcalDefs.checkPartstat(att.getPartstat());
                    if (pstat == IcalDefs.partstatDeclined) {
                        continue;
                    }
                    if (pstat == IcalDefs.partstatNeedsAction) {
                        continue;
                    }
                }
            }
            events.add(ei);
        }
    }
    try {
        EventPeriods eventPeriods = new EventPeriods(start, end);
        for (EventInfo ei : events) {
            BwEvent ev = ei.getEvent();
            int type;
            if (ev.getEntityType() == IcalDefs.entityTypeEvent) {
                if (BwEvent.statusCancelled.equals(ev.getStatus())) {
                    // Ignore this one.
                    continue;
                }
                type = BwFreeBusyComponent.typeBusy;
                if (ev.getAttendeeSchedulingObject()) {
                    att = ev.findAttendee(uri);
                    if (att != null) {
                        if (IcalDefs.checkPartstat(att.getPartstat()) == IcalDefs.partstatTentative) {
                            type = BwFreeBusyComponent.typeBusyTentative;
                        }
                    }
                }
                if (BwEvent.statusTentative.equals(ev.getStatus())) {
                    type = BwFreeBusyComponent.typeBusyTentative;
                } else if (BwEvent.statusUnavailable.equals(ev.getStatus())) {
                    type = BwFreeBusyComponent.typeBusyUnavailable;
                }
                eventPeriods.addPeriod(ev.getDtstart(), ev.getDtend(), type);
            } else if (ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy) {
                Collection<BwFreeBusyComponent> fbcs = ev.getFreeBusyPeriods();
                for (BwFreeBusyComponent fbc : fbcs) {
                    type = fbc.getType();
                    for (Period p : fbc.getPeriods()) {
                        eventPeriods.addPeriod(p.getStart(), p.getEnd(), type);
                    }
                }
            }
        }
        /* iterate through the sorted periods combining them where they are
       adjacent or overlap */
        BwFreeBusyComponent fbc = eventPeriods.makeFreeBusyComponent(BwFreeBusyComponent.typeBusy);
        if (fbc != null) {
            fb.addFreeBusyPeriod(fbc);
        }
        fbc = eventPeriods.makeFreeBusyComponent(BwFreeBusyComponent.typeBusyUnavailable);
        if (fbc != null) {
            fb.addFreeBusyPeriod(fbc);
        }
        fbc = eventPeriods.makeFreeBusyComponent(BwFreeBusyComponent.typeBusyTentative);
        if (fbc != null) {
            fb.addFreeBusyPeriod(fbc);
        }
    } catch (Throwable t) {
        if (debug) {
            error(t);
        }
        throw new CalFacadeException(t);
    }
    return fb;
}
Also used : EventPeriods(org.bedework.calfacade.util.EventPeriods) BwFreeBusyComponent(org.bedework.calfacade.BwFreeBusyComponent) EventInfo(org.bedework.calfacade.svc.EventInfo) RecurringRetrievalMode(org.bedework.calfacade.RecurringRetrievalMode) ArrayList(java.util.ArrayList) Period(net.fortuna.ical4j.model.Period) EventPeriod(org.bedework.calfacade.util.Granulator.EventPeriod) BwEvent(org.bedework.calfacade.BwEvent) CalendarsI(org.bedework.calsvci.CalendarsI) BwCalendar(org.bedework.calfacade.BwCalendar) OrFilter(org.bedework.caldav.util.filter.OrFilter) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) TreeSet(java.util.TreeSet) Collection(java.util.Collection) BwAttendee(org.bedework.calfacade.BwAttendee) BwEventObj(org.bedework.calfacade.BwEventObj) FilterBase(org.bedework.caldav.util.filter.FilterBase)

Example 24 with BwAttendee

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

the class AttendeePropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    try {
        ChangeTableEntry cte = ui.getCte();
        BwEvent ev = ui.getEvent();
        Set<BwAttendee> atts = ev.getAttendees();
        AttendeePropType pr = (AttendeePropType) ui.getProp();
        String attUri = ui.getIcalCallback().getCaladdr(ui.getIcalCallback().getPrincipal().getPrincipalRef());
        /* Must have an organizer propery */
        BwOrganizer org = ev.getOrganizer();
        if (org == null) {
            return new UpdateResult("No organizer for attendee update");
        }
        boolean isOrganizer = attUri.equals(org.getOrganizerUri());
        if (!isOrganizer) {
            /* Options are pretty limited here - change partstat only to our own entry
         */
            if (!pr.getCalAddress().equals(attUri)) {
                return new UpdateResult("Cannot update other attendees");
            }
            if (ui.isAdd() || ui.isRemove()) {
                return new UpdateResult("Cannot add or remove attendees");
            }
            if (!ui.isChange()) {
                // Nothing to do
                return UpdateResult.getOkResult();
            }
            // return new UpdateResult("unimplemented - attendee update");
            throw new WebdavException("Unimplemented - attendees update");
        }
        if (ui.isAdd()) {
            if (!Util.isEmpty(atts)) {
                for (BwAttendee att : atts) {
                    if (att.getAttendeeUri().equals(pr.getCalAddress())) {
                        // Already there
                        return UpdateResult.getOkResult();
                    }
                }
            }
            BwAttendee newAtt = makeAttendee(pr);
            ev.addAttendee(newAtt);
            cte.addAddedValue(newAtt);
            return UpdateResult.getOkResult();
        }
        if (ui.isRemove()) {
            if (Util.isEmpty(atts)) {
                // Nothing to remove
                return UpdateResult.getOkResult();
            }
            BwAttendee remAtt = makeAttendee(pr);
            if (ev.removeAttendee(remAtt)) {
                cte.addRemovedValue(remAtt);
            }
            return UpdateResult.getOkResult();
        }
        if (ui.isChange()) {
            // Change a value
            if (Util.isEmpty(atts)) {
                // Nothing to change
                return new UpdateResult("No comment to change");
            }
            for (BwAttendee att : atts) {
                if (att.getAttendeeUri().equals(pr.getCalAddress())) {
                    // Found
                    throw new WebdavException("Unimplemented - attendees update");
                // return UpdateResult.getOkResult();
                }
            }
        }
        return UpdateResult.getOkResult();
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) AttendeePropType(ietf.params.xml.ns.icalendar_2.AttendeePropType) BwAttendee(org.bedework.calfacade.BwAttendee) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BwOrganizer(org.bedework.calfacade.BwOrganizer)

Example 25 with BwAttendee

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

the class AttendeeRule method end.

@Override
public void end(final String ns, final String name) throws Exception {
    BwAttendee entity = (BwAttendee) pop();
    EventInfo ei = (EventInfo) getTop(EventInfo.class, name);
    BwEvent e = ei.getEvent();
    if (e instanceof BwEventProxy) {
        e = ((BwEventProxy) e).getRef();
    }
    // Mark unsaved
    entity.setId(CalFacadeDefs.unsavedItemKey);
    e.addAttendee(entity);
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) BwEvent(org.bedework.calfacade.BwEvent) BwEventProxy(org.bedework.calfacade.BwEventProxy) BwAttendee(org.bedework.calfacade.BwAttendee)

Aggregations

BwAttendee (org.bedework.calfacade.BwAttendee)41 BwEvent (org.bedework.calfacade.BwEvent)25 EventInfo (org.bedework.calfacade.svc.EventInfo)19 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)17 BwString (org.bedework.calfacade.BwString)10 BwOrganizer (org.bedework.calfacade.BwOrganizer)8 BwEventProxy (org.bedework.calfacade.BwEventProxy)7 Period (net.fortuna.ical4j.model.Period)6 BwDateTime (org.bedework.calfacade.BwDateTime)6 BwFreeBusyComponent (org.bedework.calfacade.BwFreeBusyComponent)6 PropertyList (net.fortuna.ical4j.model.PropertyList)5 BwEventObj (org.bedework.calfacade.BwEventObj)5 TreeSet (java.util.TreeSet)4 DateTime (net.fortuna.ical4j.model.DateTime)4 PeriodList (net.fortuna.ical4j.model.PeriodList)4 Property (net.fortuna.ical4j.model.Property)4 VFreeBusy (net.fortuna.ical4j.model.component.VFreeBusy)4 FreeBusy (net.fortuna.ical4j.model.property.FreeBusy)4 BwCalendar (org.bedework.calfacade.BwCalendar)4 BwCategory (org.bedework.calfacade.BwCategory)4