Search in sources :

Example 86 with BwEvent

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

the class CalintfHelper method postGetEvent.

/* Post processing of event access has been checked
   */
protected CoreEventInfo postGetEvent(final BwEvent ev, final Filters f, final Acl.CurrentAccess ca) throws CalFacadeException {
    /* XXX-ALARM
    if (currentMode == userMode) {
      ev.setAlarms(getAlarms(ev, user));
    }
    */
    BwEvent event;
    if (ev instanceof BwEventAnnotation) {
        event = new BwEventProxy((BwEventAnnotation) ev);
        if ((f != null) && !f.postFilter(ev, currentPrincipal())) {
            return null;
        }
    } else {
        event = ev;
    }
    CoreEventInfo cei = new CoreEventInfo(event, ca);
    return cei;
}
Also used : BwEventAnnotation(org.bedework.calfacade.BwEventAnnotation) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) BwEvent(org.bedework.calfacade.BwEvent) BwEventProxy(org.bedework.calfacade.BwEventProxy)

Example 87 with BwEvent

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

the class CalintfImpl method getFreeBusy.

/* ====================================================================
   *                   Free busy
   * ==================================================================== */
@Override
public BwEvent getFreeBusy(final Collection<BwCalendar> cals, final BwPrincipal who, final BwDateTime start, final BwDateTime end, final boolean returnAll, final boolean ignoreTransparency) throws CalFacadeException {
    if (who.getKind() != WhoDefs.whoTypeUser) {
        throw new CalFacadeException("Unsupported: non user principal for free-busy");
    }
    final Collection<CoreEventInfo> events = getFreeBusyEntities(cals, start, end, ignoreTransparency);
    final BwEvent fb = new BwEventObj();
    fb.setEntityType(IcalDefs.entityTypeFreeAndBusy);
    fb.setOwnerHref(who.getPrincipalRef());
    fb.setDtstart(start);
    fb.setDtend(end);
    try {
        final TreeSet<EventPeriod> eventPeriods = new TreeSet<>();
        for (final CoreEventInfo ei : events) {
            final BwEvent ev = ei.getEvent();
            // Ignore if times were specified and this event is outside the times
            final BwDateTime estart = ev.getDtstart();
            final BwDateTime eend = ev.getDtend();
            /* Don't report out of the requested period */
            final String dstart;
            final String dend;
            if (estart.before(start)) {
                dstart = start.getDtval();
            } else {
                dstart = estart.getDtval();
            }
            if (eend.after(end)) {
                dend = end.getDtval();
            } else {
                dend = eend.getDtval();
            }
            final DateTime psdt = new DateTime(dstart);
            final DateTime pedt = new DateTime(dend);
            psdt.setUtc(true);
            pedt.setUtc(true);
            int type = BwFreeBusyComponent.typeBusy;
            if (BwEvent.statusTentative.equals(ev.getStatus())) {
                type = BwFreeBusyComponent.typeBusyTentative;
            }
            eventPeriods.add(new EventPeriod(psdt, pedt, type));
        }
        /* iterate through the sorted periods combining them where they are
       adjacent or overlap */
        Period p = null;
        /* For the moment just build a single BwFreeBusyComponent
       */
        BwFreeBusyComponent fbc = null;
        int lastType = 0;
        for (final EventPeriod ep : eventPeriods) {
            if (debug) {
                debug(ep.toString());
            }
            if (p == null) {
                p = new Period(ep.getStart(), ep.getEnd());
                lastType = ep.getType();
            } else if ((lastType != ep.getType()) || ep.getStart().after(p.getEnd())) {
                // Non adjacent periods
                if (fbc == null) {
                    fbc = new BwFreeBusyComponent();
                    fbc.setType(lastType);
                    fb.addFreeBusyPeriod(fbc);
                }
                fbc.addPeriod(p.getStart(), p.getEnd());
                if (lastType != ep.getType()) {
                    fbc = null;
                }
                p = new Period(ep.getStart(), ep.getEnd());
                lastType = ep.getType();
            } else if (ep.getEnd().after(p.getEnd())) {
                // Extend the current period
                p = new Period(p.getStart(), ep.getEnd());
            }
        // else it falls within the existing period
        }
        if (p != null) {
            if ((fbc == null) || (lastType != fbc.getType())) {
                fbc = new BwFreeBusyComponent();
                fbc.setType(lastType);
                fb.addFreeBusyPeriod(fbc);
            }
            fbc.addPeriod(p.getStart(), p.getEnd());
        }
    } catch (final Throwable t) {
        if (debug) {
            error(t);
        }
        throw new CalFacadeException(t);
    }
    return fb;
}
Also used : EventPeriod(org.bedework.calfacade.util.Granulator.EventPeriod) BwFreeBusyComponent(org.bedework.calfacade.BwFreeBusyComponent) BwDateTime(org.bedework.calfacade.BwDateTime) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) Period(net.fortuna.ical4j.model.Period) EventPeriod(org.bedework.calfacade.util.Granulator.EventPeriod) BwEvent(org.bedework.calfacade.BwEvent) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) DateTime(net.fortuna.ical4j.model.DateTime) BwDateTime(org.bedework.calfacade.BwDateTime) TreeSet(java.util.TreeSet) BwEventObj(org.bedework.calfacade.BwEventObj)

Example 88 with BwEvent

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

the class CalintfImpl method getFreeBusyEntities.

private Collection<CoreEventInfo> getFreeBusyEntities(final Collection<BwCalendar> cals, final BwDateTime start, final BwDateTime end, final boolean ignoreTransparency) throws CalFacadeException {
    /* Only events and freebusy for freebusy reports. */
    final FilterBase filter = new OrFilter();
    try {
        filter.addChild(EntityTypeFilter.makeEntityTypeFilter(null, "event", false));
        filter.addChild(EntityTypeFilter.makeEntityTypeFilter(null, "freeAndBusy", false));
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
    final RecurringRetrievalMode rrm = new RecurringRetrievalMode(Rmode.expanded, start, end);
    final Collection<CoreEventInfo> evs = getEvents(cals, filter, start, end, null, DeletedState.noDeleted, rrm, true);
    // Filter out transparent and cancelled events
    final Collection<CoreEventInfo> events = new TreeSet<>();
    for (final CoreEventInfo cei : evs) {
        final BwEvent ev = cei.getEvent();
        if (!ignoreTransparency && IcalDefs.transparencyTransparent.equals(ev.getPeruserTransparency(this.getPrincipal().getPrincipalRef()))) {
            // Ignore this one.
            continue;
        }
        if (ev.getSuppressed() || BwEvent.statusCancelled.equals(ev.getStatus())) {
            // Ignore this one.
            continue;
        }
        events.add(cei);
    }
    return events;
}
Also used : RecurringRetrievalMode(org.bedework.calfacade.RecurringRetrievalMode) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) TreeSet(java.util.TreeSet) BwEvent(org.bedework.calfacade.BwEvent) OrFilter(org.bedework.caldav.util.filter.OrFilter) FilterBase(org.bedework.caldav.util.filter.FilterBase) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 89 with BwEvent

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

the class XbwContactPropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    try {
        final ChangeTableEntry cte = ui.getCte();
        final BwEvent ev = ui.getEvent();
        final List<BwXproperty> xcontacts = ev.getXproperties(BwXproperty.xBedeworkContact);
        final Set<BwContact> contacts = ev.getContacts();
        final String lang = UpdaterUtil.getLang(ui.getProp());
        final String xval = ((TextPropertyType) ui.getProp()).getText();
        final BwString cstr = new BwString(lang, xval);
        if (ui.isRemove()) {
            if (Util.isEmpty(xcontacts)) {
                // Nothing to remove
                return UpdateResult.getOkResult();
            }
            for (final BwXproperty xp : xcontacts) {
                if (!xp.getValue().equals(xval)) {
                    continue;
                }
                // Found
                ev.removeXproperty(xp);
                cte.addRemovedValue(xp);
                /* Do we have a corresponding contact */
                for (final BwContact c : contacts) {
                    if (c.getCn().equals(cstr)) {
                        ev.removeContact(c);
                        cte.addRemovedValue(c);
                        break;
                    }
                }
                return UpdateResult.getOkResult();
            }
            return UpdateResult.getOkResult();
        }
        if (ui.isAdd()) {
            for (final BwXproperty xp : xcontacts) {
                if (xp.getValue().equals(xval)) {
                    return new UpdateResult("Entity already has " + ui.getPropName() + " property with that value - cannot add");
                }
            }
            /* Add the xprop or a contact */
            if (!checkContact(ui, ev, contacts, lang, xval)) {
                final BwXproperty xp = makeXprop(lang, xval);
                ev.addXproperty(xp);
                cte.addAddedValue(xp);
            }
            return UpdateResult.getOkResult();
        }
        if (ui.isChange()) {
            for (final BwXproperty xp : xcontacts) {
                if (xp.getValue().equals(xval)) {
                    // Found
                    ev.removeXproperty(xp);
                    cte.addRemovedValue(xp);
                    final String nlang = UpdaterUtil.getLang(ui.getUpdprop());
                    final String nxval = ((TextPropertyType) ui.getUpdprop()).getText();
                    if (!checkContact(ui, ev, contacts, nlang, nxval)) {
                        final BwXproperty nxp = makeXprop(nlang, nxval);
                        ev.addXproperty(nxp);
                        cte.addAddedValue(nxp);
                    }
                    return UpdateResult.getOkResult();
                }
            }
        }
        return UpdateResult.getOkResult();
    } catch (final CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : BwXproperty(org.bedework.calfacade.BwXproperty) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) BwContact(org.bedework.calfacade.BwContact) BwString(org.bedework.calfacade.BwString) TextPropertyType(ietf.params.xml.ns.icalendar_2.TextPropertyType) BwString(org.bedework.calfacade.BwString) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 90 with BwEvent

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

the class XbwLocPropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    try {
        final ChangeTableEntry cte = ui.getCte();
        final BwEvent ev = ui.getEvent();
        final List<BwXproperty> xlocs = ev.getXproperties(xBedeworkLocation);
        // Should only be one or zero
        final BwXproperty xloc;
        if (Util.isEmpty(xlocs)) {
            xloc = null;
        } else {
            xloc = xlocs.get(0);
        }
        final String lang = UpdaterUtil.getLang(ui.getProp());
        final String xval = ((TextPropertyType) ui.getProp()).getText();
        final BaseParameterType keyParam = XcalUtil.findParam(ui.getProp(), XcalTags.xBedeworkLocationKey);
        final String keyName;
        if (keyParam != null) {
            keyName = ((TextParameterType) keyParam).getText();
        } else {
            keyName = null;
        }
        final BwLocation evLoc = ev.getLocation();
        if (ui.isRemove()) {
            if (xlocs == null) {
                // Nothing to remove
                return UpdateResult.getOkResult();
            }
            // TODO - match values?
            ev.removeXproperty(xloc);
            cte.addRemovedValue(xloc);
            if (evLoc != null) {
                ev.setLocation(null);
                cte.addRemovedValue(evLoc);
            }
            return UpdateResult.getOkResult();
        }
        if (ui.isAdd()) {
            if (xloc != null) {
                return new UpdateResult("Entity already has " + ui.getPropName() + " property - cannot add");
            }
            if (!checkLocation(ui, ev, lang, xval, null)) {
                final BwXproperty xp = makeXprop(lang, xval);
                ev.addXproperty(xp);
                cte.addAddedValue(xp);
            }
            return UpdateResult.getOkResult();
        }
        if (ui.isChange()) {
            if (xloc == null) {
                return new UpdateResult("Entity has no " + ui.getPropName() + " property - cannot change");
            }
            if (CalFacadeUtil.cmpObjval(xval, xloc.getValue()) != 0) {
                return new UpdateResult("Values don't match for update to " + ui.getPropName());
            }
            ev.removeXproperty(xloc);
            cte.addRemovedValue(xloc);
            final String nlang = UpdaterUtil.getLang(ui.getUpdprop());
            final String nxval = ((TextPropertyType) ui.getUpdprop()).getText();
            if (!checkLocation(ui, ev, nlang, nxval, keyName)) {
                final BwXproperty nxp = makeXprop(nlang, nxval);
                if (keyName != null) {
                    nxp.getParameters().add(new Xpar(XcalTags.xBedeworkLocationKey.getLocalPart(), keyName));
                }
                ev.addXproperty(nxp);
                cte.addAddedValue(nxp);
            }
        }
        return UpdateResult.getOkResult();
    } catch (final CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : Xpar(org.bedework.calfacade.BwXproperty.Xpar) BaseParameterType(ietf.params.xml.ns.icalendar_2.BaseParameterType) BwLocation(org.bedework.calfacade.BwLocation) BwXproperty(org.bedework.calfacade.BwXproperty) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) BwString(org.bedework.calfacade.BwString) TextPropertyType(ietf.params.xml.ns.icalendar_2.TextPropertyType) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

BwEvent (org.bedework.calfacade.BwEvent)160 EventInfo (org.bedework.calfacade.svc.EventInfo)80 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)55 BwEventProxy (org.bedework.calfacade.BwEventProxy)33 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)26 BwAttendee (org.bedework.calfacade.BwAttendee)25 BwDateTime (org.bedework.calfacade.BwDateTime)25 BwString (org.bedework.calfacade.BwString)24 UpdateResult (org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)23 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)23 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)21 BwCalendar (org.bedework.calfacade.BwCalendar)21 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)20 BwXproperty (org.bedework.calfacade.BwXproperty)16 TreeSet (java.util.TreeSet)15 BwEventObj (org.bedework.calfacade.BwEventObj)13 ArrayList (java.util.ArrayList)12 Period (net.fortuna.ical4j.model.Period)12 BwCategory (org.bedework.calfacade.BwCategory)10 BwContact (org.bedework.calfacade.BwContact)10