Search in sources :

Example 81 with BwEvent

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

the class BwSysIntfImpl method schedule.

@Override
public Collection<SchedRecipientResult> schedule(final CalDAVEvent ev) throws WebdavException {
    try {
        ScheduleResult sr;
        BwEvent event = getEvent(ev);
        event.setOwnerHref(currentPrincipal.getPrincipalRef());
        if (Icalendar.itipReplyMethodType(event.getScheduleMethod())) {
            sr = getSvci().getScheduler().scheduleResponse(getEvinfo(ev));
        } else {
            sr = getSvci().getScheduler().schedule(getEvinfo(ev), null, null, // iSchedule
            true);
        }
        return checkStatus(sr);
    } catch (WebdavException we) {
        throw we;
    } catch (CalFacadeAccessException cfae) {
        throw new WebdavForbidden();
    } catch (CalFacadeException cfe) {
        if (CalFacadeException.duplicateGuid.equals(cfe.getMessage())) {
            throw new WebdavBadRequest("Duplicate-guid");
        }
        throw new WebdavException(cfe);
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : WebdavBadRequest(org.bedework.webdav.servlet.shared.WebdavBadRequest) ScheduleResult(org.bedework.calfacade.ScheduleResult) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 82 with BwEvent

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

the class BwSysIntfImpl method addEvent.

/* ====================================================================
   *                   Events
   * ==================================================================== */
/* (non-Javadoc)
   * @see org.bedework.caldav.server.SysIntf#addEvent(org.bedework.caldav.server.CalDAVEvent, boolean, boolean)
   */
@Override
public Collection<CalDAVEvent> addEvent(final CalDAVEvent ev, final boolean noInvites, final boolean rollbackOnError) throws WebdavException {
    try {
        /* Is the event a scheduling object? */
        final EventInfo ei = getEvinfo(ev);
        final Collection<BwEventProxy> bwevs = getSvci().getEventsHandler().add(ei, noInvites, // scheduling - inbox
        false, // autocreate
        false, rollbackOnError).failedOverrides;
        if (bwevs == null) {
            return null;
        }
        final Collection<CalDAVEvent> evs = new ArrayList<CalDAVEvent>();
        for (final BwEvent bwev : bwevs) {
            evs.add(new BwCalDAVEvent(this, new EventInfo(bwev)));
        }
        return evs;
    } catch (final CalFacadeAccessException cfae) {
        throw new WebdavForbidden();
    } catch (final CalFacadeException cfe) {
        if (CalFacadeException.schedulingTooManyAttendees.equals(cfe.getDetailMessage())) {
            throw new WebdavForbidden(CaldavTags.maxAttendeesPerInstance, ev.getParentPath() + "/" + cfe.getExtra());
        }
        if (CalFacadeException.invalidOverride.equals(cfe.getDetailMessage())) {
            throw new WebdavForbidden(CaldavTags.validCalendarData, ev.getParentPath() + "/" + cfe.getExtra());
        }
        if (CalFacadeException.duplicateGuid.equals(cfe.getDetailMessage())) {
            throw new WebdavForbidden(CaldavTags.noUidConflict, ev.getParentPath() + "/" + cfe.getExtra());
        }
        if (CalFacadeException.duplicateName.equals(cfe.getDetailMessage())) {
            throw new WebdavForbidden(CaldavTags.noUidConflict, ev.getParentPath() + "/" + ev.getName());
        }
        throw new WebdavException(cfe);
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) ArrayList(java.util.ArrayList) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) BwEventProxy(org.bedework.calfacade.BwEventProxy) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) CalDAVEvent(org.bedework.caldav.server.CalDAVEvent)

Example 83 with BwEvent

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

the class BwSysIntfImpl method getFreeBusy.

/* (non-Javadoc)
   * @see org.bedework.caldav.server.sysinterface.SysIntf#getFreeBusy(org.bedework.caldav.server.CalDAVCollection, int, org.bedework.caldav.util.TimeRange)
   */
@Override
public CalDAVEvent getFreeBusy(final CalDAVCollection col, final int depth, final TimeRange timeRange) throws WebdavException {
    try {
        BwCalendar bwCol = unwrap(col);
        int calType = bwCol.getCalType();
        if (!bwCol.getCollectionInfo().allowFreeBusy) {
            throw new WebdavForbidden(WebdavTags.supportedReport);
        }
        Collection<BwCalendar> cals = new ArrayList<BwCalendar>();
        if (calType == BwCalendar.calTypeCalendarCollection) {
            cals.add(bwCol);
        } else if (depth == 0) {
        /* Cannot return anything */
        } else {
            for (BwCalendar ch : getSvci().getCalendarsHandler().getChildren(bwCol)) {
                // For depth 1 we only add calendar collections
                if ((depth > 1) || (ch.getCalType() == BwCalendar.calTypeCalendarCollection)) {
                    cals.add(ch);
                }
            }
        }
        AccessPrincipal owner = col.getOwner();
        String orgUri;
        if (owner instanceof BwPrincipal) {
            orgUri = getSvci().getDirectories().principalToCaladdr((BwPrincipal) owner);
        } else {
            BwPrincipal p = BwPrincipal.makeUserPrincipal();
            p.setAccount(owner.getAccount());
            orgUri = getSvci().getDirectories().principalToCaladdr(p);
        }
        BwOrganizer org = new BwOrganizer();
        org.setOrganizerUri(orgUri);
        BwEvent fb;
        if (cals.isEmpty()) {
            // Return an empty object
            fb = new BwEventObj();
            fb.setEntityType(IcalDefs.entityTypeFreeAndBusy);
            fb.setDtstart(getBwDt(timeRange.getStart()));
            fb.setDtend(getBwDt(timeRange.getEnd()));
        } else {
            fb = getSvci().getScheduler().getFreeBusy(cals, (BwPrincipal) currentPrincipal, getBwDt(timeRange.getStart()), getBwDt(timeRange.getEnd()), org, // uid
            null, null);
        }
        EventInfo ei = new EventInfo(fb);
        return new BwCalDAVEvent(this, ei);
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    } catch (WebdavException wde) {
        throw wde;
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) ArrayList(java.util.ArrayList) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) BwCalendar(org.bedework.calfacade.BwCalendar) AccessPrincipal(org.bedework.access.AccessPrincipal) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BwPrincipal(org.bedework.calfacade.BwPrincipal) BwEventObj(org.bedework.calfacade.BwEventObj) BwOrganizer(org.bedework.calfacade.BwOrganizer)

Example 84 with BwEvent

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

the class BwUpdates method findSubComponent.

private Component findSubComponent(final EventInfo ei, final BaseComponentType bc) throws WebdavException {
    try {
        BwEvent ev = ei.getEvent();
        int etype = ev.getEntityType();
        if (bc instanceof ValarmType) {
            if ((etype != IcalDefs.entityTypeEvent) || (etype != IcalDefs.entityTypeTodo)) {
                return null;
            }
            /* Look for the alarm - we match on the whole component */
            BwAlarm matched = null;
            BwAlarm pattern = Xalarms.toBwAlarm((ValarmType) bc, false);
            if ((pattern == null) || (ev.getNumAlarms() == 0)) {
                return null;
            }
            for (BwAlarm al : ev.getAlarms()) {
                if (al.matches(pattern)) {
                    if (matched != null) {
                        // Multiple matches - bad
                        return null;
                    }
                    matched = al;
                }
            }
            return new PropertyUpdateComponent(ei, matched);
        }
        return null;
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : ValarmType(ietf.params.xml.ns.icalendar_2.ValarmType) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) BwAlarm(org.bedework.calfacade.BwAlarm) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 85 with BwEvent

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

the class BwUpdates method addSubComp.

private UpdateResult addSubComp(final EventInfo ei, final ComponentReferenceType sel) throws WebdavException {
    try {
        BwEvent ev = ei.getEvent();
        int etype = ev.getEntityType();
        BaseComponentType bc = sel.getBaseComponent().getValue();
        if (bc instanceof ValarmType) {
            if ((etype != IcalDefs.entityTypeEvent) || (etype != IcalDefs.entityTypeTodo)) {
                return new UpdateResult("Invalid entity type for alarm add");
            }
            BwAlarm al = Xalarms.toBwAlarm((ValarmType) bc, false);
            if (al == null) {
                return new UpdateResult("Invalid alarm for add");
            }
            ev.addAlarm(al);
            return UpdateResult.getOkResult();
        }
        return new UpdateResult("Invalid entity type for add");
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : ValarmType(ietf.params.xml.ns.icalendar_2.ValarmType) BaseComponentType(ietf.params.xml.ns.icalendar_2.BaseComponentType) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) BwAlarm(org.bedework.calfacade.BwAlarm) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

BwEvent (org.bedework.calfacade.BwEvent)160 EventInfo (org.bedework.calfacade.svc.EventInfo)80 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)55 BwEventProxy (org.bedework.calfacade.BwEventProxy)33 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)26 BwAttendee (org.bedework.calfacade.BwAttendee)25 BwDateTime (org.bedework.calfacade.BwDateTime)25 BwString (org.bedework.calfacade.BwString)24 UpdateResult (org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)23 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)23 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)21 BwCalendar (org.bedework.calfacade.BwCalendar)21 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)20 BwXproperty (org.bedework.calfacade.BwXproperty)16 TreeSet (java.util.TreeSet)15 BwEventObj (org.bedework.calfacade.BwEventObj)13 ArrayList (java.util.ArrayList)12 Period (net.fortuna.ical4j.model.Period)12 BwCategory (org.bedework.calfacade.BwCategory)10 BwContact (org.bedework.calfacade.BwContact)10