Search in sources :

Example 16 with CalendarUserConfiguration

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);
    }
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration)

Example 17 with CalendarUserConfiguration

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;
}
Also used : CalendarKey(org.olat.commons.calendar.model.CalendarKey) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) CalendarFileInfos(org.olat.commons.calendar.model.CalendarFileInfos) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) File(java.io.File) HashSet(java.util.HashSet)

Example 18 with CalendarUserConfiguration

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);
            }
        }
    }
}
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 19 with CalendarUserConfiguration

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;
}
Also used : ImportedCalendar(org.olat.commons.calendar.model.ImportedCalendar) ArrayList(java.util.ArrayList) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) IOException(java.io.IOException)

Example 20 with CalendarUserConfiguration

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;
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Aggregations

CalendarUserConfiguration (org.olat.commons.calendar.model.CalendarUserConfiguration)46 KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)24 Kalendar (org.olat.commons.calendar.model.Kalendar)12 Identity (org.olat.core.id.Identity)12 ArrayList (java.util.ArrayList)10 BusinessGroup (org.olat.group.BusinessGroup)10 CalendarKey (org.olat.commons.calendar.model.CalendarKey)8 Test (org.junit.Test)6 CalendarManager (org.olat.commons.calendar.CalendarManager)6 CorruptedCourseException (org.olat.course.CorruptedCourseException)6 ICourse (org.olat.course.ICourse)6 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 CollaborationTools (org.olat.collaboration.CollaborationTools)4 CollaborationToolsFactory (org.olat.collaboration.CollaborationToolsFactory)4 Roles (org.olat.core.id.Roles)4 CourseGroupManager (org.olat.course.groupsandrights.CourseGroupManager)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2