Search in sources :

Example 1 with CalendarUserConfiguration

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

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)

Example 2 with CalendarUserConfiguration

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

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

the class CollaborationManagerImpl method getCalendar.

@Override
public KalendarRenderWrapper getCalendar(BusinessGroup businessGroup, UserRequest ureq, boolean isAdmin) {
    // do not use a global translator since in the fututre a collaborationtools
    // may be shared among users
    // get the calendar
    KalendarRenderWrapper calRenderWrapper = calendarManager.getGroupCalendar(businessGroup);
    boolean isOwner = businessGroupService.hasRoles(ureq.getIdentity(), businessGroup, GroupRoles.coach.name());
    if (!(isAdmin || isOwner)) {
        // check if participants have read/write access
        int iCalAccess = CollaborationTools.CALENDAR_ACCESS_OWNERS;
        Long lCalAccess = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(businessGroup).lookupCalendarAccess();
        if (lCalAccess != null)
            iCalAccess = lCalAccess.intValue();
        if (iCalAccess == CollaborationTools.CALENDAR_ACCESS_ALL) {
            calRenderWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
        } else {
            calRenderWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
        }
    } else {
        calRenderWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
    }
    CalendarUserConfiguration config = calendarManager.findCalendarConfigForIdentity(calRenderWrapper.getKalendar(), ureq.getIdentity());
    if (config != null) {
        calRenderWrapper.setConfiguration(config);
    }
    return calRenderWrapper;
}
Also used : CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Example 4 with CalendarUserConfiguration

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

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

the class HomeCalendarManager method addCalendars.

/**
 * Append the calendars of a list of groups. The groups must have their calendar tool
 * enabled, this routine doesn't check it.
 * @param ureq
 * @param groups
 * @param isOwner
 * @param calendars
 */
private void addCalendars(List<BusinessGroup> groups, boolean isOwner, boolean isParticipant, List<KalendarRenderWrapper> calendars, Map<CalendarKey, CalendarUserConfiguration> configMap) {
    Map<Long, Long> groupKeyToAccess = CoreSpringFactory.getImpl(CollaborationManager.class).lookupCalendarAccess(groups);
    for (BusinessGroup bGroup : groups) {
        try {
            KalendarRenderWrapper groupCalendarWrapper = calendarManager.getGroupCalendar(bGroup);
            groupCalendarWrapper.setPrivateEventsVisible(true);
            // set calendar access
            int iCalAccess = CollaborationTools.CALENDAR_ACCESS_OWNERS;
            Long lCalAccess = groupKeyToAccess.get(bGroup.getKey());
            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);
            }
            if (isOwner || isParticipant) {
                groupCalendarWrapper.setPrivateEventsVisible(true);
            }
            calendars.add(groupCalendarWrapper);
        } catch (Exception e) {
            log.error("Cannot read calendar of group: " + bGroup, e);
        }
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) CollaborationManager(org.olat.collaboration.CollaborationManager) CorruptedCourseException(org.olat.course.CorruptedCourseException)

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