use of org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent in project openolat by klemens.
the class ICalFileCalendarManager method updateEventsFrom.
@Override
public boolean updateEventsFrom(Kalendar cal, List<KalendarEvent> kalendarEvents) {
final OLATResourceable calOres = getOresHelperFor(cal);
Boolean updatedSuccessful = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calOres, new SyncerCallback<Boolean>() {
@Override
public Boolean execute() {
Kalendar loadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
for (KalendarEvent kalendarEvent : kalendarEvents) {
// remove old event
loadedCal.removeEvent(kalendarEvent);
// add changed event
loadedCal.addEvent(kalendarEvent);
}
boolean successfullyPersist = persistCalendar(loadedCal);
// inform all controller about calendar change for reload
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(cal), OresHelper.lookupType(CalendarManager.class));
return successfullyPersist;
}
});
return updatedSuccessful.booleanValue();
}
use of org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent 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 org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent in project openolat by klemens.
the class ICalFileCalendarManager method removeFutureOfEvent.
@Override
public boolean removeFutureOfEvent(Kalendar cal, KalendarRecurEvent kalendarEvent) {
OLATResourceable calOres = getOresHelperFor(cal);
Boolean removeSuccessful = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calOres, new SyncerCallback<Boolean>() {
@Override
public Boolean execute() {
boolean successfullyPersist = false;
try {
String uid = kalendarEvent.getID();
Date occurenceDate = kalendarEvent.getOccurenceDate();
Kalendar loadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
KalendarEvent rootEvent = loadedCal.getEvent(kalendarEvent.getID(), null);
String rRule = rootEvent.getRecurrenceRule();
Recur recur = new Recur(rRule);
recur.setUntil(CalendarUtils.createDate(occurenceDate));
RRule rrule = new RRule(recur);
rootEvent.setRecurrenceRule(rrule.getValue());
for (KalendarEvent kEvent : loadedCal.getEvents()) {
if (uid.equals(kEvent.getID()) && StringHelper.containsNonWhitespace(kEvent.getRecurrenceID()) && occurenceDate.before(kEvent.getBegin())) {
loadedCal.removeEvent(kEvent);
}
}
successfullyPersist = persistCalendar(loadedCal);
} catch (ParseException e) {
log.error("", e);
}
return new Boolean(successfullyPersist);
}
});
// inform all controller about calendar change for reload
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(cal), OresHelper.lookupType(CalendarManager.class));
return removeSuccessful.booleanValue();
}
use of org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent in project openolat by klemens.
the class ICalFileCalendarManager method removeEventFrom.
/**
* @see org.olat.commons.calendar.CalendarManager#removeEventFrom(org.olat.commons.calendar.model.Kalendar, org.olat.commons.calendar.model.KalendarEvent)
*/
@Override
public boolean removeEventFrom(final Kalendar cal, final KalendarEvent kalendarEvent) {
OLATResourceable calOres = getOresHelperFor(cal);
Boolean removeSuccessful = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calOres, new SyncerCallback<Boolean>() {
@Override
public Boolean execute() {
String uid = kalendarEvent.getID();
String recurrenceId = kalendarEvent.getRecurrenceID();
Kalendar loadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
if (StringHelper.containsNonWhitespace(recurrenceId)) {
loadedCal.removeEvent(kalendarEvent);
KalendarEvent rootEvent = loadedCal.getEvent(kalendarEvent.getID(), null);
if (rootEvent != null && kalendarEvent instanceof KalendarRecurEvent) {
Date recurrenceDate = ((KalendarRecurEvent) kalendarEvent).getOccurenceDate();
rootEvent.addRecurrenceExc(recurrenceDate);
}
} else {
for (KalendarEvent kEvent : loadedCal.getEvents()) {
if (uid.equals(kEvent.getID())) {
loadedCal.removeEvent(kEvent);
}
}
}
boolean successfullyPersist = persistCalendar(loadedCal);
return new Boolean(successfullyPersist);
}
});
// inform all controller about calendar change for reload
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(cal), OresHelper.lookupType(CalendarManager.class));
return removeSuccessful.booleanValue();
}
use of org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent in project openolat by klemens.
the class ICalFileCalendarManager method updateCalendar.
@Override
public boolean updateCalendar(final Kalendar cal, final Kalendar importedCal) {
OLATResourceable calOres = getOresHelperFor(cal);
Boolean updatedSuccessful = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calOres, new SyncerCallback<Boolean>() {
@Override
public Boolean execute() {
Map<KalendarEventKey, KalendarEvent> uidToEvent = new HashMap<>();
for (KalendarEvent event : cal.getEvents()) {
if (StringHelper.containsNonWhitespace(event.getID())) {
uidToEvent.put(new KalendarEventKey(event), event);
}
}
Kalendar loadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
for (KalendarEvent importedEvent : importedCal.getEvents()) {
KalendarEventKey uid = new KalendarEventKey(importedEvent);
if (uidToEvent.containsKey(uid)) {
// remove old event
loadedCal.removeEvent(importedEvent);
// add changed event
loadedCal.addEvent(importedEvent);
} else {
loadedCal.addEvent(importedEvent);
}
}
boolean successfullyPersist = persistCalendar(cal);
// inform all controller about calendar change for reload
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(cal), OresHelper.lookupType(CalendarManager.class));
return new Boolean(successfullyPersist);
}
});
return updatedSuccessful.booleanValue();
}
Aggregations