use of org.apache.openmeetings.service.calendar.caldav.methods.SyncMethod in project openmeetings by apache.
the class WebDAVSyncHandler method internalSyncItems.
@Override
DavMethodBase internalSyncItems() throws IOException, DavException {
boolean additionalSyncNeeded = false;
DavPropertyNameSet properties = new DavPropertyNameSet();
properties.add(DavPropertyName.GETETAG);
// Create report to get
SyncReportInfo reportInfo = new SyncReportInfo(calendar.getToken(), properties, SyncReportInfo.SYNC_LEVEL_1);
SyncMethod method = new SyncMethod(path, reportInfo);
client.executeMethod(method);
if (method.succeeded()) {
List<String> currenthrefs = new ArrayList<>();
// Map of Href and the Appointments, belonging to it.
Map<String, Appointment> map = listToMap(appointmentDao.getHrefsbyCalendar(calendar.getId()), appointmentDao.getbyCalendar(calendar.getId()));
for (MultiStatusResponse response : method.getResponseBodyAsMultiStatus().getResponses()) {
int status = response.getStatus()[0].getStatusCode();
if (status == SC_OK) {
Appointment a = map.get(response.getHref());
if (a != null) {
// Old Event to get
String origetag = a.getEtag(), currentetag = CalendarDataProperty.getEtagfromResponse(response);
// If event modified, only then get it.
if (!currentetag.equals(origetag)) {
currenthrefs.add(response.getHref());
}
} else {
// New Event, to get
currenthrefs.add(response.getHref());
}
} else if (status == SC_NOT_FOUND) {
// Delete the Appointments not found on the server.
Appointment a = map.get(response.getHref());
// Only if the event exists on the database, delete it.
if (a != null) {
appointmentDao.delete(a, calendar.getOwner().getId());
}
} else if (status == SC_INSUFFICIENT_SPACE_ON_RESOURCE) {
additionalSyncNeeded = true;
}
}
MultigetHandler multigetHandler = new MultigetHandler(currenthrefs, path, calendar, client, appointmentDao, utils);
multigetHandler.syncItems();
// Set the new token
calendar.setToken(method.getResponseSynctoken());
} else if (method.getStatusCode() == SC_FORBIDDEN || method.getStatusCode() == SC_PRECONDITION_FAILED) {
// Specific case where a server might sometimes forget the sync token
// Thus requiring a full sync needed to be done.
log.info("Sync Token not accepted by server. Doing a full sync again.");
calendar.setToken(null);
additionalSyncNeeded = true;
} else {
log.error("Error in Sync Method Response with status code {}", method.getStatusCode());
}
if (additionalSyncNeeded) {
releaseConnection(method);
return internalSyncItems();
}
return method;
}
Aggregations