use of org.olat.commons.calendar.model.CalendarUserConfiguration in project openolat by klemens.
the class OLATUpgrade_10_4_0 method processKalendarConfig.
private void processKalendarConfig(Identity identity, String calendarId, KalendarConfig config) {
Kalendar cal;
CalendarUserConfiguration userConfig;
if (StringHelper.isLong(calendarId)) {
// guess if it's a course or a group calendar
if (calendarMgr.getCalendarFile(CalendarManager.TYPE_COURSE, calendarId) != null) {
cal = new Kalendar(calendarId, CalendarManager.TYPE_COURSE);
} else if (calendarMgr.getCalendarFile(CalendarManager.TYPE_GROUP, calendarId) != null) {
cal = new Kalendar(calendarId, CalendarManager.TYPE_GROUP);
} else {
return;
}
} else {
// personal calendar
cal = new Kalendar(calendarId, CalendarManager.TYPE_USER);
}
userConfig = calendarUserConfigurationDao.getCalendarUserConfiguration(identity, cal.getCalendarID(), cal.getType());
if (userConfig == null) {
userConfig = calendarUserConfigurationDao.createCalendarUserConfiguration(cal, identity);
userConfig.setCssClass(config.getCss());
userConfig.setVisible(config.isVis());
userConfig = calendarUserConfigurationDao.update(userConfig);
}
}
use of org.olat.commons.calendar.model.CalendarUserConfiguration in project openolat by klemens.
the class HomeCalendarManager method getListOfCalendarsFiles.
@Override
public List<CalendarFileInfos> getListOfCalendarsFiles(Identity identity) {
List<CalendarFileInfos> aggregatedFiles = new ArrayList<>();
Map<CalendarKey, CalendarUserConfiguration> configMap = calendarManager.getCalendarUserConfigurationsMap(identity);
// personal calendar
CalendarKey personalCalendarKey = new CalendarKey(identity.getName(), CalendarManager.TYPE_USER);
CalendarUserConfiguration personalCalendarConfig = configMap.get(personalCalendarKey);
if (calendarModule.isEnablePersonalCalendar() && (personalCalendarConfig == null || personalCalendarConfig.isInAggregatedFeed())) {
File iCalFile = calendarManager.getCalendarICalFile(CalendarManager.TYPE_USER, identity.getName());
if (iCalFile != null) {
aggregatedFiles.add(new CalendarFileInfos(identity.getName(), CalendarManager.TYPE_USER, iCalFile));
}
// reload every hour
List<CalendarFileInfos> importedCalendars = importCalendarManager.getImportedCalendarInfosForIdentity(identity, true);
aggregatedFiles.addAll(importedCalendars);
}
// group calendars
if (calendarModule.isEnableGroupCalendar()) {
SearchBusinessGroupParams groupParams = new SearchBusinessGroupParams(identity, true, true);
groupParams.addTools(CollaborationTools.TOOL_CALENDAR);
List<BusinessGroup> groups = businessGroupService.findBusinessGroups(groupParams, null, 0, -1);
Set<BusinessGroup> resourceSet = new HashSet<>();
for (BusinessGroup group : groups) {
if (resourceSet.contains(group)) {
continue;
} else {
resourceSet.add(group);
}
String calendarId = group.getKey().toString();
CalendarKey key = new CalendarKey(calendarId, CalendarManager.TYPE_GROUP);
CalendarUserConfiguration calendarConfig = configMap.get(key);
if (calendarConfig == null || calendarConfig.isInAggregatedFeed()) {
File iCalFile = calendarManager.getCalendarICalFile(CalendarManager.TYPE_GROUP, calendarId);
if (iCalFile != null) {
aggregatedFiles.add(new CalendarFileInfos(calendarId, CalendarManager.TYPE_GROUP, iCalFile));
}
}
}
}
if (calendarModule.isEnableCourseElementCalendar() || calendarModule.isEnableCourseToolCalendar()) {
List<Object[]> resources = getCourses(identity);
Set<RepositoryEntry> resourceSet = new HashSet<>();
for (Object[] resource : resources) {
RepositoryEntry courseEntry = (RepositoryEntry) resource[0];
if (resourceSet.contains(courseEntry)) {
continue;
} else {
resourceSet.add(courseEntry);
}
String calendarId = courseEntry.getOlatResource().getResourceableId().toString();
CalendarKey key = new CalendarKey(calendarId, CalendarManager.TYPE_COURSE);
CalendarUserConfiguration calendarConfig = configMap.get(key);
if (calendarConfig == null || calendarConfig.isInAggregatedFeed()) {
File iCalFile = calendarManager.getCalendarICalFile(CalendarManager.TYPE_COURSE, calendarId);
if (iCalFile != null) {
aggregatedFiles.add(new CalendarFileInfos(calendarId, CalendarManager.TYPE_COURSE, iCalFile));
}
}
}
}
return aggregatedFiles;
}
use of org.olat.commons.calendar.model.CalendarUserConfiguration in project openolat by klemens.
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 ImportCalendarManager method getImportedCalendarsForIdentity.
/**
* Get imported calendars for a user.
* @param ureq
* @return
*/
public List<KalendarRenderWrapper> getImportedCalendarsForIdentity(Identity identity, boolean reload) {
// initialize the calendars list
List<KalendarRenderWrapper> calendars = new ArrayList<KalendarRenderWrapper>();
if (calendarModule.isEnabled() && calendarModule.isEnablePersonalCalendar()) {
long timestamp = System.currentTimeMillis();
List<ImportedCalendar> importedCalendars = importedCalendarDao.getImportedCalendars(identity);
KalendarEventFilter filter = new KalendarEventFilter(identity, importedCalendars);
for (ImportedCalendar importedCalendar : importedCalendars) {
try {
if (reload) {
reloadImportCalendar(importedCalendar, timestamp, filter);
}
String calendarId = importedCalendar.getCalendarId();
KalendarRenderWrapper calendarWrapper = calendarManager.getImportedCalendar(identity, calendarId);
calendarWrapper.setDisplayName(importedCalendar.getDisplayName());
calendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
calendarWrapper.setImported(true);
CalendarUserConfiguration config = calendarManager.findCalendarConfigForIdentity(calendarWrapper.getKalendar(), identity);
if (config != null) {
calendarWrapper.setConfiguration(config);
}
calendars.add(calendarWrapper);
} catch (Exception e) {
log.error("Cannot read an imported file", e);
}
}
Collections.sort(calendars, KalendarComparator.getInstance());
}
return calendars;
}
use of org.olat.commons.calendar.model.CalendarUserConfiguration in project openolat by klemens.
the class UserCalendarWebService method getPersonalCalendar.
private KalendarRenderWrapper getPersonalCalendar(Identity identity) {
// get the personal calendar
CalendarManager calendarManager = CoreSpringFactory.getImpl(CalendarManager.class);
KalendarRenderWrapper calendarWrapper = calendarManager.getPersonalCalendar(identity);
calendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
calendarWrapper.setPrivateEventsVisible(true);
CalendarUserConfiguration config = calendarManager.findCalendarConfigForIdentity(calendarWrapper.getKalendar(), identity);
if (config != null) {
calendarWrapper.setConfiguration(config);
}
return calendarWrapper;
}
Aggregations