Search in sources :

Example 11 with BwEvent

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

the class Events method processExpanded.

private Collection<EventInfo> processExpanded(final Collection<EventInfo> events, final RecurringRetrievalMode recurRetrieval) throws CalFacadeException {
    Collection<EventInfo> res = new ArrayList<>();
    for (EventInfo ei : events) {
        BwEvent ev = ei.getEvent();
        if (!ev.getRecurring()) {
            res.add(ei);
            continue;
        }
        CurrentAccess ca = ei.getCurrentAccess();
        Set<EventInfo> oveis = ei.getOverrides();
        if (!Util.isEmpty(oveis)) {
            for (EventInfo oei : oveis) {
                if (oei.getEvent().inDateTimeRange(recurRetrieval.start.getDate(), recurRetrieval.end.getDate())) {
                    oei.setRetrievedEvent(ei);
                    res.add(oei);
                }
            }
        }
        /* Generate non-overridden instances. */
        final Collection<Recurrence> instances = RecurUtil.getRecurrences(ei, getAuthpars().getMaxYears(), getAuthpars().getMaxInstances(), recurRetrieval.getStartDate(), recurRetrieval.getEndDate());
        if (instances == null) {
            return res;
        }
        for (final Recurrence rec : instances) {
            if (rec.override != null) {
                continue;
            }
            final BwEventAnnotation ann = new BwEventAnnotation();
            ann.setDtstart(rec.start);
            ann.setDtend(rec.end);
            ann.setRecurrenceId(rec.recurrenceId);
            ann.setOwnerHref(ev.getOwnerHref());
            // Call it an override
            ann.setOverride(true);
            ann.setTombstoned(false);
            ann.setName(ev.getName());
            ann.setUid(ev.getUid());
            ann.setTarget(ev);
            ann.setMaster(ev);
            final BwEvent proxy = new BwEventProxy(ann);
            final EventInfo oei = new EventInfo(proxy);
            oei.setCurrentAccess(ei.getCurrentAccess());
            oei.setRetrievedEvent(ei);
            res.add(oei);
        }
    }
    return res;
}
Also used : Recurrence(org.bedework.icalendar.RecurUtil.Recurrence) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) EventInfo(org.bedework.calfacade.svc.EventInfo) BwEventAnnotation(org.bedework.calfacade.BwEventAnnotation) ArrayList(java.util.ArrayList) BwEvent(org.bedework.calfacade.BwEvent) CurrentAccess(org.bedework.access.Acl.CurrentAccess) BwEventProxy(org.bedework.calfacade.BwEventProxy)

Example 12 with BwEvent

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

the class Events method update.

@Override
public UpdateResult update(final EventInfo ei, final boolean noInvites, final String fromAttUri, final boolean alwaysWrite) throws CalFacadeException {
    try {
        final BwEvent event = ei.getEvent();
        final UpdateResult updResult = ei.getUpdResult();
        updateEntities(updResult, event);
        final BwCalendar cal = validate(event, false, false, false);
        adjustEntities(ei);
        final RealiasResult raResp = reAlias(event);
        if (raResp.getStatus() != ok) {
            throw new CalFacadeException(CalFacadeException.badRequest, "Status: " + raResp.getStatus() + " message: " + raResp.getMessage());
        }
        boolean organizerSchedulingObject = false;
        boolean attendeeSchedulingObject = false;
        if (cal.getCollectionInfo().scheduling) {
            organizerSchedulingObject = event.getOrganizerSchedulingObject();
            attendeeSchedulingObject = event.getAttendeeSchedulingObject();
        }
        boolean schedulingObject = organizerSchedulingObject || attendeeSchedulingObject;
        if (event.getSignificantChange() && schedulingObject) {
            event.updateStag(getCurrentTimestamp());
        }
        boolean changed = alwaysWrite || checkChanges(ei, organizerSchedulingObject, attendeeSchedulingObject) || ei.getOverridesChanged();
        boolean sequenceChange = ei.getUpdResult().sequenceChange;
        /* TODO - this is wrong.
         At the very least we should only reschedule the override that changed.
         However adding an override looks like a change for all the fields
         copied in. There should only be a change if the value is different
       */
        boolean doReschedule = ei.getUpdResult().doReschedule;
        if (ei.getNumOverrides() > 0) {
            for (final EventInfo oei : ei.getOverrides()) {
                setScheduleState(oei.getEvent(), false, false);
                if (cal.getCollectionInfo().scheduling && oei.getEvent().getAttendeeSchedulingObject()) {
                    schedulingObject = true;
                    attendeeSchedulingObject = true;
                // Shouldn't need to check organizer - it's set in the master even
                // if suppressed.
                }
                if (checkChanges(oei, organizerSchedulingObject, attendeeSchedulingObject)) {
                    changed = true;
                    if (oei.getUpdResult().sequenceChange) {
                        sequenceChange = true;
                    }
                }
                if (schedulingObject) {
                    oei.getEvent().updateStag(getCurrentTimestamp());
                }
                doReschedule = doReschedule || oei.getUpdResult().doReschedule;
            }
        }
        if (!changed) {
            if (debug) {
                trace("No changes to event: returning");
            }
            return ei.getUpdResult();
        }
        event.setDtstamps(getCurrentTimestamp());
        if (organizerSchedulingObject && sequenceChange) {
            event.setSequence(event.getSequence() + 1);
        }
        final UpdateEventResult uer = getCal().updateEvent(ei);
        updResult.addedInstances = uer.added;
        updResult.updatedInstances = uer.updated;
        updResult.deletedInstances = uer.deleted;
        updResult.fromAttUri = fromAttUri;
        if (!noInvites && schedulingObject) {
            if (organizerSchedulingObject) {
                // Set RSVP on all attendees with PARTSTAT = NEEDS_ACTION
                for (final BwAttendee att : event.getAttendees()) {
                    if (att.getPartstat().equals(IcalDefs.partstatValNeedsAction)) {
                        att.setRsvp(true);
                    }
                }
            }
            boolean sendit = organizerSchedulingObject || updResult.reply;
            if (!sendit) {
                if (!Util.isEmpty(ei.getOverrides())) {
                    for (final EventInfo oei : ei.getOverrides()) {
                        if (oei.getUpdResult().reply) {
                            sendit = true;
                            break;
                        }
                    }
                }
            }
            if (sendit) {
                final SchedulingIntf sched = (SchedulingIntf) getSvc().getScheduler();
                sched.implicitSchedule(ei, false);
            /* We assume we don't need to update again to set attendee status
           * Trying to do an update results in duplicate key errors.
           *
           * If it turns out the scgedule status is not getting persisted in the
           * calendar entry then we need to find a way to set just that value in
           * already persisted entity.
           */
            }
        }
        return updResult;
    } catch (final Throwable t) {
        getSvc().rollbackTransaction();
        if (t instanceof CalFacadeException) {
            throw (CalFacadeException) t;
        }
        throw new CalFacadeException(t);
    }
}
Also used : CoreEventInfo(org.bedework.calcorei.CoreEventInfo) EventInfo(org.bedework.calfacade.svc.EventInfo) BwEvent(org.bedework.calfacade.BwEvent) SchedulingIntf(org.bedework.calsvc.scheduling.SchedulingIntf) BwCalendar(org.bedework.calfacade.BwCalendar) BwAttendee(org.bedework.calfacade.BwAttendee) UpdateResult(org.bedework.calfacade.svc.EventInfo.UpdateResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) UpdateEventResult(org.bedework.calcorei.CoreEventsI.UpdateEventResult)

Example 13 with BwEvent

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

the class Events method postProcess.

private EventInfo postProcess(final CoreEventInfo cei) throws CalFacadeException {
    if (cei == null) {
        return null;
    }
    // trace("ev: " + ev);
    /* If the event is an event reference (an alias) implant it in an event
     * proxy and return that object.
     */
    BwEvent ev = cei.getEvent();
    if (ev instanceof BwEventAnnotation) {
        ev = new BwEventProxy((BwEventAnnotation) ev);
    }
    final Set<EventInfo> overrides = new TreeSet<EventInfo>();
    if (cei.getOverrides() != null) {
        for (final CoreEventInfo ocei : cei.getOverrides()) {
            final BwEventProxy op = (BwEventProxy) ocei.getEvent();
            overrides.add(new EventInfo(op));
        }
    }
    final EventInfo ei = new EventInfo(ev, overrides);
    /* Reconstruct if any contained items. */
    if (cei.getNumContainedItems() > 0) {
        for (CoreEventInfo ccei : cei.getContainedItems()) {
            BwEvent cv = ccei.getEvent();
            ei.addContainedItem(new EventInfo(cv));
        }
    }
    ei.setCurrentAccess(cei.getCurrentAccess());
    return ei;
}
Also used : CoreEventInfo(org.bedework.calcorei.CoreEventInfo) EventInfo(org.bedework.calfacade.svc.EventInfo) BwEventAnnotation(org.bedework.calfacade.BwEventAnnotation) TreeSet(java.util.TreeSet) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) BwEvent(org.bedework.calfacade.BwEvent) BwEventProxy(org.bedework.calfacade.BwEventProxy)

Example 14 with BwEvent

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

the class Events method add.

@Override
public UpdateResult add(final EventInfo ei, final boolean noInvites, final boolean schedulingInbox, final boolean autoCreateCollection, final boolean rollbackOnError) throws CalFacadeException {
    try {
        if (getPrincipalInfo().getSubscriptionsOnly()) {
            throw new CalFacadeForbidden("User has read only access");
        }
        final UpdateResult updResult = ei.getUpdResult();
        updResult.adding = true;
        updResult.hasChanged = true;
        final BwEvent event = ei.getEvent();
        adjustEntities(ei);
        final BwPreferences prefs = getSvc().getPrefsHandler().get();
        if (prefs != null) {
            final Collection<BwCategory> cats = getSvc().getCategoriesHandler().get(prefs.getDefaultCategoryUids());
            for (final BwCategory cat : cats) {
                event.addCategory(cat);
            }
        }
        final RealiasResult raResp = reAlias(event);
        if (raResp.getStatus() != ok) {
            throw new CalFacadeException(CalFacadeException.badRequest, "Status: " + raResp.getStatus() + " message: " + raResp.getMessage());
        }
        // Or just validate?
        assignGuid(event);
        updateEntities(updResult, event);
        BwCalendar cal = validate(event, true, schedulingInbox, autoCreateCollection);
        BwEventProxy proxy = null;
        BwEvent override = null;
        if (event instanceof BwEventProxy) {
            proxy = (BwEventProxy) event;
            override = proxy.getRef();
            setupSharableEntity(override, getPrincipal().getPrincipalRef());
        } else {
            setupSharableEntity(event, getPrincipal().getPrincipalRef());
            if (ei.getNumContainedItems() > 0) {
                for (final EventInfo aei : ei.getContainedItems()) {
                    final BwEvent av = aei.getEvent();
                    av.setParent(event);
                    setupSharableEntity(av, getPrincipal().getPrincipalRef());
                }
            }
        }
        final BwCalendar undereffedCal = cal;
        if (cal.getInternalAlias()) {
            /* Resolve the alias and put the event in it's proper place */
            // XXX This is probably OK for non-public admin
            final boolean setCats = getSvc().getPars().getPublicAdmin();
            if (!setCats) {
                cal = getCols().resolveAlias(cal, true, false);
            } else {
                while (true) {
                    final Set<BwCategory> cats = cal.getCategories();
                    for (final BwCategory cat : cats) {
                        event.addCategory(cat);
                    }
                    if (!cal.getInternalAlias()) {
                        break;
                    }
                    cal = getCols().resolveAlias(cal, false, false);
                }
            }
            event.setColPath(cal.getPath());
        }
        if (!cal.getCalendarCollection()) {
            throw new CalFacadeAccessException();
        }
        if (!event.getPublick() && Util.isEmpty(event.getAlarms())) {
            setDefaultAlarms(ei, undereffedCal);
        }
        boolean schedulingObject = false;
        if (cal.getCollectionInfo().scheduling && (event.getOrganizerSchedulingObject() || event.getAttendeeSchedulingObject())) {
            schedulingObject = true;
        }
        final Integer maxAttendees = getSvc().getAuthProperties().getMaxAttendeesPerInstance();
        if ((maxAttendees != null) && !Util.isEmpty(event.getAttendees()) && (event.getAttendees().size() > maxAttendees)) {
            throw new CalFacadeException(CalFacadeException.schedulingTooManyAttendees);
        }
        event.setDtstamps(getCurrentTimestamp());
        if (schedulingObject) {
            event.updateStag(getCurrentTimestamp());
        }
        /* All Overrides go in same calendar and have same name */
        final Collection<BwEventProxy> overrides = ei.getOverrideProxies();
        if (overrides != null) {
            for (final BwEventProxy ovei : overrides) {
                setScheduleState(ovei, true, schedulingInbox);
                if ((maxAttendees != null) && !Util.isEmpty(ovei.getAttendees()) && (ovei.getAttendees().size() > maxAttendees)) {
                    throw new CalFacadeException(CalFacadeException.schedulingTooManyAttendees);
                }
                ovei.setDtstamps(getCurrentTimestamp());
                if (cal.getCollectionInfo().scheduling && (ovei.getOrganizerSchedulingObject() || ovei.getAttendeeSchedulingObject())) {
                    schedulingObject = true;
                }
                if (schedulingObject) {
                    ovei.updateStag(getCurrentTimestamp());
                }
                final BwEventAnnotation ann = ovei.getRef();
                ann.setColPath(event.getColPath());
                ann.setName(event.getName());
            }
        }
        if (event.getOrganizerSchedulingObject()) {
            // Set RSVP on all attendees with PARTSTAT = NEEDS_ACTION
            for (final BwAttendee att : event.getAttendees()) {
                if (att.getPartstat() == IcalDefs.partstatValNeedsAction) {
                    att.setRsvp(true);
                }
            }
        }
        UpdateEventResult uer = getCal().addEvent(ei, schedulingInbox, rollbackOnError);
        if (ei.getNumContainedItems() > 0) {
            for (final EventInfo oei : ei.getContainedItems()) {
                oei.getEvent().setName(event.getName());
                final UpdateEventResult auer = getCal().addEvent(oei, schedulingInbox, rollbackOnError);
                if (auer.errorCode != null) {
                // ?
                }
            }
        }
        updResult.failedOverrides = uer.failedOverrides;
        if (!noInvites) {
            if (event.getAttendeeSchedulingObject()) {
                // Attendee replying?
                updResult.reply = true;
            }
            if (cal.getCollectionInfo().scheduling && schedulingObject) {
                final SchedulingIntf sched = (SchedulingIntf) getSvc().getScheduler();
                sched.implicitSchedule(ei, false);
            /* We assume we don't need to update again to set attendee status
           * Trying to do an update results in duplicate key errors.
           *
           * If it turns out the scgedule status is not getting persisted in the
           * calendar entry then we need to find a way to set just that value in
           * already persisted entity.
           */
            }
        }
        return updResult;
    } catch (final Throwable t) {
        if (debug) {
            error(t);
        }
        getSvc().rollbackTransaction();
        if (t instanceof CalFacadeException) {
            throw (CalFacadeException) t;
        }
        throw new CalFacadeException(t);
    }
}
Also used : BwPreferences(org.bedework.calfacade.svc.BwPreferences) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) EventInfo(org.bedework.calfacade.svc.EventInfo) BwCategory(org.bedework.calfacade.BwCategory) CalFacadeForbidden(org.bedework.calfacade.exc.CalFacadeForbidden) BwEvent(org.bedework.calfacade.BwEvent) SchedulingIntf(org.bedework.calsvc.scheduling.SchedulingIntf) BwCalendar(org.bedework.calfacade.BwCalendar) BwEventProxy(org.bedework.calfacade.BwEventProxy) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BwEventAnnotation(org.bedework.calfacade.BwEventAnnotation) BwAttendee(org.bedework.calfacade.BwAttendee) UpdateResult(org.bedework.calfacade.svc.EventInfo.UpdateResult) UpdateEventResult(org.bedework.calcorei.CoreEventsI.UpdateEventResult)

Example 15 with BwEvent

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

the class Events method makeInstance.

private EventInfo makeInstance(final EventInfo ei, final String recurrenceId) throws CalFacadeException {
    final BwEvent ev = ei.getEvent();
    if (!ev.getRecurring()) {
        return ei;
    }
    if (!Util.isEmpty(ei.getOverrides())) {
        for (final EventInfo oei : ei.getOverrides()) {
            if (oei.getEvent().getRecurrenceId().equals(recurrenceId)) {
                oei.setRetrievedEvent(ei);
                oei.setCurrentAccess(ei.getCurrentAccess());
                return oei;
            }
        }
    }
    /* Not in the overrides - generate an instance */
    final BwDateTime rstart;
    final boolean dateOnly = ev.getDtstart().getDateType();
    if (dateOnly) {
        rstart = BwDateTime.makeBwDateTime(true, recurrenceId.substring(0, 8), null);
    } else {
        final String stzid = ev.getDtstart().getTzid();
        DateTime dt = null;
        try {
            dt = new DateTime(recurrenceId);
        } catch (final ParseException pe) {
            throw new CalFacadeException(pe);
        }
        final DtStart ds = ev.getDtstart().makeDtStart();
        dt.setTimeZone(ds.getTimeZone());
        rstart = BwDateTime.makeBwDateTime(dt);
    }
    final BwDateTime rend = rstart.addDuration(BwDuration.makeDuration(ev.getDuration()));
    final BwEventAnnotation ann = new BwEventAnnotation();
    ann.setDtstart(rstart);
    ann.setDtend(rend);
    ann.setRecurrenceId(recurrenceId);
    ann.setOwnerHref(ev.getOwnerHref());
    // Call it an override
    ann.setOverride(true);
    ann.setTombstoned(false);
    ann.setName(ev.getName());
    ann.setUid(ev.getUid());
    ann.setTarget(ev);
    ann.setMaster(ev);
    BwEvent proxy = new BwEventProxy(ann);
    EventInfo oei = new EventInfo(proxy);
    oei.setCurrentAccess(ei.getCurrentAccess());
    oei.setRetrievedEvent(ei);
    return oei;
}
Also used : DtStart(net.fortuna.ical4j.model.property.DtStart) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) EventInfo(org.bedework.calfacade.svc.EventInfo) BwDateTime(org.bedework.calfacade.BwDateTime) BwEventAnnotation(org.bedework.calfacade.BwEventAnnotation) BwEvent(org.bedework.calfacade.BwEvent) ParseException(java.text.ParseException) BwEventProxy(org.bedework.calfacade.BwEventProxy) DateTime(net.fortuna.ical4j.model.DateTime) BwDateTime(org.bedework.calfacade.BwDateTime) 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