Search in sources :

Example 16 with KalendarEvent

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Identity(org.olat.core.id.Identity) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) File(java.io.File) CalendarImportTest(org.olat.commons.calendar.CalendarImportTest) Test(org.junit.Test)

Example 17 with KalendarEvent

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());
}
Also used : KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Identity(org.olat.core.id.Identity) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) File(java.io.File) URL(java.net.URL) CalendarImportTest(org.olat.commons.calendar.CalendarImportTest) Test(org.junit.Test)

Example 18 with KalendarEvent

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());
}
Also used : KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Identity(org.olat.core.id.Identity) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) File(java.io.File) URL(java.net.URL) CalendarImportTest(org.olat.commons.calendar.CalendarImportTest) Test(org.junit.Test)

Example 19 with KalendarEvent

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");
}
Also used : KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) CountDownLatch(java.util.concurrent.CountDownLatch) ValidationException(net.fortuna.ical4j.model.ValidationException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Date(java.util.Date) Kalendar(org.olat.commons.calendar.model.Kalendar) Identity(org.olat.core.id.Identity) CalendarImportTest(org.olat.commons.calendar.CalendarImportTest) Test(org.junit.Test)

Example 20 with KalendarEvent

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);
}
Also used : CalendarGUIAddEvent(org.olat.commons.calendar.ui.events.CalendarGUIAddEvent) CalendarGUIEditEvent(org.olat.commons.calendar.ui.events.CalendarGUIEditEvent) CalendarGUIResizeEvent(org.olat.commons.calendar.ui.events.CalendarGUIResizeEvent) ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) CalendarGUIMoveEvent(org.olat.commons.calendar.ui.events.CalendarGUIMoveEvent) CalendarGUIPrintEvent(org.olat.commons.calendar.ui.events.CalendarGUIPrintEvent) CalendarGUISelectEvent(org.olat.commons.calendar.ui.events.CalendarGUISelectEvent) CalendarGUIFormEvent(org.olat.commons.calendar.ui.events.CalendarGUIFormEvent)

Aggregations

KalendarEvent (org.olat.commons.calendar.model.KalendarEvent)172 Date (java.util.Date)80 Kalendar (org.olat.commons.calendar.model.Kalendar)68 Test (org.junit.Test)48 KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)46 Identity (org.olat.core.id.Identity)46 ArrayList (java.util.ArrayList)42 Calendar (java.util.Calendar)40 CalendarImportTest (org.olat.commons.calendar.CalendarImportTest)34 CalendarManager (org.olat.commons.calendar.CalendarManager)32 OLATResourceable (org.olat.core.id.OLATResourceable)20 CalendarGUIModifiedEvent (org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent)18 File (java.io.File)16 ExDate (net.fortuna.ical4j.model.property.ExDate)16 ICourse (org.olat.course.ICourse)16 URI (java.net.URI)14 HttpResponse (org.apache.http.HttpResponse)14 URL (java.net.URL)12 KalendarRecurEvent (org.olat.commons.calendar.model.KalendarRecurEvent)12 EventVO (org.olat.commons.calendar.restapi.EventVO)12