Search in sources :

Example 1 with CalendarKey

use of org.olat.commons.calendar.model.CalendarKey in project OpenOLAT by OpenOLAT.

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 2 with CalendarKey

use of org.olat.commons.calendar.model.CalendarKey in project OpenOLAT by OpenOLAT.

the class ICalFileCalendarManager method getCalendarUserConfigurationsMap.

@Override
public Map<CalendarKey, CalendarUserConfiguration> getCalendarUserConfigurationsMap(IdentityRef identity, String... types) {
    List<CalendarUserConfiguration> list = calendarUserConfigDao.getCalendarUserConfigurations(identity, types);
    Map<CalendarKey, CalendarUserConfiguration> map = new HashMap<>();
    for (CalendarUserConfiguration config : list) {
        map.put(new CalendarKey(config.getCalendarId(), config.getType()), config);
    }
    return map;
}
Also used : CalendarKey(org.olat.commons.calendar.model.CalendarKey) HashMap(java.util.HashMap) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration)

Example 3 with CalendarKey

use of org.olat.commons.calendar.model.CalendarKey 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 4 with CalendarKey

use of org.olat.commons.calendar.model.CalendarKey in project OpenOLAT by OpenOLAT.

the class CourseCalendars method addCalendars.

private static void addCalendars(UserRequest ureq, UserCourseEnvironment courseEnv, List<BusinessGroup> groups, boolean isOwner, LinkProvider linkProvider, List<KalendarRenderWrapper> calendars) {
    if (groups == null || groups.isEmpty())
        return;
    CollaborationToolsFactory collabFactory = CollaborationToolsFactory.getInstance();
    CalendarManager calendarManager = CoreSpringFactory.getImpl(CalendarManager.class);
    Map<CalendarKey, CalendarUserConfiguration> configMap = calendarManager.getCalendarUserConfigurationsMap(ureq.getIdentity(), CalendarManager.TYPE_GROUP);
    for (BusinessGroup bGroup : groups) {
        CollaborationTools collabTools = collabFactory.getOrCreateCollaborationTools(bGroup);
        if (!collabTools.isToolEnabled(CollaborationTools.TOOL_CALENDAR)) {
            continue;
        }
        boolean member = courseEnv.isIdentityInCourseGroup(bGroup.getKey());
        KalendarRenderWrapper groupCalendarWrapper = calendarManager.getGroupCalendar(bGroup);
        groupCalendarWrapper.setPrivateEventsVisible(member || isOwner);
        // set calendar access
        int iCalAccess = CollaborationTools.CALENDAR_ACCESS_OWNERS;
        Long lCalAccess = collabTools.lookupCalendarAccess();
        if (lCalAccess != null)
            iCalAccess = lCalAccess.intValue();
        if (iCalAccess == CollaborationTools.CALENDAR_ACCESS_OWNERS && !isOwner) {
            groupCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
        } else {
            groupCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
        }
        CalendarUserConfiguration config = configMap.get(groupCalendarWrapper.getCalendarKey());
        if (config != null) {
            groupCalendarWrapper.setConfiguration(config);
        }
        groupCalendarWrapper.setLinkProvider(linkProvider);
        calendars.add(groupCalendarWrapper);
    }
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) CalendarKey(org.olat.commons.calendar.model.CalendarKey) BusinessGroup(org.olat.group.BusinessGroup) CollaborationTools(org.olat.collaboration.CollaborationTools) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) CollaborationToolsFactory(org.olat.collaboration.CollaborationToolsFactory)

Example 5 with CalendarKey

use of org.olat.commons.calendar.model.CalendarKey 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)

Aggregations

CalendarKey (org.olat.commons.calendar.model.CalendarKey)8 CalendarUserConfiguration (org.olat.commons.calendar.model.CalendarUserConfiguration)8 ArrayList (java.util.ArrayList)4 KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)4 BusinessGroup (org.olat.group.BusinessGroup)4 File (java.io.File)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 CollaborationTools (org.olat.collaboration.CollaborationTools)2 CollaborationToolsFactory (org.olat.collaboration.CollaborationToolsFactory)2 CalendarManager (org.olat.commons.calendar.CalendarManager)2 CalendarFileInfos (org.olat.commons.calendar.model.CalendarFileInfos)2 Identity (org.olat.core.id.Identity)2 SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2