use of org.bedework.calsvci.SynchReport in project bw-calendar-engine by Bedework.
the class CalSvc method getSynchReport.
/* (non-Javadoc)
* @see org.bedework.calsvci.CalSvcI#getSynchReport(java.lang.String, java.lang.String, int, boolean)
*/
@Override
public SynchReport getSynchReport(final String path, final String token, final int limit, final boolean recurse) throws CalFacadeException {
final BwCalendar col = getCalendarsHandler().get(path);
if (col == null) {
return null;
}
Set<SynchReportItem> items = new TreeSet<SynchReportItem>();
String resToken = getSynchItems(col, path, token, items, recurse);
final SynchReport res = new SynchReport(items, resToken);
if ((limit > 0) && (res.size() >= limit)) {
if (res.size() == limit) {
return res;
}
items = new TreeSet<>();
resToken = "";
for (final SynchReportItem item : res.getItems()) {
if (item.getToken().compareTo(resToken) > 0) {
resToken = item.getToken();
}
items.add(item);
if (items.size() == limit) {
break;
}
}
}
if (resToken.length() == 0) {
resToken = Util.icalUTCTimestamp() + "-0000";
}
return new SynchReport(items, resToken);
}
use of org.bedework.calsvci.SynchReport 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);
}
}
Aggregations