Search in sources :

Example 1 with BwEventAnnotation

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

the class EventFieldRule method field.

@Override
public void field(final String name) throws Exception {
    if (skippedNames.contains(name)) {
        return;
    }
    DateTimeValues dtv = null;
    if (top() instanceof DateTimeValues) {
        dtv = (DateTimeValues) pop();
    }
    EventInfo ei = (EventInfo) getTop(EventInfo.class, name);
    BwEventAnnotation ann = null;
    BwEvent e = ei.getEvent();
    if (e instanceof BwEventProxy) {
        ann = ((BwEventProxy) e).getRef();
    // e = ann;
    }
    if (shareableContainedEntityTags(e, name)) {
        return;
    }
    try {
        if (name.equals("emptyFlags")) {
            char[] flags = stringFld().toCharArray();
            for (char c : flags) {
                if ((c != 'T') && (c != 'F')) {
                    error("Bad empty flags '" + stringFld() + "' for event " + ann);
                }
            }
            ann.setEmptyFlags(new String(flags));
        /* ------------------- Start/end --------------------------- */
        } else if (name.equals("noStart")) {
            if (ann != null) {
                ann.setNoStart(booleanFld());
            } else {
                e.setNoStart(booleanFld());
            }
        } else if (name.equals("dtstart")) {
            if (ann != null) {
                ann.setDtstart(dateTimeFld(dtv));
            } else {
                e.setDtstart(dateTimeFld(dtv));
            }
        } else if (name.equals("dtend")) {
            if (ann != null) {
                ann.setDtend(dateTimeFld(dtv));
            } else {
                e.setDtend(dateTimeFld(dtv));
            }
        } else if (name.equals("duration")) {
            // XXX Fix bad duration value due to old bug
            String dur = stringFld();
            char endType = e.getEndType();
            if ("PT1S".equals(dur) && (endType == StartEndComponent.endTypeNone)) {
                dur = "PT0S";
            }
            if (ann != null) {
                ann.setDuration(dur);
            } else {
                e.setDuration(dur);
            }
        } else if (name.equals("endType")) {
            if (ann != null) {
                ann.setEndType(charFld());
            } else {
                e.setEndType(charFld());
            }
        } else if (name.equals("entityType")) {
            e.setEntityType(intFld());
        } else if (name.equals("name")) {
            if (ann != null) {
                ann.setName(stringFld());
            } else {
                e.setName(stringFld());
            }
        } else if (name.equals("uid")) {
            if (ann != null) {
                ann.setUid(stringFld());
            } else {
                e.setUid(stringFld());
            }
        } else if (name.equals("classification")) {
            e.setClassification(stringFld());
        } else if (name.equals("link")) {
            e.setLink(stringFld());
        } else if (name.equals("geo-latitude")) {
            BwGeo geo = e.getGeo();
            if (geo == null) {
                geo = new BwGeo();
                e.setGeo(geo);
            }
            // geo.setLatitude(bigDecimalFld());
            geo.setLatitude(bigDecimalFld());
        } else if (name.equals("geo-longitude")) {
            BwGeo geo = e.getGeo();
            if (geo == null) {
                geo = new BwGeo();
                e.setGeo(geo);
            }
            // geo.setLongitude(bigDecimalFld());
            geo.setLongitude(bigDecimalFld());
        } else if (name.equals("status")) {
            String status = stringFld();
            if ((status != null) && (!status.equals("F"))) {
                // 2.3.2
                e.setStatus(status);
            }
        } else if (name.equals("cost")) {
            e.setCost(stringFld());
        } else if (name.equals("deleted")) {
            e.setDeleted(booleanFld());
        } else if (name.equals("tombstoned")) {
            e.setTombstoned(booleanFld());
        } else if (name.equals("dtstamp")) {
            e.setDtstamp(stringFld());
        } else if (name.equals("lastmod")) {
            e.setLastmod(stringFld());
        } else if (name.equals("created")) {
            e.setCreated(stringFld());
        } else if (name.equals("byteSize")) {
            e.setByteSize(intFld());
        } else if (name.equals("priority")) {
            e.setPriority(integerFld());
        } else if (name.equals("transparency")) {
            e.setTransparency(stringFld());
        } else if (name.equals("relatedTo")) {
        // e.setRelatedTo(stringFld());
        } else if (name.equals("percentComplete")) {
            e.setPercentComplete(integerFld());
        } else if (name.equals("completed")) {
            e.setCompleted(stringFld());
        } else if (name.equals("ctoken")) {
            e.setCtoken(stringFld());
        /* --------------- Recurrence fields ---------------------- */
        } else if (name.equals("recurring")) {
            e.setRecurring(new Boolean(booleanFld()));
        } else if (name.equals("rrule")) {
            e.addRrule(stringFld());
        } else if (name.equals("exrule")) {
            e.addExrule(stringFld());
        } else if (name.equals("rdate")) {
            e.addRdate(dateTimeFld(dtv));
        } else if (name.equals("exdate")) {
            e.addExdate(dateTimeFld(dtv));
        } else if (name.equals("recurrenceId")) {
            e.setRecurrenceId(stringFld());
        } else if (name.equals("latestDate")) {
            e.setCtoken(stringFld());
        /* --------------- Scheduling fields ---------------------- */
        } else if (name.equals("organizer")) {
        // pre 3.5
        } else if (name.equals("sequence")) {
            e.setSequence(intFld());
        } else if (name.equals("scheduleMethod")) {
            e.setScheduleMethod(intFld());
        } else if (name.equals("originator")) {
            e.setOriginator(stringFld());
        } else if (name.equals("recipient")) {
            e.addRecipient(stringFld());
        } else if (name.equals("scheduleState")) {
            e.setScheduleState(intFld());
        } else if (name.equals("organizerSchedulingObject")) {
            e.setOrganizerSchedulingObject(booleanFld());
        } else if (name.equals("attendeeSchedulingObject")) {
            e.setAttendeeSchedulingObject(booleanFld());
        } else if (name.equals("stag")) {
            e.setStag(stringFld());
        /* ------------------- vavailability --------------------------- */
        } else if (name.equals("busyType")) {
            e.setBusyType(intFld());
        /* ------------------- vpoll --------------------------- */
        } else if (name.equals("pollCandidate")) {
            e.setPollCandidate(booleanFld());
        } else {
            unknownTag(name);
        }
    } catch (Exception ex) {
        error("Error processing event uid " + e.getUid(), ex);
        globals.entityError = true;
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) BwEventAnnotation(org.bedework.calfacade.BwEventAnnotation) BwGeo(org.bedework.calfacade.BwGeo) BwEvent(org.bedework.calfacade.BwEvent) BwEventProxy(org.bedework.calfacade.BwEventProxy)

Example 2 with BwEventAnnotation

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

the class EventRule method begin.

@Override
public void begin(final String ns, final String name, final Attributes att) throws Exception {
    super.begin(ns, kind, att);
    BwEvent ev = (BwEvent) pop();
    boolean override = (kind.equals(objectOverride));
    if (ev instanceof BwEventAnnotation) {
        BwEventAnnotation ann = (BwEventAnnotation) ev;
        ann.setOverride(override);
        ev = new BwEventProxy(ann);
        if (override) {
            /* The override is embedded in the event so the top() should be the master
         * Annotations will get the master and target set later.
         */
            EventInfo mei = (EventInfo) top();
            ann.setTarget(mei.getEvent());
            ann.setMaster(mei.getEvent());
        } else {
            /* Make up empty event object for us to fill in */
            BwEvent e = new BwEventObj();
            ann.setTarget(e);
            ann.setMaster(e);
        }
    } else if (override) {
        error("Restore error - override but not annotation.");
    }
    EventInfo ei = new EventInfo(ev);
    /* Initialise fields that may be missed when restoring earlier data */
    ev.setNoStart(false);
    push(ei);
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) BwEventAnnotation(org.bedework.calfacade.BwEventAnnotation) BwEvent(org.bedework.calfacade.BwEvent) BwEventProxy(org.bedework.calfacade.BwEventProxy) BwEventObj(org.bedework.calfacade.BwEventObj)

Example 3 with BwEventAnnotation

use of org.bedework.calfacade.BwEventAnnotation 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 4 with BwEventAnnotation

use of org.bedework.calfacade.BwEventAnnotation 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 5 with BwEventAnnotation

use of org.bedework.calfacade.BwEventAnnotation 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)

Aggregations

BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)27 BwEvent (org.bedework.calfacade.BwEvent)22 BwEventProxy (org.bedework.calfacade.BwEventProxy)19 EventInfo (org.bedework.calfacade.svc.EventInfo)15 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)10 BwDateTime (org.bedework.calfacade.BwDateTime)8 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)7 BwRecurrenceInstance (org.bedework.calfacade.BwRecurrenceInstance)6 BwCalendar (org.bedework.calfacade.BwCalendar)5 Dur (net.fortuna.ical4j.model.Dur)4 ArrayList (java.util.ArrayList)3 TreeSet (java.util.TreeSet)3 DateTime (net.fortuna.ical4j.model.DateTime)3 SearchResponse (org.elasticsearch.action.search.SearchResponse)3 SearchHit (org.elasticsearch.search.SearchHit)3 Period (net.fortuna.ical4j.model.Period)2 TimeZone (net.fortuna.ical4j.model.TimeZone)2 DtStart (net.fortuna.ical4j.model.property.DtStart)2 CurrentAccess (org.bedework.access.Acl.CurrentAccess)2 HibSession (org.bedework.calcorei.HibSession)2