Search in sources :

Example 56 with EventInfo

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

the class BwSysIntfImpl method updateEvent.

@Override
public void updateEvent(final CalDAVEvent event) throws WebdavException {
    try {
        EventInfo ei = getEvinfo(event);
        getSvci().getEventsHandler().update(ei, false);
    } catch (CalFacadeAccessException cfae) {
        throw new WebdavForbidden();
    } catch (CalFacadeForbidden cff) {
        throw new WebdavForbidden(cff.getQname(), cff.getMessage());
    } 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) EventInfo(org.bedework.calfacade.svc.EventInfo) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalFacadeForbidden(org.bedework.calfacade.exc.CalFacadeForbidden) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 57 with EventInfo

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

the class BwSysIntfImpl method writeCalendar.

@Override
public String writeCalendar(final Collection<CalDAVEvent> evs, final MethodEmitted method, final XmlEmit xml, final Writer wtr, final String contentType) throws WebdavException {
    try {
        Collection<EventInfo> bwevs = new ArrayList<EventInfo>();
        int meth = ScheduleMethods.methodTypeNone;
        if (method == MethodEmitted.publish) {
            meth = ScheduleMethods.methodTypePublish;
        }
        for (CalDAVEvent cde : evs) {
            BwCalDAVEvent bcde = (BwCalDAVEvent) cde;
            if (method == MethodEmitted.eventMethod) {
                meth = getEvent(bcde).getScheduleMethod();
            }
            bwevs.add(bcde.getEvinfo());
        }
        String ctype = contentType;
        if ((ctype == null) || (!ctype.equals("text/calendar") && !ctype.equals("application/calendar+json") && !ctype.equals(XcalTags.mimetype))) {
            ctype = getDefaultContentType();
        }
        if (ctype.equals("text/calendar")) {
            Calendar ical = trans.toIcal(bwevs, meth);
            if (xml == null) {
                IcalTranslator.writeCalendar(ical, wtr);
            } else {
                xml.cdataValue(toIcalString(ical, "text/calendar"));
            }
        } else if (ctype.equals("application/calendar+json")) {
            if (xml == null) {
                trans.writeJcal(bwevs, meth, wtr);
            } else {
                final StringWriter sw = new StringWriter();
                trans.writeJcal(bwevs, meth, sw);
                xml.cdataValue(sw.toString());
            }
        } else if (ctype.equals(XcalTags.mimetype)) {
            XmlEmit x;
            if (xml == null) {
                x = new XmlEmit();
                x.startEmit(wtr);
            } else {
                x = xml;
            }
            trans.writeXmlCalendar(bwevs, meth, x);
        }
        return ctype;
    } catch (WebdavException we) {
        throw we;
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) StringWriter(java.io.StringWriter) BwCalendar(org.bedework.calfacade.BwCalendar) Calendar(net.fortuna.ical4j.model.Calendar) ArrayList(java.util.ArrayList) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalDAVEvent(org.bedework.caldav.server.CalDAVEvent) XmlEmit(org.bedework.util.xml.XmlEmit)

Example 58 with EventInfo

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

the class BwSysIntfImpl method fromIcal.

/* (non-Javadoc)
   * @see org.bedework.caldav.server.sysinterface.SysIntf#fromIcal(org.bedework.caldav.server.CalDAVCollection, java.io.Reader, java.lang.String, org.bedework.caldav.server.sysinterface.SysIntf.IcalResultType, boolean)
   */
@Override
public SysiIcalendar fromIcal(final CalDAVCollection col, final Reader rdr, final String contentType, final IcalResultType rtype, final boolean mergeAttendees) throws WebdavException {
    // Ensure open
    getSvci();
    boolean rollback = true;
    /* (CALDAV:supported-calendar-data) */
    if ((contentType == null) || (!contentType.equals("text/calendar") && !contentType.equals("application/calendar+json"))) {
        if (debug) {
            debug("Bad content type: " + contentType);
        }
        throw new WebdavForbidden(CaldavTags.supportedCalendarData, "Bad content type: " + contentType);
    }
    try {
        BwCalendar bwcol = null;
        if (col != null) {
            bwcol = unwrap(col);
        }
        final Icalendar ic = trans.fromIcal(bwcol, new SysIntfReader(rdr), contentType, // diff the contents
        true, mergeAttendees);
        if (rtype == IcalResultType.OneComponent) {
            if (ic.getComponents().size() != 1) {
                throw new WebdavForbidden(CaldavTags.validCalendarObjectResource);
            }
            if (!(ic.getComponents().iterator().next() instanceof EventInfo)) {
                throw new WebdavForbidden(CaldavTags.validCalendarObjectResource);
            }
        } else if (rtype == IcalResultType.TimeZone) {
            if (ic.getTimeZones().size() != 1) {
                throw new WebdavForbidden("Expected one timezone");
            }
        }
        final SysiIcalendar sic = new MySysiIcalendar(this, ic);
        rollback = false;
        return sic;
    } catch (final IcalMalformedException ime) {
        throw new WebdavForbidden(CaldavTags.validCalendarData, ime.getMessage());
    } catch (final CalFacadeException cfe) {
        if (CalFacadeException.unknownTimezone.equals(cfe.getDetailMessage())) {
            throw new WebdavForbidden(CaldavTags.validTimezone, cfe.getMessage());
        }
        throw new WebdavForbidden(CaldavTags.validCalendarObjectResource, cfe.getMessage());
    } catch (final WebdavException wde) {
        throw wde;
    } catch (final Throwable t) {
        if (debug) {
            error(t);
        }
        // Assume bad data in some way
        throw new WebdavForbidden(CaldavTags.validCalendarObjectResource, t.getMessage());
    } finally {
        if (rollback) {
            try {
                getSvci().rollbackTransaction();
            } catch (final Throwable ignored) {
            }
        }
    }
}
Also used : SysIntfReader(org.bedework.caldav.server.SysIntfReader) EventInfo(org.bedework.calfacade.svc.EventInfo) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) Icalendar(org.bedework.icalendar.Icalendar) SysiIcalendar(org.bedework.caldav.server.SysiIcalendar) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwCalendar(org.bedework.calfacade.BwCalendar) SysiIcalendar(org.bedework.caldav.server.SysiIcalendar) IcalMalformedException(org.bedework.icalendar.IcalMalformedException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 59 with EventInfo

use of org.bedework.calfacade.svc.EventInfo 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 60 with EventInfo

use of org.bedework.calfacade.svc.EventInfo 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)

Aggregations

EventInfo (org.bedework.calfacade.svc.EventInfo)111 BwEvent (org.bedework.calfacade.BwEvent)80 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)37 BwCalendar (org.bedework.calfacade.BwCalendar)27 BwEventProxy (org.bedework.calfacade.BwEventProxy)24 BwAttendee (org.bedework.calfacade.BwAttendee)19 ArrayList (java.util.ArrayList)16 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)15 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)15 BwString (org.bedework.calfacade.BwString)11 BwDateTime (org.bedework.calfacade.BwDateTime)10 BwEventObj (org.bedework.calfacade.BwEventObj)10 TreeSet (java.util.TreeSet)9 BwXproperty (org.bedework.calfacade.BwXproperty)9 BwPrincipal (org.bedework.calfacade.BwPrincipal)7 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)7 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)7 Calendar (net.fortuna.ical4j.model.Calendar)6 Period (net.fortuna.ical4j.model.Period)6 BwOrganizer (org.bedework.calfacade.BwOrganizer)6