Search in sources :

Example 11 with OmCalendar

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

the class CalendarDialog method onSubmit.

@Override
protected void onSubmit(AjaxRequestTarget target) {
    switch(type) {
        case UPDATE_CALENDAR:
            OmCalendar c = form.getModelObject();
            c.setHref(form.url.getModelObject());
            HttpClient client = calendarPanel.getHttpClient();
            if (form.gcal.getModelObject()) {
                c.setSyncType(OmCalendar.SyncType.GOOGLE_CALENDAR);
                c.setToken(form.username.getModelObject());
                if (c.getId() == null)
                    calendarPanel.populateGoogleCalendar(c, target);
            } else if (c.getId() == null && form.username.getModelObject() != null) {
                apptManager.provideCredentials(client, c, new UsernamePasswordCredentials(form.username.getModelObject(), form.pass.getModelObject()));
            }
            apptManager.createCalendar(client, c);
            calendarPanel.refreshCalendars(target);
            calendarPanel.refresh(target);
            break;
        case SYNC_CALENDAR:
            syncCalendar(form.getModelObject(), target);
            if (setFormModelObject()) {
                setButtons(target);
                this.open(target);
                target.add(this);
            }
            break;
        case UPDATE_APPOINTMENT:
            updateAppointment(appointment);
            calendarPanel.refresh(target);
            break;
        case DELETE_APPOINTMENT:
            deleteAppointment(appointment);
            calendarPanel.refresh(target);
            break;
    }
    clearFormModel(target);
    target.add(feedback);
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) OmCalendar(org.apache.openmeetings.db.entity.calendar.OmCalendar) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 12 with OmCalendar

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

the class AppointmentManager method discoverCalendars.

/**
 * Function which finds all the calendars of the Principal URL of the calendar
 *
 * @param client - {@link HttpClient} to discover calendar
 * @param calendar - calendar to get principal URL from
 * @return - <code>true</code> in case calendar was discovered successfully
 */
private boolean discoverCalendars(HttpClient client, OmCalendar calendar) {
    cleanupIdleConnections();
    if (calendar.getSyncType() == SyncType.NONE) {
        PropFindMethod propFindMethod = null;
        String userPath = null, homepath = null;
        DavPropertyName curUserPrincipal = DavPropertyName.create("current-user-principal"), calHomeSet = DavPropertyName.create("calendar-home-set", CalDAVConstants.NAMESPACE_CALDAV), suppCalCompSet = DavPropertyName.create("supported-calendar-component-set", CalDAVConstants.NAMESPACE_CALDAV);
        // Find out whether it's a calendar or if we can find the calendar-home or current-user url
        try {
            String path = getPathfromCalendar(client, calendar);
            DavPropertyNameSet properties = new DavPropertyNameSet();
            properties.add(curUserPrincipal);
            properties.add(calHomeSet);
            properties.add(DavPropertyName.RESOURCETYPE);
            propFindMethod = new PropFindMethod(path, properties, CalDAVConstants.DEPTH_0);
            client.executeMethod(propFindMethod);
            if (propFindMethod.succeeded()) {
                for (MultiStatusResponse response : propFindMethod.getResponseBodyAsMultiStatus().getResponses()) {
                    DavPropertySet set = response.getProperties(SC_OK);
                    DavProperty<?> calhome = set.get(calHomeSet), curPrinci = set.get(curUserPrincipal), resourcetype = set.get(DavPropertyName.RESOURCETYPE);
                    if (checkCalendarResourceType(resourcetype)) {
                        // This is a calendar and thus initialize and return
                        return initCalendar(client, calendar);
                    }
                    // Else find all the calendars on the Principal and return.
                    if (calhome != null) {
                        // Calendar Home Path
                        homepath = getTextValuefromProperty(calhome);
                        break;
                    } else if (curPrinci != null) {
                        // Current User Principal Path
                        userPath = getTextValuefromProperty(curPrinci);
                        break;
                    }
                }
            } else {
                return false;
            }
            if (homepath == null && userPath != null) {
                // If calendar home path wasn't set, then we get it
                DavPropertyNameSet props = new DavPropertyNameSet();
                props.add(calHomeSet);
                propFindMethod = new PropFindMethod(userPath, props, DavConstants.DEPTH_0);
                client.executeMethod(propFindMethod);
                if (propFindMethod.succeeded()) {
                    for (MultiStatusResponse response : propFindMethod.getResponseBodyAsMultiStatus().getResponses()) {
                        DavPropertySet set = response.getProperties(SC_OK);
                        DavProperty<?> calhome = set.get(calHomeSet);
                        if (calhome != null) {
                            homepath = getTextValuefromProperty(calhome);
                            break;
                        }
                    }
                } else {
                    return false;
                }
            }
            if (homepath != null) {
                DavPropertyNameSet props = new DavPropertyNameSet();
                props.add(DavPropertyName.RESOURCETYPE);
                props.add(suppCalCompSet);
                props.add(DavPropertyName.DISPLAYNAME);
                propFindMethod = new PropFindMethod(homepath, props, DavConstants.DEPTH_1);
                client.executeMethod(propFindMethod);
                if (propFindMethod.succeeded()) {
                    boolean success = false;
                    for (MultiStatusResponse response : propFindMethod.getResponseBodyAsMultiStatus().getResponses()) {
                        boolean isVevent = false, isCalendar;
                        DavPropertySet set = response.getProperties(SC_OK);
                        DavProperty<?> p = set.get(suppCalCompSet), resourcetype = set.get(DavPropertyName.RESOURCETYPE), displayname = set.get(DavPropertyName.DISPLAYNAME);
                        isCalendar = checkCalendarResourceType(resourcetype);
                        if (p != null) {
                            for (Object o : (Collection<?>) p.getValue()) {
                                if (o instanceof Element) {
                                    Element e = (Element) o;
                                    String name = DomUtil.getAttribute(e, "name", null);
                                    if ("VEVENT".equals(name)) {
                                        isVevent = true;
                                    }
                                }
                            }
                        }
                        if (isCalendar && isVevent) {
                            success = true;
                            // Get New Calendar
                            OmCalendar tempCalendar = new OmCalendar();
                            if (displayname != null) {
                                tempCalendar.setTitle(displayname.getValue().toString());
                            }
                            tempCalendar.setHref(client.getHostConfiguration().getHostURL() + response.getHref());
                            tempCalendar.setDeleted(false);
                            tempCalendar.setOwner(calendar.getOwner());
                            calendarDao.update(tempCalendar);
                            initCalendar(client, tempCalendar);
                        }
                    }
                    return success;
                }
            }
        } catch (IOException e) {
            log.error("Error executing PROPFIND Method, during testConnection.", e);
        } catch (Exception e) {
            log.error("Severe Error in executing PROPFIND Method, during testConnection.", e);
        } finally {
            if (propFindMethod != null) {
                propFindMethod.releaseConnection();
            }
        }
    }
    return false;
}
Also used : PropFindMethod(org.apache.jackrabbit.webdav.client.methods.PropFindMethod) Element(org.w3c.dom.Element) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) IOException(java.io.IOException) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName) IOException(java.io.IOException) DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) Collection(java.util.Collection) OmCalendar(org.apache.openmeetings.db.entity.calendar.OmCalendar)

Example 13 with OmCalendar

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

the class AppointmentManager method updateItem.

/**
 * Function for create/updating multiple appointment on the server.
 * Performs modification alongside of creation new events on the server.
 *
 * @param client - {@link HttpClient} to discover calendar
 * @param appointment Appointment to create/update.
 * @return <code>true</code> in case item was updated
 */
public boolean updateItem(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 = ensureTrailingSlash(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.updateItem(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 14 with OmCalendar

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

the class BackupExport method exportCalendar.

/*
	 * ##################### Backup Calendars
	 */
private void exportCalendar(ZipOutputStream zos, ProgressHolder progressHolder) throws Exception {
    List<OmCalendar> list = calendarDao.get();
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);
    registry.bind(User.class, UserConverter.class);
    writeList(serializer, zos, "calendars.xml", "calendars", list);
    progressHolder.setProgress(22);
}
Also used : RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) OmCalendar(org.apache.openmeetings.db.entity.calendar.OmCalendar) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) Serializer(org.simpleframework.xml.Serializer)

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