Search in sources :

Example 11 with BwAttendee

use of org.bedework.calfacade.BwAttendee 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 12 with BwAttendee

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

the class DocBuilder method indexAttendees.

private void indexAttendees(final Set<BwAttendee> atts, final boolean vpoll) throws CalFacadeException {
    try {
        if (Util.isEmpty(atts)) {
            return;
        }
        if (vpoll) {
            startArray(getJname(PropertyInfoIndex.VOTER));
        } else {
            startArray(getJname(PropertyInfoIndex.ATTENDEE));
        }
        for (final BwAttendee val : atts) {
            startObject();
            startObject("pars");
            if (val.getRsvp()) {
                makeField(ParameterInfoIndex.RSVP.getJname(), val.getRsvp());
            }
            if (vpoll && val.getStayInformed()) {
                makeField(ParameterInfoIndex.STAY_INFORMED.getJname(), val.getStayInformed());
            }
            makeField(ParameterInfoIndex.CN.getJname(), val.getCn());
            String temp = val.getPartstat();
            if (temp == null) {
                temp = IcalDefs.partstatValNeedsAction;
            }
            makeField(ParameterInfoIndex.PARTSTAT.getJname(), temp);
            makeField(ParameterInfoIndex.SCHEDULE_STATUS.getJname(), val.getScheduleStatus());
            makeField(ParameterInfoIndex.CUTYPE.getJname(), val.getCuType());
            makeField(ParameterInfoIndex.DELEGATED_FROM.getJname(), val.getDelegatedFrom());
            makeField(ParameterInfoIndex.DELEGATED_TO.getJname(), val.getDelegatedTo());
            makeField(ParameterInfoIndex.DIR.getJname(), val.getDir());
            makeField(ParameterInfoIndex.LANGUAGE.getJname(), val.getLanguage());
            makeField(ParameterInfoIndex.MEMBER.getJname(), val.getMember());
            makeField(ParameterInfoIndex.ROLE.getJname(), val.getRole());
            makeField(ParameterInfoIndex.SENT_BY.getJname(), val.getSentBy());
            endObject();
            makeField("uri", val.getAttendeeUri());
            endObject();
        }
        endArray();
    } catch (final IndexException e) {
        throw new CalFacadeException(e);
    }
}
Also used : IndexException(org.bedework.util.indexing.IndexException) BwAttendee(org.bedework.calfacade.BwAttendee) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 13 with BwAttendee

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

the class EntityBuilder method restoreAttendees.

private Set<BwAttendee> restoreAttendees(final boolean vpoll) throws CalFacadeException {
    final PropertyInfoIndex pi;
    if (vpoll) {
        pi = PropertyInfoIndex.VOTER;
    } else {
        pi = PropertyInfoIndex.ATTENDEE;
    }
    final List<Object> vals = getFieldValues(pi);
    if (Util.isEmpty(vals)) {
        return null;
    }
    final Set<BwAttendee> atts = new TreeSet<>();
    for (final Object o : vals) {
        try {
            pushFields(o);
            final BwAttendee att = new BwAttendee();
            if (pushFields(PropertyInfoIndex.PARAMETERS)) {
                try {
                    att.setRsvp(getBool(ParameterInfoIndex.RSVP));
                    att.setCn(getString(ParameterInfoIndex.CN));
                    att.setPartstat(getString(ParameterInfoIndex.PARTSTAT));
                    att.setScheduleStatus(getString(ParameterInfoIndex.SCHEDULE_STATUS));
                    att.setCuType(getString(ParameterInfoIndex.CUTYPE));
                    att.setDelegatedFrom(getString(ParameterInfoIndex.DELEGATED_FROM));
                    att.setDelegatedTo(getString(ParameterInfoIndex.DELEGATED_TO));
                    att.setDir(getString(ParameterInfoIndex.DIR));
                    att.setLanguage(getString(ParameterInfoIndex.LANGUAGE));
                    att.setMember(getString(ParameterInfoIndex.MEMBER));
                    att.setRole(getString(ParameterInfoIndex.ROLE));
                    att.setSentBy(getString(ParameterInfoIndex.SENT_BY));
                    if (vpoll) {
                        att.setStayInformed(getBool(ParameterInfoIndex.STAY_INFORMED));
                    }
                } finally {
                    popFields();
                }
            }
            att.setAttendeeUri(getString(PropertyInfoIndex.URI));
            atts.add(att);
        } catch (final IndexException ie) {
            throw new CalFacadeException(ie);
        } finally {
            popFields();
        }
    }
    return atts;
}
Also used : PropertyInfoIndex(org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex) IndexException(org.bedework.util.indexing.IndexException) TreeSet(java.util.TreeSet) BwAttendee(org.bedework.calfacade.BwAttendee) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 14 with BwAttendee

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

the class AttendeeFieldRule method field.

@Override
public void field(final String name) throws Throwable {
    BwAttendee ent = (BwAttendee) top();
    if (name.equals("id") || name.equals("seq")) {
        // pre 3.5 - won't work
        return;
    }
    if (name.equals("cn")) {
        ent.setCn(stringFld());
        return;
    }
    if (name.equals("dir")) {
        ent.setDir(stringFld());
        return;
    }
    if (name.equals("member")) {
        ent.setMember(stringFld());
        return;
    }
    if (name.equals("reinvite")) {
        return;
    }
    if (name.equals("rsvp")) {
        ent.setRsvp(booleanFld());
        return;
    }
    if (name.equals("role")) {
        ent.setRole(stringFld());
        return;
    }
    if (name.equals("sequence")) {
        ent.setSequence(intFld());
        return;
    }
    if (name.equals("dtstamp")) {
        ent.setDtstamp(stringFld());
        return;
    }
    if (name.equals("partstat")) {
        ent.setPartstat(stringFld());
        return;
    }
    if (name.equals("cuType")) {
        ent.setCuType(stringFld());
        return;
    }
    if (name.equals("delegatedFrom")) {
        ent.setDelegatedFrom(stringFld());
        return;
    }
    if (name.equals("delegatedTo")) {
        ent.setDelegatedTo(stringFld());
        return;
    }
    if (name.equals("language")) {
        ent.setLanguage(stringFld());
        return;
    }
    if (name.equals("scheduleAgent")) {
        ent.setScheduleAgent(intFld());
        return;
    }
    if (name.equals("scheduleStatus")) {
        ent.setScheduleStatus(stringFld());
        return;
    }
    if (name.equals("sentBy")) {
        ent.setSentBy(stringFld());
        return;
    }
    if (name.equals("attendeeUri")) {
        ent.setAttendeeUri(stringFld());
        return;
    }
    if (name.equals("byteSize")) {
        ent.setByteSize(intFld());
        return;
    }
    unknownTag(name);
}
Also used : BwAttendee(org.bedework.calfacade.BwAttendee)

Example 15 with BwAttendee

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

the class InReply method process.

@Override
public ProcessResult process(final EventInfo ei) throws CalFacadeException {
    /* Process a response we as the organizer, or their proxy, received from
     * an attendee
     */
    final ProcessResult pr = new ProcessResult();
    final SchedulingI sched = getSvc().getScheduler();
    BwEvent ev = ei.getEvent();
    final EventInfo colEi = sched.getStoredMeeting(ev);
    /* The event should have a calendar set to the inbox it came from.
     * That inbox may be owned by somebody other than the current user if a
     * calendar user has delegated control of their inbox to some other user
     * e.g. secretary.
     */
    pr.attendeeAccepting = true;
    check: {
        if (colEi == null) {
            // No corresponding stored meeting
            break check;
        }
        if (ev.getOriginator() == null) {
            pr.sr.errorCode = CalFacadeException.schedulingNoOriginator;
            break check;
        }
        String attUri = null;
        /* Should be exactly one attendee */
        if (!ev.getSuppressed()) {
            final Collection<BwAttendee> atts = ev.getAttendees();
            if ((atts == null) || (atts.size() != 1)) {
                pr.sr.errorCode = CalFacadeException.schedulingExpectOneAttendee;
                break check;
            }
            final BwAttendee att = atts.iterator().next();
            if (!att.getPartstat().equals(acceptPartstat)) {
                pr.attendeeAccepting = false;
            }
            attUri = att.getAttendeeUri();
        }
        if (ei.getNumOverrides() > 0) {
            for (final EventInfo oei : ei.getOverrides()) {
                ev = oei.getEvent();
                final Collection<BwAttendee> atts = ev.getAttendees();
                if ((atts == null) || (atts.size() != 1)) {
                    pr.sr.errorCode = CalFacadeException.schedulingExpectOneAttendee;
                    break check;
                }
                final BwAttendee att = atts.iterator().next();
                if (!att.getPartstat().equals(acceptPartstat)) {
                    pr.attendeeAccepting = false;
                }
                if (attUri == null) {
                    attUri = att.getAttendeeUri();
                } else if (!attUri.equals(att.getAttendeeUri())) {
                    pr.sr.errorCode = CalFacadeException.schedulingExpectOneAttendee;
                    break check;
                }
            }
        }
        if (attUri == null) {
            pr.sr.errorCode = CalFacadeException.schedulingExpectOneAttendee;
            break check;
        }
        /*TODO If the sequence of the incoming event is lower than the sequence on the
       * calendar event we ignore it.
       */
        final boolean vpoll = colEi.getEvent().getEntityType() == IcalDefs.entityTypeVpoll;
        if (vpoll) {
            if (!updateOrganizerPollCopy(colEi, ei, attUri, pr.sr)) {
                break check;
            }
        } else if (!updateOrganizerCopy(colEi, ei, attUri, pr.sr)) {
            break check;
        }
        pr.removeInboxEntry = false;
    }
    return pr;
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) BwEvent(org.bedework.calfacade.BwEvent) SchedulingI(org.bedework.calsvci.SchedulingI) BwAttendee(org.bedework.calfacade.BwAttendee)

Aggregations

BwAttendee (org.bedework.calfacade.BwAttendee)41 BwEvent (org.bedework.calfacade.BwEvent)25 EventInfo (org.bedework.calfacade.svc.EventInfo)19 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)17 BwString (org.bedework.calfacade.BwString)10 BwOrganizer (org.bedework.calfacade.BwOrganizer)8 BwEventProxy (org.bedework.calfacade.BwEventProxy)7 Period (net.fortuna.ical4j.model.Period)6 BwDateTime (org.bedework.calfacade.BwDateTime)6 BwFreeBusyComponent (org.bedework.calfacade.BwFreeBusyComponent)6 PropertyList (net.fortuna.ical4j.model.PropertyList)5 BwEventObj (org.bedework.calfacade.BwEventObj)5 TreeSet (java.util.TreeSet)4 DateTime (net.fortuna.ical4j.model.DateTime)4 PeriodList (net.fortuna.ical4j.model.PeriodList)4 Property (net.fortuna.ical4j.model.Property)4 VFreeBusy (net.fortuna.ical4j.model.component.VFreeBusy)4 FreeBusy (net.fortuna.ical4j.model.property.FreeBusy)4 BwCalendar (org.bedework.calfacade.BwCalendar)4 BwCategory (org.bedework.calfacade.BwCategory)4