use of net.fortuna.ical4j.data.CalendarBuilder in project openolat by klemens.
the class ICalFileCalendarManager method buildKalendarFrom.
@Override
public Kalendar buildKalendarFrom(InputStream in, String calType, String calId) {
Kalendar kalendar = null;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
CalendarBuilder builder = new CalendarBuilder();
Calendar calendar = builder.build(reader);
kalendar = createKalendar(calType, calId, calendar);
} catch (Exception e) {
throw new OLATRuntimeException("Error parsing calendar file.", e);
}
return kalendar;
}
use of net.fortuna.ical4j.data.CalendarBuilder in project openolat by klemens.
the class ICalFileCalendarManager method synchronizeCalendarFrom.
@Override
public boolean synchronizeCalendarFrom(InputStream in, String source, Kalendar targetCalendar) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
Calendar inCalendar = new CalendarBuilder().build(reader);
Kalendar inTmpKalendar = createKalendar("TEMP", UUID.randomUUID().toString(), inCalendar);
String targetId = "-" + targetCalendar.getType() + "-" + targetCalendar.getCalendarID() + "-";
OLATResourceable calOres = getOresHelperFor(targetCalendar);
Boolean updatedSuccessful = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calOres, new SyncerCallback<Boolean>() {
@Override
public Boolean execute() {
// remove event in target calendar which doesn't exist in stream
Collection<KalendarEvent> currentEvents = targetCalendar.getEvents();
for (KalendarEvent currentEvent : currentEvents) {
if (currentEvent.getExternalSource() != null && source.equals(currentEvent.getExternalSource())) {
String eventId = currentEvent.getID();
String recurrenceId = currentEvent.getRecurrenceID();
if (inTmpKalendar.getEvent(eventId, recurrenceId) == null) {
targetCalendar.removeEvent(currentEvent);
} else if (eventId.contains(targetId)) {
// don't import myself;
targetCalendar.removeEvent(currentEvent);
}
}
}
Collection<KalendarEvent> inEvents = inTmpKalendar.getEvents();
for (KalendarEvent inEvent : inEvents) {
if (inEvent.getID().contains(targetId)) {
continue;
}
inEvent.setManagedFlags(new CalendarManagedFlag[] { CalendarManagedFlag.all });
inEvent.setExternalSource(source);
KalendarEvent currentEvent = targetCalendar.getEvent(inEvent.getID(), inEvent.getRecurrenceID());
if (currentEvent == null) {
targetCalendar.addEvent(inEvent);
} else {
// need perhaps more refined synchronization per event
targetCalendar.addEvent(inEvent);
}
}
boolean successfullyPersist = persistCalendar(targetCalendar);
// inform all controller about calendar change for reload
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(targetCalendar), OresHelper.lookupType(CalendarManager.class));
return new Boolean(successfullyPersist);
}
});
return updatedSuccessful.booleanValue();
} catch (Exception e) {
log.error("", e);
return false;
}
}
use of net.fortuna.ical4j.data.CalendarBuilder in project openolat by klemens.
the class ICalServlet method getOutlookVTimeZone.
/**
* Load the VTimeZone for Outlook. ical4j use a static map to reuse the TimeZone objects, we need to load
* and save our specialized TimeZone in a separate map.
*/
private VTimeZone getOutlookVTimeZone(final String id) throws IOException, ParserException {
return outlookVTimeZones.computeIfAbsent(id, (timeZoneId) -> {
try {
URL resource = ResourceLoader.getResource("zoneinfo-outlook/" + id + ".ics");
CalendarBuilder builder = new CalendarBuilder();
Calendar calendar = builder.build(resource.openStream());
VTimeZone vTimeZone = (VTimeZone) calendar.getComponent(Component.VTIMEZONE);
return vTimeZone;
} catch (Exception e) {
log.error("", e);
return null;
}
});
}
Aggregations