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);
}
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;
}
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;
}
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);
}
Aggregations