Search in sources :

Example 16 with KalendarRenderWrapper

use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper 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 KalendarRenderWrapper

use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper 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 KalendarRenderWrapper

use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper 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 KalendarRenderWrapper

use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project openolat by klemens.

the class WeeklyCalendarController method getCallerKalendarRenderWrapper.

private KalendarRenderWrapper getCallerKalendarRenderWrapper() {
    if (callerOres == null || calendarWrappers == null)
        return null;
    String callerResId = callerOres.getResourceableId().toString();
    for (KalendarRenderWrapper calendarWrapper : calendarWrappers) {
        String calendarType = calendarWrapper.getKalendar().getType();
        String calendarId = calendarWrapper.getKalendar().getCalendarID();
        if (callerResId.equals(calendarId)) {
            if ((WeeklyCalendarController.CALLER_COLLAB.equals(caller) && CalendarManager.TYPE_GROUP.equals(calendarType)) || (WeeklyCalendarController.CALLER_COURSE.equals(caller) && CalendarManager.TYPE_COURSE.equals(calendarType))) {
                return calendarWrapper;
            }
        } else if ((WeeklyCalendarController.CALLER_PROFILE.equals(caller) || WeeklyCalendarController.CALLER_HOME.equals(caller)) && CalendarManager.TYPE_USER.equals(calendarType) && calendarId.equals(callerOres.getResourceableTypeName())) {
            return calendarWrapper;
        }
    }
    return null;
}
Also used : KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Example 20 with KalendarRenderWrapper

use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project openolat by klemens.

the class WeeklyCalendarController method doConfigure.

private void doConfigure(UserRequest ureq) {
    removeAsListenerAndDispose(cmc);
    removeAsListenerAndDispose(configurationCtrl);
    KalendarRenderWrapper alwaysVisibleKalendar = getCallerKalendarRenderWrapper();
    List<KalendarRenderWrapper> allCalendars = new ArrayList<>(calendarWrappers);
    configurationCtrl = new CalendarPersonalConfigurationController(ureq, getWindowControl(), allCalendars, alwaysVisibleKalendar, allowImport);
    listenTo(configurationCtrl);
    String title = translate("cal.configuration.list");
    cmc = new CloseableModalController(getWindowControl(), "c", configurationCtrl.getInitialComponent(), true, title);
    cmc.setContextHelp(getTranslator(), "Calendar");
    listenTo(cmc);
    cmc.activate();
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) ArrayList(java.util.ArrayList) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Aggregations

KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)134 KalendarEvent (org.olat.commons.calendar.model.KalendarEvent)46 ArrayList (java.util.ArrayList)28 Test (org.junit.Test)28 Identity (org.olat.core.id.Identity)26 Date (java.util.Date)24 CalendarUserConfiguration (org.olat.commons.calendar.model.CalendarUserConfiguration)24 Calendar (java.util.Calendar)22 Kalendar (org.olat.commons.calendar.model.Kalendar)22 ICourse (org.olat.course.ICourse)20 File (java.io.File)18 BusinessGroup (org.olat.group.BusinessGroup)16 URI (java.net.URI)14 HttpResponse (org.apache.http.HttpResponse)14 CalendarImportTest (org.olat.commons.calendar.CalendarImportTest)14 URL (java.net.URL)12 EventVO (org.olat.commons.calendar.restapi.EventVO)12 CalendarManager (org.olat.commons.calendar.CalendarManager)10 HttpGet (org.apache.http.client.methods.HttpGet)8 UserRequest (org.olat.core.gui.UserRequest)8