use of org.olat.commons.calendar.model.Kalendar in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManagerTest method testAddChangeEvent_v2.
@Test
public void testAddChangeEvent_v2() {
Identity test = JunitTestHelper.createAndPersistIdentityAsRndUser("ical-1-");
String TEST_EVENT_ID = "id-testAddEvent";
Kalendar cal = calendarManager.getPersonalCalendar(test).getKalendar();
// 1. Test Add Event
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MILLISECOND, 0);
Date start = calendar.getTime();
calendar.add(Calendar.HOUR_OF_DAY, 1);
Date end = calendar.getTime();
KalendarEvent testEvent = new KalendarEvent(TEST_EVENT_ID, null, "testEvent", start, end);
calendarManager.addEventTo(cal, testEvent);
// empty the cache
emptyCalendarCache();
Kalendar reloadedCal = calendarManager.getPersonalCalendar(test).getKalendar();
KalendarEvent reloadedEvent = reloadedCal.getEvent(TEST_EVENT_ID, null);
Assert.assertNotNull("Could not found added event", reloadedEvent);
Assert.assertEquals("Added event has wrong subject", testEvent.getSubject(), reloadedEvent.getSubject());
Assert.assertEquals(reloadedEvent.getBegin(), start);
Assert.assertEquals(reloadedEvent.getEnd(), end);
// 2. Test Change event
calendar.add(Calendar.HOUR_OF_DAY, 1);
Date updatedEnd = calendar.getTime();
calendar.add(Calendar.HOUR_OF_DAY, -4);
Date updatedStart = calendar.getTime();
reloadedEvent.setSubject("testEvent changed");
reloadedEvent.setBegin(updatedStart);
reloadedEvent.setEnd(updatedEnd);
calendarManager.updateEventFrom(cal, reloadedEvent);
// empty the cache
emptyCalendarCache();
Kalendar updatedCal = calendarManager.getPersonalCalendar(test).getKalendar();
KalendarEvent updatedEvent = updatedCal.getEvent(TEST_EVENT_ID, null);
Assert.assertNotNull("Could not found updated event", updatedEvent);
Assert.assertEquals("Added event has wrong subject", "testEvent changed", updatedEvent.getSubject());
Assert.assertEquals(updatedStart, updatedEvent.getBegin());
Assert.assertEquals(updatedEnd, updatedEvent.getEnd());
}
use of org.olat.commons.calendar.model.Kalendar in project OpenOLAT by OpenOLAT.
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.model.Kalendar in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManager method createKalendarEventRecurringOccurence.
@Override
public KalendarEvent createKalendarEventRecurringOccurence(KalendarRecurEvent recurEvent) {
KalendarEvent rootEvent = recurEvent.getCalendar().getEvent(recurEvent.getID(), null);
VEvent vEvent = getVEvent(recurEvent);
PropertyList vEventProperties = vEvent.getProperties();
for (Iterator<?> objIt = vEventProperties.iterator(); objIt.hasNext(); ) {
Object property = objIt.next();
if (property instanceof RRule || property instanceof ExDate) {
objIt.remove();
}
}
try {
Kalendar calendar = recurEvent.getCalendar();
Date startDate = recurEvent.getOccurenceDate();
String startString = CalendarUtils.formatRecurrenceDate(startDate, rootEvent.isAllDayEvent());
RecurrenceId recurId;
if (rootEvent.isAllDayEvent()) {
recurId = new RecurrenceId(tz);
recurId.setDate(CalendarUtils.createDate(startDate));
} else {
recurId = new RecurrenceId(startString, tz);
}
vEventProperties.add(recurId);
KalendarEvent kEvent = getKalendarEvent(vEvent);
kEvent.setKalendar(calendar);
return kEvent;
} catch (ParseException e) {
log.error("", e);
return null;
}
}
use of org.olat.commons.calendar.model.Kalendar in project OpenOLAT by OpenOLAT.
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 org.olat.commons.calendar.model.Kalendar in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManager method getCalendar.
@Override
public Kalendar getCalendar(final String type, final String calendarID) {
String key = getKeyFor(type, calendarID);
Kalendar cal = calendarCache.get(key);
if (cal == null) {
cal = getCalendarFromCache(type, calendarID);
}
return cal;
}
Aggregations