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;
}
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;
}
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);
}
}
}
}
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());
}
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());
}
Aggregations