Search in sources :

Example 1 with CalFacadeInvalidSynctoken

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

the class CoreCalendarsDAO method getSynchCollections.

protected List getSynchCollections(final String path, final String token) throws CalFacadeException {
    final HibSession sess = getSess();
    if (path == null) {
        sess.rollback();
        throw new CalFacadeBadRequest("Missing path");
    }
    if ((token != null) && (token.length() < 18)) {
        sess.rollback();
        throw new CalFacadeInvalidSynctoken(token);
    }
    final StringBuilder sb = new StringBuilder();
    sb.append("from ");
    sb.append(BwCalendar.class.getName());
    sb.append(" col ");
    sb.append("where col.colPath=:path ");
    if (token != null) {
        /* We want any undeleted alias or external subscription or 
         any collection with a later change token.
       */
        sb.append(" and ((col.calType=7 or col.calType=8) or " + "(col.lastmod.timestamp>:lastmod" + "   or (col.lastmod.timestamp=:lastmod and " + "  col.lastmod.sequence>:seq)))");
    } else {
        // No deleted collections for null sync-token
        sb.append("and (col.filterExpr is null or col.filterExpr <> :tsfilter)");
    }
    sess.createQuery(sb.toString());
    sess.setString("path", path);
    if (token != null) {
        sess.setString("lastmod", token.substring(0, 16));
        sess.setInt("seq", Integer.parseInt(token.substring(17), 16));
    } else {
        sess.setString("tsfilter", BwCalendar.tombstonedFilter);
    }
    sess.cacheableQuery();
    return sess.getList();
}
Also used : HibSession(org.bedework.calcorei.HibSession) CalFacadeBadRequest(org.bedework.calfacade.exc.CalFacadeBadRequest) CalFacadeInvalidSynctoken(org.bedework.calfacade.exc.CalFacadeInvalidSynctoken) BwCalendar(org.bedework.calfacade.BwCalendar)

Example 2 with CalFacadeInvalidSynctoken

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

Aggregations

CalFacadeInvalidSynctoken (org.bedework.calfacade.exc.CalFacadeInvalidSynctoken)2 HibSession (org.bedework.calcorei.HibSession)1 SynchReportDataItem (org.bedework.caldav.server.sysinterface.SysIntf.SynchReportData.SynchReportDataItem)1 BwCalendar (org.bedework.calfacade.BwCalendar)1 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)1 CalFacadeBadRequest (org.bedework.calfacade.exc.CalFacadeBadRequest)1 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)1 SynchReport (org.bedework.calsvci.SynchReport)1 SynchReportItem (org.bedework.calsvci.SynchReportItem)1 WebdavBadRequest (org.bedework.webdav.servlet.shared.WebdavBadRequest)1 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)1 WebdavForbidden (org.bedework.webdav.servlet.shared.WebdavForbidden)1