Search in sources :

Example 96 with KalendarRenderWrapper

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

the class CourseCalendarController method needToDifferentiateManagedEvents.

private boolean needToDifferentiateManagedEvents(List<KalendarRenderWrapper> calednarWrappers) {
    boolean hasManaged = false;
    for (KalendarRenderWrapper wrapper : calednarWrappers) {
        Kalendar cal = wrapper.getKalendar();
        hasManaged |= cal.hasManagedEvents();
    }
    return hasManaged;
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Example 97 with KalendarRenderWrapper

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

the class HomeCalendarManager method getListOfCalendarWrappers.

@Override
public List<KalendarRenderWrapper> getListOfCalendarWrappers(UserRequest ureq, WindowControl wControl) {
    if (!calendarModule.isEnabled()) {
        return new ArrayList<KalendarRenderWrapper>();
    }
    Identity identity = ureq.getIdentity();
    List<KalendarRenderWrapper> calendars = new ArrayList<KalendarRenderWrapper>();
    Map<CalendarKey, CalendarUserConfiguration> configMap = calendarManager.getCalendarUserConfigurationsMap(ureq.getIdentity());
    appendPersonalCalendar(identity, calendars, configMap);
    appendGroupCalendars(identity, calendars, configMap);
    appendCourseCalendars(ureq, wControl, calendars, configMap);
    // reload every hour
    List<KalendarRenderWrapper> importedCalendars = importCalendarManager.getImportedCalendarsForIdentity(identity, true);
    for (KalendarRenderWrapper importedCalendar : importedCalendars) {
        importedCalendar.setPrivateEventsVisible(true);
    }
    calendars.addAll(importedCalendars);
    return calendars;
}
Also used : CalendarKey(org.olat.commons.calendar.model.CalendarKey) ArrayList(java.util.ArrayList) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) Identity(org.olat.core.id.Identity) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Example 98 with KalendarRenderWrapper

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

the class HomeCalendarManager method appendCourseCalendars.

private void appendCourseCalendars(UserRequest ureq, WindowControl wControl, List<KalendarRenderWrapper> calendars, Map<CalendarKey, CalendarUserConfiguration> configMap) {
    if (calendarModule.isEnableCourseElementCalendar() || calendarModule.isEnableCourseToolCalendar()) {
        // add course calendars
        List<Object[]> resources = getCourses(ureq.getIdentity());
        Set<OLATResource> editoredResources = getEditorGrants(ureq.getIdentity());
        Set<Long> duplicates = new HashSet<>();
        for (Object[] resource : resources) {
            RepositoryEntry courseEntry = (RepositoryEntry) resource[0];
            if (duplicates.contains(courseEntry.getKey())) {
                continue;
            }
            duplicates.add(courseEntry.getKey());
            String role = (String) resource[1];
            Long courseResourceableID = courseEntry.getOlatResource().getResourceableId();
            try {
                ICourse course = CourseFactory.loadCourse(courseEntry);
                if (isCourseCalendarEnabled(course)) {
                    // calendar course aren't enabled per default but course node of type calendar are always possible
                    // REVIEW if (!course.getCourseEnvironment().getCourseConfig().isCalendarEnabled()) continue;
                    // add course calendar
                    KalendarRenderWrapper courseCalendarWrapper = calendarManager.getCourseCalendar(course);
                    boolean isPrivileged = GroupRoles.owner.name().equals(role) || editoredResources.contains(courseEntry.getOlatResource());
                    if (isPrivileged) {
                        courseCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
                    } else {
                        courseCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
                    }
                    if (role != null && (GroupRoles.owner.name().equals(role) || GroupRoles.coach.name().equals(role) || GroupRoles.participant.name().equals(role))) {
                        courseCalendarWrapper.setPrivateEventsVisible(true);
                    }
                    CalendarUserConfiguration config = configMap.get(courseCalendarWrapper.getCalendarKey());
                    if (config != null) {
                        courseCalendarWrapper.setConfiguration(config);
                    }
                    courseCalendarWrapper.setLinkProvider(new CourseLinkProviderController(course, Collections.singletonList(course), ureq, wControl));
                    calendars.add(courseCalendarWrapper);
                }
            } catch (CorruptedCourseException e) {
                OLATResource olatResource = courseEntry.getOlatResource();
                log.error("Corrupted course: " + olatResource.getResourceableTypeName() + " :: " + courseResourceableID, null);
            } catch (Exception e) {
                OLATResource olatResource = courseEntry.getOlatResource();
                log.error("Cannor read calendar of course: " + olatResource.getResourceableTypeName() + " :: " + courseResourceableID, null);
            }
        }
    }
}
Also used : OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) CourseLinkProviderController(org.olat.course.run.calendar.CourseLinkProviderController) RepositoryEntry(org.olat.repository.RepositoryEntry) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) CorruptedCourseException(org.olat.course.CorruptedCourseException) CorruptedCourseException(org.olat.course.CorruptedCourseException) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) HashSet(java.util.HashSet)

Example 99 with KalendarRenderWrapper

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

the class ICalFileCalendarManagerTest method testImportICal_icalFullDay.

@Test
public void testImportICal_icalFullDay() throws URISyntaxException, IOException {
    Identity test = JunitTestHelper.createAndPersistIdentityAsRndUser("ur3-");
    URL calendarUrl = ICalFileCalendarManagerTest.class.getResource("Fullday_ical.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(3, events.size());
    // 24 hours but on 2 days
    KalendarEvent on2days = importedCalendar.getKalendar().getEvent("EFE10508-15B0-4FCE-A258-37BA642B760D", null);
    Assert.assertFalse(on2days.isAllDayEvent());
    // real all day with the iCal standard
    KalendarEvent allDay = importedCalendar.getKalendar().getEvent("14C0ACCD-AC0B-4B10-A448-0BF129492091", null);
    Assert.assertTrue(allDay.isAllDayEvent());
    // almost a full day bit it miss one minute
    KalendarEvent longDay = importedCalendar.getKalendar().getEvent("C562E736-DCFF-4002-9E5B-77D891D4A322", null);
    Assert.assertFalse(longDay.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 100 with KalendarRenderWrapper

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

the class ICalFileCalendarManagerTest method testListEventsForPeriodWithoutDTEndEvent.

/**
 * Check a NPE
 * @throws IOException
 */
@Test
public void testListEventsForPeriodWithoutDTEndEvent() 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.assertEquals("e73iiu9masoddi4g0vllmi2ht0@google.com", event.getID());
    Assert.assertNull(event.getEnd());
    // test persist
    boolean allOk = calendarManager.persistCalendar(reloadCalWrapper.getKalendar());
    Assert.assertTrue(allOk);
    // an other possible RS
    // within period
    Date periodStart = CalendarUtils.getDate(2010, Calendar.MARCH, 15);
    Date periodEnd = CalendarUtils.getDate(2010, Calendar.MARCH, 20);
    List<KalendarEvent> eventsForPeriod = calendarManager.getEvents(reloadCalWrapper.getKalendar(), periodStart, periodEnd, true);
    Assert.assertNotNull(eventsForPeriod);
    Assert.assertEquals(0, eventsForPeriod.size());
    KalendarEvent eventForPeriod = events.iterator().next();
    Assert.assertEquals("e73iiu9masoddi4g0vllmi2ht0@google.com", eventForPeriod.getID());
    // out of scope
    Date periodStart2 = CalendarUtils.getDate(2008, Calendar.APRIL, 15);
    Date periodEnd2 = CalendarUtils.getDate(2008, Calendar.APRIL, 17);
    List<KalendarEvent> eventsOutOfPeriod = calendarManager.getEvents(reloadCalWrapper.getKalendar(), periodStart2, periodEnd2, true);
    Assert.assertNotNull(eventsOutOfPeriod);
    Assert.assertTrue(eventsOutOfPeriod.isEmpty());
}
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) Date(java.util.Date) CalendarImportTest(org.olat.commons.calendar.CalendarImportTest) Test(org.junit.Test)

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