use of org.osaf.caldav4j.methods.PutMethod in project openmeetings by apache.
the class EtagsHandler method updateItem.
@Override
public boolean updateItem(Appointment appointment) {
OmCalendar calendar = appointment.getCalendar();
String href;
if (calendar != null && calendar.getSyncType() != SyncType.NONE) {
// Store new Appointment on the server
PutMethod putMethod = null;
try {
List<String> hrefs = null;
CalendarOutputter calendarOutputter = new CalendarOutputter();
Calendar ical = utils.parseAppointmenttoCalendar(appointment);
putMethod = new PutMethod();
putMethod.setRequestBody(ical);
putMethod.setCalendarOutputter(calendarOutputter);
if (Strings.isEmpty(appointment.getHref())) {
String temp = path + appointment.getIcalId() + ".ics";
temp = UrlUtils.removeDoubleSlashes(temp);
putMethod.setPath(temp);
putMethod.setIfNoneMatch(true);
putMethod.setAllEtags(true);
} else {
putMethod.setPath(appointment.getHref());
putMethod.setIfMatch(true);
putMethod.addEtag(appointment.getEtag());
}
client.executeMethod(putMethod);
if (putMethod.getStatusCode() == SC_CREATED || putMethod.getStatusCode() == SC_NO_CONTENT) {
href = putMethod.getPath();
appointment.setHref(href);
// Check if the ETag header was returned.
Header etagh = putMethod.getResponseHeader("ETag");
if (etagh == null)
hrefs = Collections.singletonList(appointment.getHref());
else {
appointment.setEtag(etagh.getValue());
appointmentDao.update(appointment, appointment.getOwner().getId());
}
} else {
// Appointment not created on the server
return false;
}
// Get new etags for the ones which didn't return an ETag header
MultigetHandler multigetHandler = new MultigetHandler(hrefs, true, path, calendar, client, appointmentDao, utils);
multigetHandler.syncItems();
return true;
} catch (IOException e) {
log.error("Error executing OptionsMethod during testConnection.", e);
} catch (Exception e) {
log.error("Severe Error in executing OptionsMethod during testConnection.", e);
} finally {
if (putMethod != null) {
putMethod.releaseConnection();
}
}
}
return false;
}
Aggregations