Search in sources :

Example 26 with BwXproperty

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

the class Events method setDefaultAlarms.

private void setDefaultAlarms(final EventInfo ei, final BwCalendar col) throws CalFacadeException {
    BwEvent event = ei.getEvent();
    boolean isEvent = event.getEntityType() == IcalDefs.entityTypeEvent;
    boolean isTask = event.getEntityType() == IcalDefs.entityTypeTodo;
    if (!isEvent && !isTask) {
        return;
    }
    /* This test was wrong - we need to test the alarm for compatability with
     * the task/event
     */
    // if (isTask && (event.getNoStart())) {
    // return;
    // }
    boolean isDate = event.getDtstart().getDateType();
    String al = getDefaultAlarmDef(col, isEvent, isDate);
    if (al == null) {
        // Get the user home and try that
        al = getDefaultAlarmDef(getCols().getHome(), isEvent, isDate);
    }
    if ((al == null) || (al.length() == 0)) {
        return;
    }
    Set<BwAlarm> alarms = compileAlarms(al);
    if (alarms == null) {
        return;
    }
    for (BwAlarm alarm : alarms) {
        /* XXX At this point we should test to see if this alarm can be added -
       * e.g. we should not add an alarm triggered off start to a task with no
       * start
       */
        alarm.addXproperty(new BwXproperty(BwXproperty.appleDefaultAlarm, null, "TRUE"));
        event.addAlarm(alarm);
        ei.getChangeset(getPrincipalHref()).addValue(PropertyInfoIndex.VALARM, alarm);
    }
}
Also used : BwXproperty(org.bedework.calfacade.BwXproperty) BwEvent(org.bedework.calfacade.BwEvent) BwAlarm(org.bedework.calfacade.BwAlarm)

Example 27 with BwXproperty

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

the class EventInfo method getDeletedOverrideProxies.

/**
 * @param userHref
 * @return Collection of deleted override proxy events or null
 * @throws CalFacadeException
 */
public Collection<BwEventProxy> getDeletedOverrideProxies(final String userHref) throws CalFacadeException {
    TreeSet<BwEventProxy> proxies = new TreeSet<>();
    if ((retrievedOverrides == null) || instanceOnly) {
        return proxies;
    }
    for (EventOverride eo : retrievedOverrides) {
        if (overrides.contains(eo)) {
            continue;
        }
        BwEventProxy proxy = (BwEventProxy) eo.getEvent();
        if (proxy.getRef().unsaved()) {
            throw new RuntimeException("Unsaved override in delete list");
        }
        if (proxy.getXproperty(BwXproperty.peruserInstance) == null) {
            /* Not peruser - remove it. */
            proxies.add(proxy);
            continue;
        }
        BwXproperty pu = proxy.findPeruserXprop(userHref, BwXproperty.peruserPropTransp);
        if (pu != null) {
            /* remove it */
            proxy.removeXproperty(pu);
        }
        /* Remove any alarm(s) */
        List<BwAlarm> toRemove = new ArrayList<>();
        for (BwAlarm a : proxy.getAlarms()) {
            if (a.getOwnerHref().equals(userHref)) {
                toRemove.add(a);
            }
        }
        for (BwAlarm a : toRemove) {
            proxy.removeAlarm(a);
        }
        if (Util.isEmpty(proxy.getXproperties(BwXproperty.peruserPropTransp)) && Util.isEmpty(proxy.getAlarms())) {
            /* No more peruser data - add to remove list */
            proxies.add(proxy);
        }
        /* Update the changes */
        ChangeTable chg = getChangeset(userHref);
        if (pu != null) {
            chg.addValue(PropertyInfoIndex.XPROP, pu);
        }
        if (!Util.isEmpty(toRemove)) {
            for (BwAlarm a : toRemove) {
                chg.addValue(PropertyInfoIndex.VALARM, a);
            }
        }
    }
    return proxies;
}
Also used : BwXproperty(org.bedework.calfacade.BwXproperty) TreeSet(java.util.TreeSet) ChangeTable(org.bedework.calfacade.util.ChangeTable) ArrayList(java.util.ArrayList) BwEventProxy(org.bedework.calfacade.BwEventProxy) BwAlarm(org.bedework.calfacade.BwAlarm)

Example 28 with BwXproperty

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

the class SchedulingBase method setChangeInfo.

private void setChangeInfo(final BwEvent ev, final StringBuilder changeInfo) {
    if (changeInfo.length() == 0) {
        return;
    }
    ev.removeXproperties(BwXproperty.bedeworkChanges);
    ev.addXproperty(new BwXproperty(BwXproperty.bedeworkChanges, null, changeInfo.toString()));
}
Also used : BwXproperty(org.bedework.calfacade.BwXproperty)

Example 29 with BwXproperty

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

the class InRequest method process.

/**
 * @param ei
 * @return ScheduleResult
 * @throws CalFacadeException
 */
@Override
public ProcessResult process(final EventInfo ei) throws CalFacadeException {
    /* We are acting as an attendee getting a request from the organizer, either
     * a first invitation or an update
     */
    ProcessResult pr = new ProcessResult();
    BwPreferences prefs = getSvc().getPrefsHandler().get();
    BwEvent ev = ei.getEvent();
    String owner = ev.getOwnerHref();
    boolean schedAssistant = ev.isSchedulingAssistant();
    if (debug) {
        trace("InSchedule schedAssistant = " + schedAssistant);
    }
    /* First we save or update the event in the users default scheduling calendar
     */
    SchedulingIntf sched = (SchedulingIntf) getSvc().getScheduler();
    String uri = getSvc().getDirectories().principalToCaladdr(getSvc().getPrincipal());
    String colPath = null;
    EventInfo ourCopy = null;
    boolean adding = false;
    ev.setAttendeeSchedulingObject(true);
    ev.setOrganizerSchedulingObject(false);
    check: {
        ourCopy = sched.getStoredMeeting(ev);
        if (ourCopy != null) {
            if (debug) {
                trace("InSchedule update for " + owner);
            }
            colPath = ourCopy.getEvent().getColPath();
            final boolean vpoll = ev.getEntityType() == IcalDefs.entityTypeVpoll;
            if (vpoll) {
                if (!updateAttendeePollCopy(ourCopy, ei, uri)) {
                    break check;
                }
            } else if (!updateAttendeeCopy(ourCopy, ei, uri)) {
                break check;
            }
            pr.removeInboxEntry = !anySignificantChange(ourCopy);
        } else {
            /* New invitation - Save in default */
            adding = true;
            if (debug) {
                trace("InSchedule add for " + owner);
            }
            String prefSched = getSvc().getCalendarsHandler().getPreferred(IcalDefs.entityTypeIcalNames[ev.getEntityType()]);
            if (prefSched == null) {
                // SCHED - status = no default collection
                if (debug) {
                    trace("InSchedule - no default collection for " + owner);
                }
                // XXX set error code in request status
                pr.removeInboxEntry = true;
                return pr;
            }
            ourCopy = newAttendeeCopy(getSvc(), prefSched, ei, uri);
            if (ourCopy == null) {
                if (debug) {
                    trace("InSchedule - unable to add to calendar for " + owner);
                }
                // XXX set error code in request status
                pr.removeInboxEntry = true;
                return pr;
            }
            ev.addXproperty(new BwXproperty(BwXproperty.bedeworkSchedulingNew, null, "true"));
            pr.removeInboxEntry = false;
        }
    }
    if (schedAssistant) {
        // Don't need the notification
        pr.removeInboxEntry = true;
    }
    ev.addXproperty(new BwXproperty(BwXproperty.bedeworkSchedulingEntityPath, null, colPath));
    /* We've saved it in the users calendar - now see if they want to auto
     * respond.
     */
    boolean noInvites = true;
    boolean doAutoRespond = !pr.removeInboxEntry && !schedAssistant && prefs.getScheduleAutoRespond();
    if (doAutoRespond) {
        if (debug) {
            trace("InSchedule - auto responding for " + owner);
        }
        noInvites = !autoRespond(getSvc(), ourCopy, ei, prefs.getScheduleDoubleBook(), uri);
    }
    if (adding) {
        final String namePrefix = ourCopy.getEvent().getUid();
        pr.sr.errorCode = sched.addEvent(ourCopy, namePrefix, BwCalendar.calTypeCalendarCollection, noInvites);
        if (pr.sr.errorCode != null) {
            if (debug) {
                trace("Schedule - error " + pr.sr.errorCode + " adding event for " + owner);
            }
            return pr;
        }
    } else {
        final UpdateResult ur = getSvc().getEventsHandler().update(ourCopy, noInvites, null);
        if (debug) {
            trace("Schedule - update result " + pr.sr + " for event" + ourCopy.getEvent());
        }
        if (ur.schedulingResult != null) {
            pr.sr = ur.schedulingResult;
        }
    }
    pr.attendeeAccepting = !Util.isEmpty(ev.getXproperties(BwXproperty.bedeworkSchedulingReplyUpdate));
    return pr;
}
Also used : BwPreferences(org.bedework.calfacade.svc.BwPreferences) EventInfo(org.bedework.calfacade.svc.EventInfo) BwXproperty(org.bedework.calfacade.BwXproperty) BwEvent(org.bedework.calfacade.BwEvent) SchedulingIntf(org.bedework.calsvc.scheduling.SchedulingIntf) BwString(org.bedework.calfacade.BwString) UpdateResult(org.bedework.calfacade.svc.EventInfo.UpdateResult)

Example 30 with BwXproperty

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

the class ProcessRealias method doRealias.

private int doRealias(final EventInfo ei, final String fromHref, final BwXproperty xp, final boolean add, final boolean remove) throws Throwable {
    final BwEvent ev = ei.getEvent();
    int updated = 0;
    boolean changed = false;
    if (!add) {
        // We need to remove the from alias
        boolean found = false;
        for (final BwXproperty xpi : ev.getXproperties(BwXproperty.bedeworkAlias)) {
            if (xpi.getValue().equals(fromHref)) {
                ev.removeXproperty(xpi);
                found = true;
                changed = true;
                break;
            }
        }
        if (!found) {
            warn("Unable to find " + fromHref);
        }
    }
    if (!remove) {
        // Need to add a new one.
        ev.addXproperty(xp);
        changed = true;
    }
    final RealiasResult resp = getSvci().getEventsHandler().reAlias(ei.getEvent());
    if (resp.getStatus() != ok) {
        warn("Status from reAlias was " + resp.getStatus() + " message was " + resp.getMessage());
        return 0;
    }
    if (!add) {
        // Remove all the categories for the from alias
        final Set<BwCategory> fromCats = getCols().getCategorySet(fromHref);
        if (!Util.isEmpty(fromCats) && !Util.isEmpty(ev.getCategories())) {
            for (final BwCategory cat : fromCats) {
                if (ev.getCategories().remove(cat)) {
                    changed = true;
                }
            }
        }
    }
    /* Now we need to adjust for the new alias
     */
    final Set<BwCategory> cats = resp.getCats();
    if (!Util.isEmpty(cats)) {
        for (final BwCategory cat : cats) {
            ev.addCategory(cat);
        }
        changed = true;
    }
    ei.clearChangeset();
    final EventInfo.UpdateResult ur = getSvci().getEventsHandler().update(ei, true);
    if (ur.hasChanged) {
        updated++;
    }
    if (!Util.isEmpty(ei.getOverrides())) {
        for (final EventInfo ovei : ei.getOverrides()) {
            updated += doRealias(ovei, fromHref, xp, add, remove);
        }
    }
    return updated;
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) BwXproperty(org.bedework.calfacade.BwXproperty) BwCategory(org.bedework.calfacade.BwCategory) BwEvent(org.bedework.calfacade.BwEvent) RealiasResult(org.bedework.calsvci.EventsI.RealiasResult)

Aggregations

BwXproperty (org.bedework.calfacade.BwXproperty)30 BwEvent (org.bedework.calfacade.BwEvent)16 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)11 BwString (org.bedework.calfacade.BwString)9 EventInfo (org.bedework.calfacade.svc.EventInfo)9 BwCategory (org.bedework.calfacade.BwCategory)7 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)7 BwAlarm (org.bedework.calfacade.BwAlarm)5 BwAttendee (org.bedework.calfacade.BwAttendee)5 BwContact (org.bedework.calfacade.BwContact)5 BwEventProxy (org.bedework.calfacade.BwEventProxy)5 PropertyList (net.fortuna.ical4j.model.PropertyList)4 BwLocation (org.bedework.calfacade.BwLocation)4 ChangeTable (org.bedework.calfacade.util.ChangeTable)4 TreeSet (java.util.TreeSet)3 Property (net.fortuna.ical4j.model.Property)3 VEvent (net.fortuna.ical4j.model.component.VEvent)3 VPoll (net.fortuna.ical4j.model.component.VPoll)3 VToDo (net.fortuna.ical4j.model.component.VToDo)3 Uid (net.fortuna.ical4j.model.property.Uid)3