use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManagerTest method testPersistCalendarWithoutDTEndEvent.
/**
* Check a NPE
* @throws IOException
*/
@Test
public void testPersistCalendarWithoutDTEndEvent() throws IOException {
// replace the standard calendar with a forged one
Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("cal-test-1-");
File calendarFile = calendarManager.getCalendarFile("user", identity.getName());
if (calendarFile.exists()) {
calendarFile.delete();
}
File newCalendarFile = new File(calendarFile.getParentFile(), calendarFile.getName());
InputStream in = CalendarImportTest.class.getResourceAsStream("cal_without_dtend.ics");
FileUtils.copyInputStreamToFile(in, newCalendarFile);
// to be sure
emptyCalendarCache();
// load the calendar
KalendarRenderWrapper reloadCalWrapper = calendarManager.getPersonalCalendar(identity);
// check if its the right calendar
Collection<KalendarEvent> events = reloadCalWrapper.getKalendar().getEvents();
Assert.assertNotNull(events);
Assert.assertEquals(1, events.size());
KalendarEvent event = events.iterator().next();
Assert.assertEquals("Arbeitszeit: 1-3h", event.getSubject());
Assert.assertNull(event.getEnd());
Assert.assertFalse(event.isToday());
Assert.assertTrue(event.isWithinOneDay());
Assert.assertFalse(event.isAllDayEvent());
// test persist
boolean allOk = calendarManager.persistCalendar(reloadCalWrapper.getKalendar());
Assert.assertTrue(allOk);
}
use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManagerTest method testImportICal_recurringEvent.
@Test
public void testImportICal_recurringEvent() throws URISyntaxException, IOException {
Identity test = JunitTestHelper.createAndPersistIdentityAsRndUser("ur1-");
URL calendarUrl = CalendarImportTest.class.getResource("RecurringEvent.ics");
File calendarFile = new File(calendarUrl.toURI());
String calendarName = UUID.randomUUID().toString().replace("-", "");
KalendarRenderWrapper importedCalendar = importCalendarManager.importCalendar(test, calendarName, CalendarManager.TYPE_USER, calendarFile);
List<KalendarEvent> events = importedCalendar.getKalendar().getEvents();
Assert.assertEquals(2, events.size());
}
use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManagerTest method testImportICal_outlookFullDay.
@Test
public void testImportICal_outlookFullDay() throws URISyntaxException, IOException {
Identity test = JunitTestHelper.createAndPersistIdentityAsRndUser("ur2-");
URL calendarUrl = ICalFileCalendarManagerTest.class.getResource("Fullday_outlook.ics");
File calendarFile = new File(calendarUrl.toURI());
String calendarName = UUID.randomUUID().toString().replace("-", "");
KalendarRenderWrapper importedCalendar = importCalendarManager.importCalendar(test, calendarName, CalendarManager.TYPE_USER, calendarFile);
List<KalendarEvent> events = importedCalendar.getKalendar().getEvents();
Assert.assertEquals(1, events.size());
KalendarEvent event = events.get(0);
Assert.assertTrue(event.isAllDayEvent());
}
use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManagerTest method testConcurrentAddEvent.
/**
* Test concurrent add event with two threads and code-point to control concurrency.
*/
@Test
public void testConcurrentAddEvent() {
final String TEST_EVENT_ID_1 = "id-testConcurrentAddEvent-1";
final String TEST_EVENT_SUBJECT_1 = "testEvent1";
final String TEST_EVENT_ID_2 = "id-testConcurrentAddEvent-2";
final String TEST_EVENT_SUBJECT_2 = "testEvent2";
final Identity test = JunitTestHelper.createAndPersistIdentityAsRndUser("ical-2-");
final List<Exception> exceptionHolder = Collections.synchronizedList(new ArrayList<Exception>(1));
final List<Boolean> statusList = Collections.synchronizedList(new ArrayList<Boolean>(1));
final CountDownLatch doneSignal = new CountDownLatch(2);
// thread 1
Thread thread1 = new Thread() {
public void run() {
try {
// 1. load calendar
Kalendar cal = calendarManager.getPersonalCalendar(test).getKalendar();
// 2. add Event1 => breakpoint hit
log.info("testConcurrentAddEvent thread1 addEvent1");
calendarManager.addEventTo(cal, new KalendarEvent(TEST_EVENT_ID_1, TEST_EVENT_SUBJECT_1, new Date(), 1));
log.info("testConcurrentAddEvent thread1 addEvent1 DONE");
// 3. check event1 exist
cal = calendarManager.getPersonalCalendar(test).getKalendar();
KalendarEvent event1 = cal.getEvent(TEST_EVENT_ID_1, null);
assertNotNull("Did not found event with id=" + TEST_EVENT_ID_1, event1);
assertEquals("Wrong calendar-event subject", event1.getSubject(), TEST_EVENT_SUBJECT_1);
// 4. sleep 2sec
// 5. check event1 still exist (event2 added in meantime)
cal = calendarManager.getPersonalCalendar(test).getKalendar();
event1 = cal.getEvent(TEST_EVENT_ID_1, null);
assertNotNull("Did not found event with id=" + TEST_EVENT_ID_1, event1);
assertEquals("Wrong calendar-event subject", event1.getSubject(), TEST_EVENT_SUBJECT_1);
statusList.add(Boolean.TRUE);
log.info("testConcurrentAddEvent thread1 finished");
} catch (Exception ex) {
// no exception should happen
exceptionHolder.add(ex);
} finally {
doneSignal.countDown();
DBFactory.getInstance().commitAndCloseSession();
}
}
};
// thread 2
Thread thread2 = new Thread() {
public void run() {
try {
// 1. load calendar
Kalendar cal = calendarManager.getPersonalCalendar(test).getKalendar();
// 3. add Event2 (breakpoint of thread1 blocks)
log.info("testConcurrentAddEvent thread2 addEvent2");
calendarManager.addEventTo(cal, new KalendarEvent(TEST_EVENT_ID_2, TEST_EVENT_SUBJECT_2, new Date(), 1));
log.info("testConcurrentAddEvent thread1 addEvent2 DONE");
// 4. check event2 exist
cal = calendarManager.getPersonalCalendar(test).getKalendar();
KalendarEvent event2 = cal.getEvent(TEST_EVENT_ID_2, null);
assertNotNull("Did not found event with id=" + TEST_EVENT_ID_2, event2);
assertEquals("Wrong calendar-event subject", event2.getSubject(), TEST_EVENT_SUBJECT_2);
// 5. check event1 exist
cal = calendarManager.getPersonalCalendar(test).getKalendar();
KalendarEvent event1 = cal.getEvent(TEST_EVENT_ID_1, null);
assertNotNull("Did not found event with id=" + TEST_EVENT_ID_1, event1);
assertEquals("Wrong calendar-event subject", event1.getSubject(), TEST_EVENT_SUBJECT_1);
statusList.add(Boolean.TRUE);
log.info("testConcurrentAddEvent thread2 finished");
} catch (Exception ex) {
// no exception should happen
exceptionHolder.add(ex);
} finally {
doneSignal.countDown();
DBFactory.getInstance().commitAndCloseSession();
}
}
};
thread1.start();
thread2.start();
try {
boolean interrupt = doneSignal.await(10, TimeUnit.SECONDS);
assertTrue("Test takes too long (more than 10s)", interrupt);
} catch (InterruptedException e) {
fail("" + e.getMessage());
}
// if not -> they are in deadlock and the db did not detect it
for (Exception exception : exceptionHolder) {
log.info("exception: " + exception.getMessage());
exception.printStackTrace();
}
assertTrue("It throws an exception in test => see sysout", exceptionHolder.isEmpty());
log.info("testConcurrentAddEvent finish successful");
}
use of org.olat.commons.calendar.model.KalendarEvent in project openolat by klemens.
the class WeeklyCalendarController method formInnerEvent.
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
if (source == calendarEl) {
if (event instanceof CalendarGUIEditEvent) {
CalendarGUIEditEvent guiEvent = (CalendarGUIEditEvent) event;
KalendarEvent kalendarEvent = guiEvent.getKalendarEvent();
if (kalendarEvent == null) {
// event already deleted
getWindowControl().setError(translate("cal.error.eventDeleted"));
return;
}
String recurrence = kalendarEvent.getRecurrenceRule();
boolean isImported = false;
KalendarRenderWrapper kalendarRenderWrapper = guiEvent.getKalendarRenderWrapper();
if (kalendarRenderWrapper != null) {
isImported = kalendarRenderWrapper.isImported();
}
if (!isImported && recurrence != null && !recurrence.equals("")) {
List<String> btnLabels = new ArrayList<>(3);
btnLabels.add(translate("cal.edit.dialog.sequence"));
btnLabels.add(translate("cal.edit.dialog.delete.single"));
btnLabels.add(translate("cal.edit.dialog.delete.sequence"));
if (dbcSequence != null) {
dbcSequence.dispose();
}
dbcSequence = DialogBoxUIFactory.createGenericDialog(ureq, getWindowControl(), translate("cal.edit.dialog.title"), translate("cal.edit.dialog.text"), btnLabels);
dbcSequence.addControllerListener(this);
dbcSequence.setUserObject(guiEvent);
dbcSequence.activate();
return;
}
KalendarRenderWrapper kalendarWrapper = guiEvent.getKalendarRenderWrapper();
pushEditEventController(ureq, kalendarEvent, kalendarWrapper);
} else if (event instanceof CalendarGUIAddEvent) {
pushAddEventController((CalendarGUIAddEvent) event, ureq);
} else if (event instanceof CalendarGUISelectEvent) {
CalendarGUISelectEvent selectEvent = (CalendarGUISelectEvent) event;
if (selectEvent.getKalendarEvent() != null) {
doOpenEventCallout(ureq, selectEvent.getKalendarEvent(), selectEvent.getKalendarRenderWrapper(), selectEvent.getTargetDomId());
}
} else if (event instanceof CalendarGUIMoveEvent) {
CalendarGUIMoveEvent moveEvent = (CalendarGUIMoveEvent) event;
doMove(ureq, moveEvent.getKalendarEvent(), moveEvent.getDayDelta(), moveEvent.getMinuteDelta(), moveEvent.getAllDay());
} else if (event instanceof CalendarGUIResizeEvent) {
CalendarGUIResizeEvent resizeEvent = (CalendarGUIResizeEvent) event;
doResize(ureq, resizeEvent.getKalendarEvent(), resizeEvent.getMinuteDelta(), resizeEvent.getAllDay());
} else if (event instanceof CalendarGUIFormEvent) {
String cmd = event.getCommand();
if (CalendarGUIFormEvent.CONFIGURE.equals(cmd)) {
doConfigure(ureq);
} else if (CalendarGUIFormEvent.AGGREGATED_FEED.equals(cmd)) {
CalendarGUIFormEvent guiEvent = (CalendarGUIFormEvent) event;
doOpenAggregatedFeedUrl(ureq, guiEvent.getTargetDomId());
}
} else if (event instanceof CalendarGUIPrintEvent) {
CalendarGUIPrintEvent printEvent = (CalendarGUIPrintEvent) event;
if (printEvent.getFrom() != null && printEvent.getTo() != null) {
doPrint(printEvent.getFrom(), printEvent.getTo());
} else if (printEvent.getTargetDomId() != null) {
doPrintEventCallout(ureq, printEvent.getTargetDomId());
}
}
}
super.formInnerEvent(ureq, source, event);
}
Aggregations