Search in sources :

Example 36 with WebdavException

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

the class BwSysIntfImpl method copyMove.

/* (non-Javadoc)
   * @see org.bedework.caldav.server.SysIntf#copyMove(org.bedework.caldav.server.CalDAVCollection, org.bedework.caldav.server.CalDAVCollection, boolean, boolean)
   */
@Override
public void copyMove(final CalDAVCollection from, final CalDAVCollection to, final boolean copy, final boolean overwrite) throws WebdavException {
    try {
        BwCalendar bwFrom = unwrap(from);
        BwCalendar bwTo = unwrap(to);
        if (!copy) {
            /* Move the from collection to the new location "to".
         * If the parent calendar is the same in both cases, this is just a rename.
         */
            if ((bwFrom.getColPath() == null) || (bwTo.getColPath() == null)) {
                throw new WebdavForbidden("Cannot move root");
            }
            if (bwFrom.getColPath().equals(bwTo.getColPath())) {
                // Rename
                getSvci().getCalendarsHandler().rename(bwFrom, to.getName());
                return;
            }
        }
    } catch (CalFacadeAccessException cfae) {
        throw new WebdavForbidden();
    } catch (CalFacadeException cfe) {
        throw new WebdavException(cfe);
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
    throw new WebdavException("unimplemented");
}
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)

Example 37 with WebdavException

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

the class BwSysIntfImpl method getSyncReport.

@Override
public SynchReportData getSyncReport(final String path, final String token, final int limit, final boolean recurse) throws WebdavException {
    try {
        String syncToken = null;
        if (token != null) {
            if (!token.startsWith("data:,")) {
                throw new WebdavForbidden(WebdavTags.validSyncToken, token);
            }
            syncToken = token.substring(6);
        }
        if ((syncToken != null) && (syncToken.length() == 16)) {
            // Force a full reload
            syncToken = null;
        }
        final SynchReport sr = getSvci().getSynchReport(path, syncToken, limit, recurse);
        if (sr == null) {
            return null;
        }
        final SynchReportData srd = new SynchReportData();
        srd.items = new ArrayList<>();
        srd.token = "data:," + sr.getToken();
        srd.truncated = sr.getTruncated();
        for (final SynchReportItem sri : sr.getItems()) {
            final SynchReportDataItem srdi;
            if (sri.getEvent() != null) {
                srdi = new SynchReportDataItem(sri.getVpath(), new BwCalDAVEvent(this, sri.getEvent()), sri.getToken());
            } else if (sri.getResource() != null) {
                srdi = new SynchReportDataItem(sri.getVpath(), new BwCalDAVResource(this, sri.getResource()), sri.getToken());
            } else if (sri.getCol() != null) {
                srdi = new SynchReportDataItem(sri.getVpath(), new BwCalDAVCollection(this, sri.getCol()), sri.getToken(), sri.getCanSync());
            } else {
                throw new RuntimeException("Unhandled sync report item type");
            }
            srd.items.add(srdi);
        }
        return srd;
    } catch (final CalFacadeAccessException cfae) {
        throw new WebdavForbidden();
    } catch (final CalFacadeInvalidSynctoken cist) {
        throw new WebdavBadRequest(WebdavTags.validSyncToken);
    } catch (final CalFacadeException cfe) {
        throw new WebdavException(cfe);
    } catch (final WebdavException we) {
        throw we;
    } catch (final Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : WebdavBadRequest(org.bedework.webdav.servlet.shared.WebdavBadRequest) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) SynchReport(org.bedework.calsvci.SynchReport) SynchReportDataItem(org.bedework.caldav.server.sysinterface.SysIntf.SynchReportData.SynchReportDataItem) CalFacadeInvalidSynctoken(org.bedework.calfacade.exc.CalFacadeInvalidSynctoken) SynchReportItem(org.bedework.calsvci.SynchReportItem)

Example 38 with WebdavException

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

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

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

the class BwSysIntfImpl method getPrincipalCollectionSet.

@Override
public Collection<String> getPrincipalCollectionSet(final String resourceUri) throws WebdavException {
    try {
        ArrayList<String> al = new ArrayList<>();
        al.add(BwPrincipal.principalRoot);
        return al;
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : ArrayList(java.util.ArrayList) WebdavException(org.bedework.webdav.servlet.shared.WebdavException)

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