Search in sources :

Example 36 with CalFacadeException

use of org.bedework.calfacade.exc.CalFacadeException 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 37 with CalFacadeException

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

Example 38 with CalFacadeException

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

the class Events method compileAlarms.

/**
 * Compile an alarm component
 *
 * @param val
 * @return alarms or null
 * @throws CalFacadeException
 */
public Set<BwAlarm> compileAlarms(final String val) throws CalFacadeException {
    try {
        StringReader sr = new StringReader(ValidateAlarmPrefix + val + ValidateAlarmSuffix);
        IcalTranslator trans = new IcalTranslator(getSvc().getIcalCallback());
        Icalendar ic = trans.fromIcal(null, sr);
        if ((ic == null) || (ic.getEventInfo() == null)) {
            if (debug) {
                trace("Not single event");
            }
            return null;
        }
        /* There should be alarms in the Calendar object
       */
        EventInfo ei = ic.getEventInfo();
        BwEvent ev = ei.getEvent();
        Set<BwAlarm> alarms = ev.getAlarms();
        if (Util.isEmpty(alarms)) {
            return null;
        }
        return alarms;
    } catch (CalFacadeException cfe) {
        if (debug) {
            error(cfe);
        }
        return null;
    }
}
Also used : CoreEventInfo(org.bedework.calcorei.CoreEventInfo) EventInfo(org.bedework.calfacade.svc.EventInfo) Icalendar(org.bedework.icalendar.Icalendar) StringReader(java.io.StringReader) BwEvent(org.bedework.calfacade.BwEvent) IcalTranslator(org.bedework.icalendar.IcalTranslator) BwAlarm(org.bedework.calfacade.BwAlarm) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 39 with CalFacadeException

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

the class Filters method get.

@Override
public GetFilterDefResponse get(final String name) {
    final GetFilterDefResponse gfdr = new GetFilterDefResponse();
    try {
        final BwFilterDef fdef = getCal().getFilterDef(name, getEntityOwner(getPrincipal()));
        if (fdef == null) {
            gfdr.setStatus(Response.Status.notFound);
        } else {
            gfdr.setStatus(Response.Status.ok);
            gfdr.setFilterDef(fdef);
        }
    } catch (final CalFacadeException cfe) {
        gfdr.setStatus(Response.Status.failed);
        gfdr.setMessage(cfe.getLocalizedMessage());
    }
    return gfdr;
}
Also used : GetFilterDefResponse(org.bedework.calfacade.responses.GetFilterDefResponse) BwFilterDef(org.bedework.calfacade.BwFilterDef) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 40 with CalFacadeException

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

the class Filters method parse.

@Override
public ParseResult parse(final BwFilterDef val) {
    final String def = val.getDefinition();
    if ((def.length() > 5) && (def.startsWith("<?xml"))) {
        // Assume xml filter
        final ParseResult pr = new ParseResult();
        try {
            final FilterType f = org.bedework.caldav.util.filter.parse.Filters.parse(def);
            final EventQuery eq = org.bedework.caldav.util.filter.parse.Filters.getQuery(f);
            val.setFilters(eq.filter);
            pr.ok = true;
        } catch (final Throwable t) {
            pr.ok = false;
            pr.message = t.getMessage();
            pr.cfe = new CalFacadeException(t);
        }
        return pr;
    }
    // Assume simple expression filter
    final String source = "BwFilterDef:" + val.getOwnerHref() + ":" + val.getName();
    final ParseResult pr = getSvc().getFilterParser().parse(def, false, source);
    if (pr.ok) {
        val.setFilters(pr.filter);
    }
    return pr;
}
Also used : FilterType(ietf.params.xml.ns.caldav.FilterType) ParseResult(org.bedework.calfacade.filter.SimpleFilterParser.ParseResult) EventQuery(org.bedework.caldav.util.filter.parse.EventQuery) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)298 BwCalendar (org.bedework.calfacade.BwCalendar)55 BwEvent (org.bedework.calfacade.BwEvent)55 EventInfo (org.bedework.calfacade.svc.EventInfo)37 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)32 ArrayList (java.util.ArrayList)28 BwString (org.bedework.calfacade.BwString)26 BwDateTime (org.bedework.calfacade.BwDateTime)24 IndexException (org.bedework.util.indexing.IndexException)23 BwPrincipal (org.bedework.calfacade.BwPrincipal)22 TreeSet (java.util.TreeSet)19 BwAttendee (org.bedework.calfacade.BwAttendee)18 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)16 Calendar (net.fortuna.ical4j.model.Calendar)15 DateTime (net.fortuna.ical4j.model.DateTime)15 Period (net.fortuna.ical4j.model.Period)13 BwCategory (org.bedework.calfacade.BwCategory)13 StringReader (java.io.StringReader)12 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)12 BwEventProxy (org.bedework.calfacade.BwEventProxy)12