Search in sources :

Example 1 with PutMethod

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;
}
Also used : Header(org.apache.commons.httpclient.Header) OmCalendar(org.apache.openmeetings.db.entity.calendar.OmCalendar) Calendar(net.fortuna.ical4j.model.Calendar) PutMethod(org.osaf.caldav4j.methods.PutMethod) OmCalendar(org.apache.openmeetings.db.entity.calendar.OmCalendar) CalendarOutputter(net.fortuna.ical4j.data.CalendarOutputter) IOException(java.io.IOException) IOException(java.io.IOException) DavException(org.apache.jackrabbit.webdav.DavException)

Aggregations

IOException (java.io.IOException)1 CalendarOutputter (net.fortuna.ical4j.data.CalendarOutputter)1 Calendar (net.fortuna.ical4j.model.Calendar)1 Header (org.apache.commons.httpclient.Header)1 DavException (org.apache.jackrabbit.webdav.DavException)1 OmCalendar (org.apache.openmeetings.db.entity.calendar.OmCalendar)1 PutMethod (org.osaf.caldav4j.methods.PutMethod)1