use of org.olat.commons.calendar.model.CalendarUserConfiguration 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.model.CalendarUserConfiguration 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.model.CalendarUserConfiguration in project openolat by klemens.
the class CalendarUserConfigurationDAOTest method getCalendarUserConfigurations.
@Test
public void getCalendarUserConfigurations() {
Identity user = JunitTestHelper.createAndPersistIdentityAsRndUser("Cal-2");
String calendarId = UUID.randomUUID().toString();
Kalendar calendar = new Kalendar(calendarId, CalendarManager.TYPE_COURSE);
CalendarUserConfiguration config = calendarDao.createCalendarUserConfiguration(calendar, user);
dbInstance.commit();
Assert.assertNotNull(config);
// retrieve
List<CalendarUserConfiguration> configList = calendarDao.getCalendarUserConfigurations(user);
Assert.assertNotNull(configList);
Assert.assertEquals(1, configList.size());
Assert.assertEquals(config, configList.get(0));
// paranoia check
CalendarUserConfiguration loadedConfig = configList.get(0);
Assert.assertNotNull(loadedConfig.getCreationDate());
Assert.assertNotNull(loadedConfig.getLastModified());
Assert.assertEquals(config.getKey(), loadedConfig.getKey());
Assert.assertEquals(calendarId, loadedConfig.getCalendarId());
Assert.assertEquals(CalendarManager.TYPE_COURSE, loadedConfig.getType());
Assert.assertEquals(user, loadedConfig.getIdentity());
Assert.assertTrue(loadedConfig.isVisible());
Assert.assertTrue(loadedConfig.isInAggregatedFeed());
}
use of org.olat.commons.calendar.model.CalendarUserConfiguration in project openolat by klemens.
the class UserInfoMainController method doOpenCalendar.
private WeeklyCalendarController doOpenCalendar(UserRequest ureq) {
removeAsListenerAndDispose(calendarController);
KalendarRenderWrapper calendarWrapper = calendarManager.getPersonalCalendar(chosenIdentity);
CalendarUserConfiguration config = calendarManager.findCalendarConfigForIdentity(calendarWrapper.getKalendar(), getIdentity());
if (config != null) {
calendarWrapper.setConfiguration(config);
}
calendarWrapper.setPrivateEventsVisible(chosenIdentity.equals(ureq.getIdentity()));
if (chosenIdentity.equals(ureq.getIdentity())) {
calendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
} else {
calendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
}
List<KalendarRenderWrapper> calendars = new ArrayList<KalendarRenderWrapper>();
calendars.add(calendarWrapper);
OLATResourceable ores = OresHelper.createOLATResourceableType(CMD_CALENDAR);
WindowControl bwControl = addToHistory(ureq, ores, null);
OLATResourceable callerOres = OresHelper.createOLATResourceableInstance(chosenIdentity.getName(), chosenIdentity.getKey());
calendarController = new WeeklyCalendarController(ureq, bwControl, calendars, WeeklyCalendarController.CALLER_PROFILE, callerOres, false);
listenTo(calendarController);
return calendarController;
}
use of org.olat.commons.calendar.model.CalendarUserConfiguration in project openolat by klemens.
the class CalendarUserConfigurationDAO method createCalendarUserConfiguration.
/**
* Create and persist an user configuration
* @param calendar
* @param identity
* @param token
* @param aggregated
* @param visible
* @return
*/
public CalendarUserConfiguration createCalendarUserConfiguration(Kalendar calendar, Identity identity, String token, boolean aggregated, boolean visible) {
CalendarUserConfiguration config = new CalendarUserConfiguration();
config.setCreationDate(new Date());
config.setLastModified(config.getCreationDate());
config.setCalendarId(calendar.getCalendarID());
config.setType(calendar.getType());
config.setToken(token);
config.setIdentity(identity);
config.setInAggregatedFeed(aggregated);
config.setVisible(visible);
dbInstance.getCurrentEntityManager().persist(config);
return config;
}
Aggregations