use of org.osaf.caldav4j.methods.CalDAVReportMethod in project openmeetings by apache.
the class EtagsHandler method internalSyncItems.
@Override
DavMethodBase internalSyncItems() throws IOException, DavException {
Long ownerId = this.calendar.getOwner().getId();
Map<String, Appointment> map = listToMap(appointmentDao.getHrefsbyCalendar(calendar.getId()), appointmentDao.getbyCalendar(calendar.getId()));
DavPropertyNameSet properties = new DavPropertyNameSet();
properties.add(DavPropertyName.GETETAG);
CompFilter vcalendar = new CompFilter(Calendar.VCALENDAR);
vcalendar.addCompFilter(new CompFilter(Component.VEVENT));
CalendarQuery query = new CalendarQuery(properties, vcalendar, map.isEmpty() ? new CalendarData() : null, false, false);
CalDAVReportMethod method = new CalDAVReportMethod(path, query, CalDAVConstants.DEPTH_1);
client.executeMethod(method);
if (method.succeeded()) {
MultiStatusResponse[] multiStatusResponses = method.getResponseBodyAsMultiStatus().getResponses();
if (map.isEmpty()) {
// Parse the responses into Appointments
for (MultiStatusResponse response : multiStatusResponses) {
if (response.getStatus()[0].getStatusCode() == SC_OK) {
String etag = CalendarDataProperty.getEtagfromResponse(response);
Calendar ical = CalendarDataProperty.getCalendarfromResponse(response);
Appointment appointments = utils.parseCalendartoAppointment(ical, response.getHref(), etag, calendar);
appointmentDao.update(appointments, ownerId);
}
}
} else {
// Calendar has been inited before
List<String> currenthrefs = new ArrayList<>();
for (MultiStatusResponse response : multiStatusResponses) {
if (response.getStatus()[0].getStatusCode() == SC_OK) {
Appointment appointment = map.get(response.getHref());
// Event updated
if (appointment != null) {
String origetag = appointment.getEtag(), currentetag = CalendarDataProperty.getEtagfromResponse(response);
// If etag is modified
if (!currentetag.equals(origetag)) {
currenthrefs.add(appointment.getHref());
}
map.remove(response.getHref());
} else {
// The orig list of events doesn't contain this event.
currenthrefs.add(response.getHref());
}
}
}
// Remaining Events have been deleted on the server, thus delete them
for (Map.Entry<String, Appointment> entry : map.entrySet()) {
appointmentDao.delete(entry.getValue(), ownerId);
}
// Get the rest of the events through a Multiget Handler.
MultigetHandler multigetHandler = new MultigetHandler(currenthrefs, path, calendar, client, appointmentDao, utils);
releaseConnection(method);
return multigetHandler.internalSyncItems();
}
} else {
log.error("Report Method return Status: {} for calId {} ", method.getStatusCode(), calendar.getId());
}
return method;
}
use of org.osaf.caldav4j.methods.CalDAVReportMethod in project openmeetings by apache.
the class MultigetHandler method internalSyncItems.
@Override
DavMethodBase internalSyncItems() throws IOException, DavException {
Long ownerId = this.calendar.getOwner().getId();
if (!isMultigetDisabled) {
CalDAVReportMethod method = new CalDAVReportMethod(path, query, CalDAVConstants.DEPTH_1);
client.executeMethod(method);
if (method.succeeded()) {
// Map for each Href as key and Appointment as Value.
Map<String, Appointment> map = listToMap(appointmentDao.getHrefsbyCalendar(calendar.getId()), appointmentDao.getbyCalendar(calendar.getId()));
for (MultiStatusResponse response : method.getResponseBodyAsMultiStatus().getResponses()) {
if (response.getStatus()[0].getStatusCode() == SC_OK) {
Appointment a = map.get(response.getHref());
// Check if it's an updated Appointment
if (a != null) {
String origetag = a.getEtag(), currentetag = CalendarDataProperty.getEtagfromResponse(response);
// If etag is modified
if (!currentetag.equals(origetag)) {
if (onlyEtag) {
a.setEtag(currentetag);
} else {
Calendar calendar = CalendarDataProperty.getCalendarfromResponse(response);
a = utils.parseCalendartoAppointment(a, calendar, currentetag);
}
appointmentDao.update(a, ownerId);
}
} else if (!onlyEtag) {
// Else it's a new Appointment
// i.e. parse into a new Appointment
// Only applicable when we get calendar data along with etag.
String etag = CalendarDataProperty.getEtagfromResponse(response);
Calendar ical = CalendarDataProperty.getCalendarfromResponse(response);
Appointment appointments = utils.parseCalendartoAppointment(ical, response.getHref(), etag, calendar);
appointmentDao.update(appointments, ownerId);
}
}
}
} else {
log.error("Report Method return Status: {} for calId {}", method.getStatusCode(), calendar.getId());
}
return method;
}
return null;
}
Aggregations