use of org.olat.commons.calendar.model.KalendarRecurEvent in project OpenOLAT by OpenOLAT.
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.model.KalendarRecurEvent in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManager method getRecurringEventsInPeriod.
private final List<KalendarRecurEvent> getRecurringEventsInPeriod(KalendarEvent kEvent, Date periodStart, Date periodEnd, TimeZone userTz) {
VEvent vEvent = getVEvent(kEvent);
if (vEvent.getEndDate() == null || vEvent.getStartDate().getDate().after(vEvent.getEndDate().getDate())) {
return Collections.emptyList();
}
// calculate the events in the specified period
Period recurringPeriod = new Period(new DateTime(periodStart), new DateTime(periodEnd));
PeriodList periodList = vEvent.calculateRecurrenceSet(recurringPeriod);
List<KalendarRecurEvent> recurringEvents = new ArrayList<>(periodList.size());
for (Object obj : periodList) {
Period period = (Period) obj;
Date date = period.getStart();
java.util.Calendar eventStartCal = java.util.Calendar.getInstance();
eventStartCal.clear();
eventStartCal.setTime(kEvent.getBegin());
java.util.Calendar eventEndCal = java.util.Calendar.getInstance();
eventEndCal.clear();
eventEndCal.setTime(kEvent.getEnd());
java.util.Calendar recurStartCal = java.util.Calendar.getInstance();
recurStartCal.clear();
if (userTz == null) {
recurStartCal.setTimeInMillis(date.getTime());
} else {
recurStartCal.setTimeInMillis(date.getTime() - userTz.getOffset(date.getTime()));
}
long duration = kEvent.getEnd().getTime() - kEvent.getBegin().getTime();
java.util.Calendar beginCal = java.util.Calendar.getInstance();
beginCal.clear();
beginCal.set(recurStartCal.get(java.util.Calendar.YEAR), recurStartCal.get(java.util.Calendar.MONTH), recurStartCal.get(java.util.Calendar.DATE), eventStartCal.get(java.util.Calendar.HOUR_OF_DAY), eventStartCal.get(java.util.Calendar.MINUTE), eventStartCal.get(java.util.Calendar.SECOND));
java.util.Calendar endCal = java.util.Calendar.getInstance();
endCal.clear();
endCal.setTimeInMillis(beginCal.getTimeInMillis() + duration);
boolean original = false;
if (kEvent.getBegin().compareTo(beginCal.getTime()) == 0) {
// prevent doubled events
original = true;
}
Date recurrenceEnd = getRecurrenceEndDate(kEvent.getRecurrenceRule());
if (kEvent.isAllDayEvent() && recurrenceEnd != null && recurStartCal.getTime().after(recurrenceEnd)) {
// workaround for ical4j-bug in all day events
continue;
}
KalendarRecurEvent recurEvent = new KalendarRecurEvent(kEvent.getID(), original, kEvent.getSubject(), beginCal.getTime(), endCal.getTime());
recurEvent.setOccurenceDate(beginCal.getTime());
recurEvent.setSourceEvent(kEvent);
recurringEvents.add(recurEvent);
}
return recurringEvents;
}
use of org.olat.commons.calendar.model.KalendarRecurEvent in project openolat by klemens.
the class WeeklyCalendarController method doResize.
private void doResize(UserRequest ureq, KalendarEvent calEvent, Long minuteDelta, Boolean allDay) {
if (calEvent instanceof KalendarRecurEvent && !StringHelper.containsNonWhitespace(calEvent.getRecurrenceID())) {
updateCtr = new ConfirmUpdateController(ureq, getWindowControl(), (KalendarRecurEvent) calEvent, 0L, minuteDelta, allDay, false);
listenTo(updateCtr);
String title = translate("cal.edit.update");
cmc = new CloseableModalController(getWindowControl(), translate("close"), updateCtr.getInitialComponent(), true, title);
listenTo(cmc);
cmc.activate();
} else {
Kalendar cal = calEvent.getCalendar();
calEvent.setEnd(doMove(calEvent.getEnd(), 0L, minuteDelta));
if (allDay != null && calEvent.isAllDayEvent() != allDay.booleanValue()) {
calEvent.setAllDayEvent(allDay.booleanValue());
}
calendarManager.updateEventFrom(cal, calEvent);
calendarEl.getComponent().setDirty(true);
}
}
use of org.olat.commons.calendar.model.KalendarRecurEvent in project openolat by klemens.
the class WeeklyCalendarController method doMove.
private void doMove(UserRequest ureq, KalendarEvent calEvent, Long dayDelta, Long minuteDelta, Boolean allDay) {
if (calEvent instanceof KalendarRecurEvent && !StringHelper.containsNonWhitespace(calEvent.getRecurrenceID())) {
updateCtr = new ConfirmUpdateController(ureq, getWindowControl(), (KalendarRecurEvent) calEvent, dayDelta, minuteDelta, allDay, true);
listenTo(updateCtr);
String title = translate("cal.edit.update");
cmc = new CloseableModalController(getWindowControl(), translate("close"), updateCtr.getInitialComponent(), true, title);
listenTo(cmc);
cmc.activate();
} else {
Kalendar cal = calEvent.getCalendar();
calEvent.setBegin(doMove(calEvent.getBegin(), dayDelta, minuteDelta));
calEvent.setEnd(doMove(calEvent.getEnd(), dayDelta, minuteDelta));
if (allDay != null && calEvent.isAllDayEvent() != allDay.booleanValue()) {
calEvent.setAllDayEvent(allDay.booleanValue());
}
calendarManager.updateEventFrom(cal, calEvent);
calendarEl.getComponent().setDirty(true);
}
}
use of org.olat.commons.calendar.model.KalendarRecurEvent in project openolat by klemens.
the class ICalFileCalendarManager method getEvents.
@Override
public List<KalendarEvent> getEvents(Kalendar calendar, Date from, Date to, boolean privateEventsVisible) {
List<KalendarEvent> allEvents = calendar.getEvents();
List<KalendarEvent> events = new ArrayList<>(128);
Map<String, List<KalendarRecurEvent>> idToRecurringEvents = new HashMap<>();
// first pass, ignore events with recurrenceId
for (KalendarEvent event : allEvents) {
if (!privateEventsVisible && event.getClassification() == KalendarEvent.CLASS_PRIVATE) {
continue;
}
if (StringHelper.containsNonWhitespace(event.getRecurrenceID())) {
continue;
}
if (StringHelper.containsNonWhitespace(event.getRecurrenceRule())) {
List<KalendarRecurEvent> recurringEvents = getRecurringEventsInPeriod(event, from, to, tz);
if (recurringEvents.size() > 0) {
idToRecurringEvents.put(event.getID(), recurringEvents);
for (KalendarRecurEvent recurEvent : recurringEvents) {
events.add(recurEvent);
}
}
} else if (isInRange(from, to, event)) {
events.add(event);
}
}
// process events with recurrenceId
for (KalendarEvent event : allEvents) {
if (!StringHelper.containsNonWhitespace(event.getRecurrenceID())) {
continue;
}
String id = event.getID();
if (idToRecurringEvents.containsKey(id)) {
VEvent vEvent = getVEvent(event);
RecurrenceId recurrenceId = vEvent.getRecurrenceId();
net.fortuna.ical4j.model.Date startDate = recurrenceId.getDate();
if (startDate instanceof net.fortuna.ical4j.model.DateTime) {
List<KalendarRecurEvent> recurringEvents = idToRecurringEvents.get(id);
for (KalendarRecurEvent recurEvent : recurringEvents) {
Date beginDate = recurEvent.getBegin();
if (beginDate.equals(startDate)) {
recurEvent.setRecurrenceEvent(event);
}
}
} else {
List<KalendarRecurEvent> recurringEvents = idToRecurringEvents.get(id);
for (KalendarRecurEvent recurEvent : recurringEvents) {
Date beginDate = recurEvent.getBegin();
net.fortuna.ical4j.model.Date occDate = CalendarUtils.createDate(beginDate);
if (occDate.equals(startDate)) {
recurEvent.setRecurrenceEvent(event);
}
}
}
}
}
return events;
}
Aggregations