Search in sources :

Example 31 with WebdavException

use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method getSpecialFreeBusy.

/* (non-Javadoc)
   * @see org.bedework.caldav.server.sysinterface.SysIntf#getSpecialFreeBusy(java.lang.String, java.util.Set, java.lang.String, org.bedework.caldav.util.TimeRange, java.io.Writer)
   */
@Override
public void getSpecialFreeBusy(final String cua, final Set<String> recipients, final String originator, final TimeRange tr, final Writer wtr) throws WebdavException {
    BwOrganizer org = new BwOrganizer();
    org.setOrganizerUri(cua);
    BwEvent ev = new BwEventObj();
    ev.setDtstart(getBwDt(tr.getStart()));
    ev.setDtend(getBwDt(tr.getEnd()));
    ev.setEntityType(IcalDefs.entityTypeFreeAndBusy);
    ev.setScheduleMethod(ScheduleMethods.methodTypeRequest);
    ev.setRecipients(recipients);
    ev.setOriginator(originator);
    ev.setOrganizer(org);
    Collection<SchedRecipientResult> srrs = requestFreeBusy(new BwCalDAVEvent(this, new EventInfo(ev)), false);
    for (SchedRecipientResult srr : srrs) {
        // We expect one only
        BwCalDAVEvent rfb = (BwCalDAVEvent) srr.freeBusy;
        if (rfb != null) {
            rfb.getEv().setOrganizer(org);
            try {
                VFreeBusy vfreeBusy = VFreeUtil.toVFreeBusy(rfb.getEv());
                net.fortuna.ical4j.model.Calendar ical = IcalTranslator.newIcal(ScheduleMethods.methodTypeReply);
                ical.getComponents().add(vfreeBusy);
                IcalTranslator.writeCalendar(ical, wtr);
            } catch (Throwable t) {
                if (debug) {
                    error(t);
                }
                throw new WebdavException(t);
            }
        }
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) VFreeBusy(net.fortuna.ical4j.model.component.VFreeBusy) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) Calendar(net.fortuna.ical4j.model.Calendar) BwEventObj(org.bedework.calfacade.BwEventObj) BwOrganizer(org.bedework.calfacade.BwOrganizer)

Example 32 with WebdavException

use of org.bedework.webdav.servlet.shared.WebdavException 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 33 with WebdavException

use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method subscribeNotification.

/* ====================================================================
   *                   Notifications
   * ==================================================================== */
public boolean subscribeNotification(final String principalHref, final String action, final List<String> emails) throws WebdavException {
    final boolean add = "add".equals(action);
    final boolean remove = "remove".equals(action);
    if (!add && !remove) {
        return false;
    }
    try {
        if (remove) {
            svci.getNotificationsHandler().unsubscribe(principalHref, emails);
            return true;
        }
        if (Util.isEmpty(emails)) {
            return false;
        }
        svci.getNotificationsHandler().subscribe(principalHref, emails);
        return true;
    } catch (final CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 34 with WebdavException

use of org.bedework.webdav.servlet.shared.WebdavException 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 35 with WebdavException

use of org.bedework.webdav.servlet.shared.WebdavException in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method getSyncToken.

@Override
public String getSyncToken(final CalDAVCollection col) throws WebdavException {
    try {
        BwCalendar bwcol = ((BwCalDAVCollection) col).getCol();
        String path = col.getPath();
        if (bwcol.getInternalAlias()) {
            path = bwcol.getAliasTarget().getPath();
        }
        return "data:," + getSvci().getCalendarsHandler().getSyncToken(path);
    } catch (CalFacadeAccessException cfae) {
        throw new WebdavForbidden();
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

WebdavException (org.bedework.webdav.servlet.shared.WebdavException)55 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)32 BwEvent (org.bedework.calfacade.BwEvent)20 WebdavForbidden (org.bedework.webdav.servlet.shared.WebdavForbidden)20 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)13 UpdateResult (org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)11 BwCalendar (org.bedework.calfacade.BwCalendar)10 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)10 ArrayList (java.util.ArrayList)9 EventInfo (org.bedework.calfacade.svc.EventInfo)9 WebdavBadRequest (org.bedework.webdav.servlet.shared.WebdavBadRequest)8 BwDateTime (org.bedework.calfacade.BwDateTime)7 BwString (org.bedework.calfacade.BwString)6 DateDatetimePropertyType (ietf.params.xml.ns.icalendar_2.DateDatetimePropertyType)4 TextPropertyType (ietf.params.xml.ns.icalendar_2.TextPropertyType)3 Holder (javax.xml.ws.Holder)3 CalDAVEvent (org.bedework.caldav.server.CalDAVEvent)3 SysiIcalendar (org.bedework.caldav.server.SysiIcalendar)3 CalPrincipalInfo (org.bedework.caldav.server.sysinterface.CalPrincipalInfo)3 BwCategory (org.bedework.calfacade.BwCategory)3