Search in sources :

Example 6 with OmCalendar

use of org.apache.openmeetings.db.entity.calendar.OmCalendar in project openmeetings by apache.

the class AppointmentManager method deleteItem.

/**
 * Delete Appointment on the CalDAV server.
 * Delete's on the Server only if the ETag of the Appointment is the one on the server,
 * i.e. only if the Event hasn't changed on the Server.
 *
 * @param client - {@link HttpClient} to discover calendar
 * @param appointment Appointment to Delete
 * @return <code>true</code> in case item was deleted
 */
public boolean deleteItem(HttpClient client, Appointment appointment) {
    cleanupIdleConnections();
    OmCalendar calendar = appointment.getCalendar();
    SyncType type = calendar.getSyncType();
    if (type != SyncType.NONE && type != SyncType.GOOGLE_CALENDAR) {
        CalendarHandler calendarHandler;
        String path = getPathfromCalendar(client, calendar);
        switch(type) {
            case WEBDAV_SYNC:
            case CTAG:
            case ETAG:
                calendarHandler = new EtagsHandler(path, calendar, client, appointmentDao, utils);
                break;
            default:
                return false;
        }
        return calendarHandler.deleteItem(appointment);
    }
    return false;
}
Also used : SyncType(org.apache.openmeetings.db.entity.calendar.OmCalendar.SyncType) EtagsHandler(org.apache.openmeetings.service.calendar.caldav.handler.EtagsHandler) OmCalendar(org.apache.openmeetings.db.entity.calendar.OmCalendar) CalendarHandler(org.apache.openmeetings.service.calendar.caldav.handler.CalendarHandler)

Example 7 with OmCalendar

use of org.apache.openmeetings.db.entity.calendar.OmCalendar 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)

Example 8 with OmCalendar

use of org.apache.openmeetings.db.entity.calendar.OmCalendar in project openmeetings by apache.

the class TestOmCalendar method saveCalendar.

@Test
public void saveCalendar() {
    OmCalendar calendar = new OmCalendar();
    Long userId = 1L;
    User owner = userDao.get(userId);
    String title = "Calendar Title", href = "http://caldav.example.com/principals/user";
    calendar.setOwner(owner);
    calendar.setTitle(title);
    calendar.setHref(href);
    calendar.setSyncType(OmCalendar.SyncType.ETAG);
    calendar = calendarDao.update(calendar);
    assertTrue("Saved calendar should have valid id: " + calendar.getId(), calendar.getId() != null && calendar.getId() > 0);
    OmCalendar c = calendarDao.get(calendar.getId());
    assertNotNull("Failed to find Calendar by id", c);
}
Also used : User(org.apache.openmeetings.db.entity.user.User) OmCalendar(org.apache.openmeetings.db.entity.calendar.OmCalendar) Test(org.junit.Test)

Example 9 with OmCalendar

use of org.apache.openmeetings.db.entity.calendar.OmCalendar in project openmeetings by apache.

the class CalendarPanel method onInitialize.

@Override
protected void onInitialize() {
    final Form<Date> form = new Form<>("form");
    add(form);
    dialog = new AppointmentDialog("appointment", this, new CompoundPropertyModel<>(getDefault()));
    add(dialog);
    boolean isRtl = isRtl();
    Options options = new Options();
    options.set("isRTL", isRtl);
    options.set("header", isRtl ? "{left: 'agendaDay,agendaWeek,month', center: 'title', right: 'today nextYear,next,prev,prevYear'}" : "{left: 'prevYear,prev,next,nextYear today', center: 'title', right: 'month,agendaWeek,agendaDay'}");
    options.set("allDaySlot", false);
    options.set("axisFormat", Options.asString("H(:mm)"));
    options.set("defaultEventMinutes", 60);
    options.set("timeFormat", Options.asString("H(:mm)"));
    options.set("buttonText", new JSONObject().put("month", getString("801")).put("week", getString("800")).put("day", getString("799")).put("today", getString("1555")).toString());
    JSONArray monthes = new JSONArray();
    JSONArray shortMonthes = new JSONArray();
    JSONArray days = new JSONArray();
    JSONArray shortDays = new JSONArray();
    // first week day must be Sunday
    days.put(0, getString("466"));
    shortDays.put(0, getString("459"));
    for (int i = 0; i < 12; i++) {
        monthes.put(i, getString(String.valueOf(469 + i)));
        shortMonthes.put(i, getString(String.valueOf(1556 + i)));
        if (i + 1 < 7) {
            days.put(i + 1, getString(String.valueOf(460 + i)));
            shortDays.put(i + 1, getString(String.valueOf(453 + i)));
        }
    }
    options.set("monthNames", monthes.toString());
    options.set("monthNamesShort", shortMonthes.toString());
    options.set("dayNames", days.toString());
    options.set("dayNamesShort", shortDays.toString());
    options.set("firstDay", cfgDao.getInt(CONFIG_CALENDAR_FIRST_DAY, 0));
    calendar = new Calendar("calendar", new AppointmentModel(), options) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onInitialize() {
            super.onInitialize();
            add(new CalendarFunctionsBehavior(getMarkupId()));
        }

        @Override
        public boolean isSelectable() {
            return true;
        }

        @Override
        public boolean isDayClickEnabled() {
            return true;
        }

        @Override
        public boolean isEventClickEnabled() {
            return true;
        }

        @Override
        public boolean isEventDropEnabled() {
            return true;
        }

        @Override
        public boolean isEventResizeEnabled() {
            return true;
        }

        // no need to override onDayClick
        @Override
        public void onSelect(AjaxRequestTarget target, CalendarView view, LocalDateTime start, LocalDateTime end, boolean allDay) {
            Appointment a = getDefault();
            LocalDateTime s = start, e = end;
            if (CalendarView.month == view) {
                LocalDateTime now = ZonedDateTime.now(getZoneId()).toLocalDateTime();
                s = start.withHour(now.getHour()).withMinute(now.getMinute());
                e = s.plus(1, ChronoUnit.HOURS);
            }
            a.setStart(getDate(s));
            a.setEnd(getDate(e));
            dialog.setModelObjectWithAjaxTarget(a, target);
            dialog.open(target);
        }

        @Override
        public void onEventClick(AjaxRequestTarget target, CalendarView view, int eventId) {
            Appointment a = apptDao.get((long) eventId);
            dialog.setModelObjectWithAjaxTarget(a, target);
            dialog.open(target);
        }

        @Override
        public void onEventDrop(AjaxRequestTarget target, int eventId, long delta, boolean allDay) {
            Appointment a = apptDao.get((long) eventId);
            if (!AppointmentDialog.isOwner(a)) {
                return;
            }
            java.util.Calendar cal = WebSession.getCalendar();
            cal.setTime(a.getStart());
            cal.add(java.util.Calendar.MILLISECOND, (int) delta);
            a.setStart(cal.getTime());
            cal.setTime(a.getEnd());
            cal.add(java.util.Calendar.MILLISECOND, (int) delta);
            a.setEnd(cal.getTime());
            apptDao.update(a, getUserId());
            if (a.getCalendar() != null) {
                updatedeleteAppointment(target, CalendarDialog.DIALOG_TYPE.UPDATE_APPOINTMENT, a);
            }
        }

        @Override
        public void onEventResize(AjaxRequestTarget target, int eventId, long delta) {
            Appointment a = apptDao.get((long) eventId);
            if (!AppointmentDialog.isOwner(a)) {
                return;
            }
            java.util.Calendar cal = WebSession.getCalendar();
            cal.setTime(a.getEnd());
            cal.add(java.util.Calendar.MILLISECOND, (int) delta);
            a.setEnd(cal.getTime());
            apptDao.update(a, getUserId());
            if (a.getCalendar() != null) {
                updatedeleteAppointment(target, CalendarDialog.DIALOG_TYPE.UPDATE_APPOINTMENT, a);
            }
        }
    };
    form.add(calendar);
    populateGoogleCalendars();
    add(refreshTimer);
    add(syncTimer);
    calendarDialog = new CalendarDialog("calendarDialog", this, new CompoundPropertyModel<>(getDefaultCalendar()));
    add(calendarDialog);
    calendarListContainer.setOutputMarkupId(true);
    calendarListContainer.add(new ListView<OmCalendar>("items", new LoadableDetachableModel<List<OmCalendar>>() {

        private static final long serialVersionUID = 1L;

        @Override
        protected List<OmCalendar> load() {
            List<OmCalendar> cals = new ArrayList<>(apptManager.getCalendars(getUserId()));
            cals.addAll(apptManager.getGoogleCalendars(getUserId()));
            return cals;
        }
    }) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<OmCalendar> item) {
            item.setOutputMarkupId(true);
            final OmCalendar cal = item.getModelObject();
            item.add(new Button("item", new PropertyModel<String>(cal, "title")).add(new AjaxEventBehavior(EVT_CLICK) {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onEvent(AjaxRequestTarget target) {
                    calendarDialog.open(target, CalendarDialog.DIALOG_TYPE.UPDATE_CALENDAR, cal);
                    target.add(calendarDialog);
                }
            }));
        }
    });
    add(new Button("syncCalendarButton").add(new AjaxEventBehavior(EVT_CLICK) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onEvent(AjaxRequestTarget target) {
            syncCalendar(target);
        }
    }));
    add(new Button("submitCalendar").add(new AjaxEventBehavior(EVT_CLICK) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onEvent(AjaxRequestTarget target) {
            calendarDialog.open(target, CalendarDialog.DIALOG_TYPE.UPDATE_CALENDAR, getDefaultCalendar());
            target.add(calendarDialog);
        }
    }));
    add(calendarListContainer);
    super.onInitialize();
}
Also used : LocalDateTime(java.time.LocalDateTime) Appointment(org.apache.openmeetings.db.entity.calendar.Appointment) Options(com.googlecode.wicket.jquery.core.Options) Form(org.apache.wicket.markup.html.form.Form) ArrayList(java.util.ArrayList) Button(com.googlecode.wicket.jquery.ui.form.button.Button) OmCalendar(org.apache.openmeetings.db.entity.calendar.OmCalendar) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) CalendarView(com.googlecode.wicket.jquery.ui.calendar.CalendarView) AjaxEventBehavior(org.apache.wicket.ajax.AjaxEventBehavior) OmCalendar(org.apache.openmeetings.db.entity.calendar.OmCalendar) Calendar(com.googlecode.wicket.jquery.ui.calendar.Calendar) GoogleCalendar(com.googlecode.wicket.jquery.ui.calendar.EventSource.GoogleCalendar) JSONArray(com.github.openjson.JSONArray) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) PropertyModel(org.apache.wicket.model.PropertyModel) Date(java.util.Date) CalendarWebHelper.getDate(org.apache.openmeetings.web.util.CalendarWebHelper.getDate) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) JSONObject(com.github.openjson.JSONObject) LoadableDetachableModel(org.apache.wicket.model.LoadableDetachableModel)

Example 10 with OmCalendar

use of org.apache.openmeetings.db.entity.calendar.OmCalendar in project openmeetings by apache.

the class CalendarPanel method getDefaultCalendar.

private OmCalendar getDefaultCalendar() {
    OmCalendar c = new OmCalendar();
    c.setDeleted(false);
    c.setOwner(userDao.get(getUserId()));
    c.setTitle(getString("calendar.defaultTitle"));
    return c;
}
Also used : OmCalendar(org.apache.openmeetings.db.entity.calendar.OmCalendar)

Aggregations

OmCalendar (org.apache.openmeetings.db.entity.calendar.OmCalendar)14 IOException (java.io.IOException)2 HttpClient (org.apache.commons.httpclient.HttpClient)2 SyncType (org.apache.openmeetings.db.entity.calendar.OmCalendar.SyncType)2 CalendarHandler (org.apache.openmeetings.service.calendar.caldav.handler.CalendarHandler)2 EtagsHandler (org.apache.openmeetings.service.calendar.caldav.handler.EtagsHandler)2 Serializer (org.simpleframework.xml.Serializer)2 Registry (org.simpleframework.xml.convert.Registry)2 RegistryStrategy (org.simpleframework.xml.convert.RegistryStrategy)2 Persister (org.simpleframework.xml.core.Persister)2 Strategy (org.simpleframework.xml.strategy.Strategy)2 JSONArray (com.github.openjson.JSONArray)1 JSONObject (com.github.openjson.JSONObject)1 Options (com.googlecode.wicket.jquery.core.Options)1 Calendar (com.googlecode.wicket.jquery.ui.calendar.Calendar)1 CalendarView (com.googlecode.wicket.jquery.ui.calendar.CalendarView)1 GoogleCalendar (com.googlecode.wicket.jquery.ui.calendar.EventSource.GoogleCalendar)1 Button (com.googlecode.wicket.jquery.ui.form.button.Button)1 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1