Search in sources :

Example 1 with ChangeTable

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

the class Events method setScheduleState.

/* Flag this as an attendee scheduling object or an organizer scheduling object
   */
private void setScheduleState(final BwEvent ev, final boolean adding, final boolean schedulingInbox) throws CalFacadeException {
    ev.setOrganizerSchedulingObject(false);
    ev.setAttendeeSchedulingObject(false);
    if ((ev.getEntityType() != IcalDefs.entityTypeEvent) && (ev.getEntityType() != IcalDefs.entityTypeTodo) && (ev.getEntityType() != IcalDefs.entityTypeVpoll)) {
        // Not a possible scheduling entity
        return;
    }
    final BwOrganizer org = ev.getOrganizer();
    final Set<BwAttendee> atts = ev.getAttendees();
    if (Util.isEmpty(atts) || (org == null)) {
        return;
    }
    final String curPrincipal = getSvc().getPrincipal().getPrincipalRef();
    final Directories dirs = getSvc().getDirectories();
    AccessPrincipal evPrincipal = dirs.caladdrToPrincipal(org.getOrganizerUri());
    if ((evPrincipal != null) && (evPrincipal.getPrincipalRef().equals(curPrincipal))) {
        ev.setOrganizerSchedulingObject(true);
        /* If we are expanding groups do so here */
        final ChangeTable chg = ev.getChangeset(getPrincipalHref());
        final Set<BwAttendee> groups = new TreeSet<>();
        if (!schedulingInbox) {
            final ChangeTableEntry cte = chg.getEntry(PropertyInfoIndex.ATTENDEE);
            checkAttendees: for (final BwAttendee att : atts) {
                if (CuType.GROUP.getValue().equals(att.getCuType())) {
                    groups.add(att);
                }
                final AccessPrincipal attPrincipal = getSvc().getDirectories().caladdrToPrincipal(att.getAttendeeUri());
                if ((attPrincipal != null) && (attPrincipal.getPrincipalRef().equals(curPrincipal))) {
                    // It's us
                    continue;
                }
                if (att.getPartstat().equals(IcalDefs.partstatValNeedsAction)) {
                    continue;
                }
                if (adding) {
                    // Can't add an event with attendees set to accepted
                    att.setPartstat(IcalDefs.partstatValNeedsAction);
                    continue;
                }
                // Not adding event. Did we add attendee?
                if ((cte != null) && !Util.isEmpty(cte.getAddedValues())) {
                    for (final Object o : cte.getAddedValues()) {
                        final BwAttendee chgAtt = (BwAttendee) o;
                        if (chgAtt.getCn().equals(att.getCn())) {
                            att.setPartstat(IcalDefs.partstatValNeedsAction);
                            continue checkAttendees;
                        }
                    }
                }
            }
        }
        try {
            /* If this is a vpoll we need the vvoters as we are going to
           have to remove the group vvoter entry and clone it for the
           attendees we add.

           I think this will work for any poll mode - if not we may
           have to rethink this approach.
         */
            Map<String, VVoter> voters = null;
            final boolean vpoll;
            if (ev.getEntityType() == IcalDefs.entityTypeVpoll) {
                voters = IcalUtil.parseVpollVvoters(ev);
                // We'll add them all back
                ev.clearVvoters();
                vpoll = true;
            } else {
                vpoll = false;
            }
            for (final BwAttendee att : groups) {
                /* If the group is in one of our domains we can try to expand it.
           * We should leave it if it's an external id.
           */
                final Holder<Boolean> trunc = new Holder<>();
                final List<BwPrincipalInfo> groupPis = dirs.find(att.getAttendeeUri(), att.getCuType(), // expand
                true, trunc);
                if ((groupPis == null) || (groupPis.size() != 1)) {
                    continue;
                }
                final BwPrincipalInfo pi = groupPis.get(0);
                if (pi.getMembers() == null) {
                    continue;
                }
                VVoter groupVvoter = null;
                Voter groupVoter = null;
                PropertyList pl = null;
                if (vpoll) {
                    groupVvoter = voters.get(att.getAttendeeUri());
                    if (groupVvoter == null) {
                        if (debug) {
                            warn("No vvoter found for " + att.getAttendeeUri());
                        }
                        continue;
                    }
                    voters.remove(att.getAttendeeUri());
                    groupVoter = groupVvoter.getVoter();
                    pl = groupVvoter.getProperties();
                }
                // Remove the group
                ev.removeAttendee(att);
                chg.changed(PropertyInfoIndex.ATTENDEE, att, null);
                for (final BwPrincipalInfo mbrPi : pi.getMembers()) {
                    if (mbrPi.getCaladruri() == null) {
                        continue;
                    }
                    final BwAttendee mbrAtt = new BwAttendee();
                    mbrAtt.setType(att.getType());
                    mbrAtt.setAttendeeUri(mbrPi.getCaladruri());
                    mbrAtt.setCn(mbrPi.getEmail());
                    mbrAtt.setCuType(mbrPi.getKind());
                    mbrAtt.setMember(att.getAttendeeUri());
                    ev.addAttendee(mbrAtt);
                    chg.addValue(PropertyInfoIndex.ATTENDEE, mbrAtt);
                    if (vpoll) {
                        pl.remove(groupVoter);
                        groupVoter = IcalUtil.setVoter(mbrAtt);
                        pl.add(groupVoter);
                        ev.addVvoter(groupVvoter.toString());
                    }
                }
            }
            if (vpoll) {
                // Add back any remaining vvoters
                for (VVoter vv : voters.values()) {
                    ev.addVvoter(vv.toString());
                }
            }
        } catch (final CalFacadeException cfe) {
            throw cfe;
        } catch (final Throwable t) {
            throw new CalFacadeException(t);
        }
        if (ev instanceof BwEventProxy) {
            // Only add x-property to master
            return;
        }
        if (CalFacadeDefs.jasigSchedulingAssistant.equals(getPars().getClientId())) {
            ev.addXproperty(new BwXproperty(BwXproperty.bedeworkSchedAssist, null, "true"));
        }
        return;
    }
    for (final BwAttendee att : atts) {
        /* See if at least one attendee is us */
        evPrincipal = getSvc().getDirectories().caladdrToPrincipal(att.getAttendeeUri());
        if ((evPrincipal != null) && (evPrincipal.getPrincipalRef().equals(curPrincipal))) {
            ev.setAttendeeSchedulingObject(true);
            break;
        }
    }
}
Also used : VVoter(net.fortuna.ical4j.model.component.VVoter) Holder(javax.xml.ws.Holder) BwEventProxy(org.bedework.calfacade.BwEventProxy) AccessPrincipal(org.bedework.access.AccessPrincipal) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) Directories(org.bedework.calfacade.ifs.Directories) PropertyList(net.fortuna.ical4j.model.PropertyList) BwXproperty(org.bedework.calfacade.BwXproperty) ChangeTable(org.bedework.calfacade.util.ChangeTable) TreeSet(java.util.TreeSet) Voter(net.fortuna.ical4j.model.property.Voter) VVoter(net.fortuna.ical4j.model.component.VVoter) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) BwAttendee(org.bedework.calfacade.BwAttendee) BwPrincipalInfo(org.bedework.calfacade.BwPrincipalInfo) BwOrganizer(org.bedework.calfacade.BwOrganizer)

Example 2 with ChangeTable

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

the class BwEventUtil method makeNewEvent.

private static EventInfo makeNewEvent(final IcalCallback cb, final int entityType, final String uid, final String colPath) throws CalFacadeException {
    final BwEvent ev = new BwEventObj();
    final EventInfo evinfo = new EventInfo(ev);
    // ev.setDtstamps();
    ev.setEntityType(entityType);
    ev.setCreatorHref(cb.getPrincipal().getPrincipalRef());
    ev.setOwnerHref(cb.getOwner().getPrincipalRef());
    ev.setUid(uid);
    ev.setColPath(colPath);
    final ChangeTable chg = evinfo.getChangeset(cb.getPrincipal().getPrincipalRef());
    // get that out of the way
    chg.changed(PropertyInfoIndex.UID, null, uid);
    evinfo.setNewEvent(true);
    return evinfo;
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) ChangeTable(org.bedework.calfacade.util.ChangeTable) BwEvent(org.bedework.calfacade.BwEvent) BwEventObj(org.bedework.calfacade.BwEventObj)

Example 3 with ChangeTable

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

the class BwFreeBusyUtil method toFreeBusy.

/**
 * @param cb
 * @param val
 * @return BwFreeBusy
 * @throws CalFacadeException
 */
public static EventInfo toFreeBusy(final IcalCallback cb, final VFreeBusy val) throws CalFacadeException {
    if (val == null) {
        return null;
    }
    boolean debug = getLog().isDebugEnabled();
    try {
        PropertyList pl = val.getProperties();
        if (pl == null) {
            // Empty VEvent
            return null;
        }
        BwEvent fb = new BwEventObj();
        EventInfo ei = new EventInfo(fb);
        ChangeTable chg = ei.getChangeset(cb.getPrincipal().getPrincipalRef());
        fb.setEntityType(IcalDefs.entityTypeFreeAndBusy);
        setDates(cb.getPrincipal().getPrincipalRef(), ei, (DtStart) pl.getProperty(Property.DTSTART), (DtEnd) pl.getProperty(Property.DTEND), (Duration) pl.getProperty(Property.DURATION));
        Iterator it = pl.iterator();
        while (it.hasNext()) {
            Property prop = (Property) it.next();
            String pval = prop.getValue();
            if ((pval != null) && (pval.length() == 0)) {
                pval = null;
            }
            PropertyInfoIndex pi = PropertyInfoIndex.fromName(prop.getName());
            if (pi == null) {
                debugMsg("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval);
                continue;
            }
            switch(pi) {
                case ATTENDEE:
                    /* ------------------- Attendee -------------------- */
                    BwAttendee att = getAttendee(cb, (Attendee) prop);
                    fb.addAttendee(att);
                    chg.addValue(pi, att);
                    break;
                case COMMENT:
                    /* ------------------- Comment -------------------- */
                    // LANG
                    fb.addComment(null, pval);
                    chg.addValue(pi, pval);
                case DTEND:
                    break;
                case DTSTAMP:
                    /* ------------------- DtStamp -------------------- */
                    chg.changed(pi, fb.getDtstamp(), pval);
                    fb.setDtstamp(pval);
                case DTSTART:
                    break;
                case FREEBUSY:
                    /* ------------------- freebusy -------------------- */
                    FreeBusy fbusy = (FreeBusy) prop;
                    PeriodList perpl = fbusy.getPeriods();
                    Parameter par = getParameter(fbusy, "FBTYPE");
                    int fbtype;
                    if (par == null) {
                        fbtype = BwFreeBusyComponent.typeBusy;
                    } else if (par.equals(FbType.BUSY)) {
                        fbtype = BwFreeBusyComponent.typeBusy;
                    } else if (par.equals(FbType.BUSY_TENTATIVE)) {
                        fbtype = BwFreeBusyComponent.typeBusyTentative;
                    } else if (par.equals(FbType.BUSY_UNAVAILABLE)) {
                        fbtype = BwFreeBusyComponent.typeBusyUnavailable;
                    } else if (par.equals(FbType.FREE)) {
                        fbtype = BwFreeBusyComponent.typeFree;
                    } else {
                        if (debug) {
                            debugMsg("Unsupported parameter " + par.getName());
                        }
                        throw new IcalMalformedException("parameter " + par.getName());
                    }
                    BwFreeBusyComponent fbc = new BwFreeBusyComponent();
                    fbc.setType(fbtype);
                    Iterator perit = perpl.iterator();
                    while (perit.hasNext()) {
                        Period per = (Period) perit.next();
                        fbc.addPeriod(per);
                    }
                    fb.addFreeBusyPeriod(fbc);
                    chg.addValue(pi, fbc);
                    break;
                case ORGANIZER:
                    /* ------------------- Organizer -------------------- */
                    BwOrganizer org = getOrganizer(cb, (Organizer) prop);
                    fb.setOrganizer(org);
                    chg.addValue(pi, org);
                    break;
                case UID:
                    /* ------------------- Uid -------------------- */
                    chg.changed(pi, fb.getUid(), pval);
                    fb.setUid(pval);
                    break;
                default:
                    if (debug) {
                        debugMsg("Unsupported property with class " + prop.getClass() + " and value " + pval);
                    }
            }
        }
        return ei;
    } catch (CalFacadeException cfe) {
        throw cfe;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : BwFreeBusyComponent(org.bedework.calfacade.BwFreeBusyComponent) EventInfo(org.bedework.calfacade.svc.EventInfo) VFreeBusy(net.fortuna.ical4j.model.component.VFreeBusy) FreeBusy(net.fortuna.ical4j.model.property.FreeBusy) PeriodList(net.fortuna.ical4j.model.PeriodList) Period(net.fortuna.ical4j.model.Period) BwEvent(org.bedework.calfacade.BwEvent) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) PropertyList(net.fortuna.ical4j.model.PropertyList) PropertyInfoIndex(org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex) ChangeTable(org.bedework.calfacade.util.ChangeTable) Iterator(java.util.Iterator) Parameter(net.fortuna.ical4j.model.Parameter) Property(net.fortuna.ical4j.model.Property) BwAttendee(org.bedework.calfacade.BwAttendee) BwEventObj(org.bedework.calfacade.BwEventObj) BwOrganizer(org.bedework.calfacade.BwOrganizer)

Example 4 with ChangeTable

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

the class BwUpdates method validateDates.

private UpdateResult validateDates(final EventInfo ei) throws WebdavException {
    DatesState ds = (DatesState) state.get(DatesState.stateName);
    if (ds == null) {
        return UpdateResult.getOkResult();
    }
    BwEvent ev = ei.getEvent();
    boolean task = ev.getEntityType() == IcalDefs.entityTypeTodo;
    PropertyInfoIndex endPi;
    ChangeTable chg = ei.getChangeset(userHref);
    if (task) {
        endPi = PropertyInfoIndex.DUE;
    } else {
        endPi = PropertyInfoIndex.DTEND;
    }
    try {
        boolean scheduleReply = ev.getScheduleMethod() == ScheduleMethods.methodTypeReply;
        if (ds.start == null) {
            if (!scheduleReply && !task) {
                return new UpdateResult("org.bedework.error.nostartdate");
            }
            /* A todo can have no date and time. set start to now, end to
         * many years from now and the noStart flag.
         *
         * Such an entry has to appear only on the current day.
         */
            if (ds.end != null) {
                ds.start = ds.end;
            } else {
                Date now = new Date(new java.util.Date().getTime());
                DtStart dtStart = new DtStart(now);
                dtStart.getParameters().add(Value.DATE);
                ds.start = BwDateTime.makeBwDateTime(dtStart);
            }
            if (!ev.getNoStart() || !CalFacadeUtil.eqObjval(ev.getDtstart(), ds.start)) {
                chg.changed(PropertyInfoIndex.DTSTART, ev.getDtstart(), null);
                ev.setDtstart(ds.start);
                ev.setNoStart(true);
            }
        } else if (ev.getNoStart() || !ds.start.equals(ev.getDtstart())) {
            chg.changed(PropertyInfoIndex.DTSTART, ev.getDtstart(), ds.start);
            ev.setNoStart(false);
            ev.setDtstart(ds.start);
        }
        char endType = StartEndComponent.endTypeNone;
        if (ds.end != null) {
            if ((ev.getEndType() != StartEndComponent.endTypeDate) || !CalFacadeUtil.eqObjval(ev.getDtend(), ds.end)) {
                chg.changed(endPi, ev.getDtend(), ds.end);
                endType = StartEndComponent.endTypeDate;
                ev.setDtend(ds.end);
            }
        } else if (scheduleReply || task) {
            // about 10 years
            Dur years = new Dur(520);
            Date now = new Date(new java.util.Date().getTime());
            DtEnd dtEnd = new DtEnd(new Date(years.getTime(now)));
            dtEnd.getParameters().add(Value.DATE);
            ds.end = BwDateTime.makeBwDateTime(dtEnd);
            if (!CalFacadeUtil.eqObjval(ev.getDtend(), ds.end)) {
                chg.changed(endPi, ev.getDtend(), ds.end);
                ev.setDtend(ds.end);
            }
        }
        /**
         * If we were given a duration store it in the event and calculate
         *          an end to the event - which we should not have been given.
         */
        if (ds.duration != null) {
            if (endType != StartEndComponent.endTypeNone) {
                if (ev.getEntityType() == IcalDefs.entityTypeFreeAndBusy) {
                // Apple is sending both - duration indicates the minimum
                // freebusy duration. Ignore for now.
                } else {
                    return new UpdateResult(CalFacadeException.endAndDuration);
                }
            }
            endType = StartEndComponent.endTypeDuration;
            if (!ds.duration.equals(ev.getDuration())) {
                chg.changed(PropertyInfoIndex.DURATION, ev.getDuration(), ds.duration);
                ev.setDuration(ds.duration);
            }
            ev.setDtend(BwDateTime.makeDateTime(ev.getDtstart().makeDtStart(), ev.getDtstart().getDateType(), new Dur(ds.duration)));
        } else if (!scheduleReply && (endType == StartEndComponent.endTypeNone) && !task) {
            /* No duration and no end specified.
         * Set the end values to the start values + 1 for dates
         */
            boolean dateOnly = ev.getDtstart().getDateType();
            Dur dur;
            if (dateOnly) {
                // 1 day
                dur = new Dur(1, 0, 0, 0);
            } else {
                // No duration
                dur = new Dur(0, 0, 0, 0);
            }
            BwDateTime bwDtEnd = BwDateTime.makeDateTime(ev.getDtstart().makeDtStart(), dateOnly, dur);
            if (!CalFacadeUtil.eqObjval(ev.getDtend(), bwDtEnd)) {
                chg.changed(endPi, ev.getDtend(), bwDtEnd);
                ev.setDtend(bwDtEnd);
            }
        }
        if ((endType != StartEndComponent.endTypeDuration) && (ev.getDtstart() != null) && (ev.getDtend() != null)) {
            // Calculate a duration
            String durVal = BwDateTime.makeDuration(ev.getDtstart(), ev.getDtend()).toString();
            if (!durVal.equals(ev.getDuration())) {
                chg.changed(PropertyInfoIndex.DURATION, ev.getDuration(), durVal);
                ev.setDuration(durVal);
            }
        }
        ev.setEndType(endType);
        return UpdateResult.getOkResult();
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : Dur(net.fortuna.ical4j.model.Dur) BwDateTime(org.bedework.calfacade.BwDateTime) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) Date(net.fortuna.ical4j.model.Date) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) PropertyInfoIndex(org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex) DtStart(net.fortuna.ical4j.model.property.DtStart) ChangeTable(org.bedework.calfacade.util.ChangeTable) DatesState(org.bedework.caldav.bwserver.stdupdaters.DateDatetimePropUpdater.DatesState) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) DtEnd(net.fortuna.ical4j.model.property.DtEnd)

Example 5 with ChangeTable

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

the class AlarmPropUpdater method flagChange.

protected void flagChange(final BwAlarm val, final UpdateInfo ui) {
    ChangeTableEntry cte = ui.getCte();
    if (cte != null) {
        cte.setChanged(null, null);
    }
    ChangeTable ct = ui.getEi().getChangeset(ui.getUserHref());
    cte = ct.getEntry(PropertyInfoIndex.VALARM);
    if (cte != null) {
        cte.setChanged(null, val);
    }
    getAS(ui).add(val);
}
Also used : ChangeTable(org.bedework.calfacade.util.ChangeTable) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry)

Aggregations

ChangeTable (org.bedework.calfacade.util.ChangeTable)15 BwEvent (org.bedework.calfacade.BwEvent)10 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)7 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)7 BwDateTime (org.bedework.calfacade.BwDateTime)6 EventInfo (org.bedework.calfacade.svc.EventInfo)5 PropertyInfoIndex (org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex)5 Date (net.fortuna.ical4j.model.Date)4 DtStart (net.fortuna.ical4j.model.property.DtStart)4 BwAttendee (org.bedework.calfacade.BwAttendee)4 BwOrganizer (org.bedework.calfacade.BwOrganizer)4 BwXproperty (org.bedework.calfacade.BwXproperty)4 Dur (net.fortuna.ical4j.model.Dur)3 Period (net.fortuna.ical4j.model.Period)3 PropertyList (net.fortuna.ical4j.model.PropertyList)3 DtEnd (net.fortuna.ical4j.model.property.DtEnd)3 BwCategory (org.bedework.calfacade.BwCategory)3 BwEventProxy (org.bedework.calfacade.BwEventProxy)3 Iterator (java.util.Iterator)2 TreeSet (java.util.TreeSet)2