Search in sources :

Example 1 with CalendarFileInfos

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

use of org.olat.commons.calendar.model.CalendarFileInfos in project openolat by klemens.

the class ImportCalendarManager method getImportedCalendarInfosForIdentity.

public List<CalendarFileInfos> getImportedCalendarInfosForIdentity(Identity identity, boolean reload) {
    List<CalendarFileInfos> calendars = new ArrayList<CalendarFileInfos>();
    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) {
            if (reload) {
                reloadImportCalendar(importedCalendar, timestamp, filter);
            }
            String calendarId = importedCalendar.getCalendarId();
            File calendarFile = calendarManager.getCalendarFile(CalendarManager.TYPE_USER, calendarId);
            CalendarFileInfos calendarInfos = new CalendarFileInfos(calendarId, CalendarManager.TYPE_USER, calendarFile);
            calendars.add(calendarInfos);
        }
    }
    return calendars;
}
Also used : ImportedCalendar(org.olat.commons.calendar.model.ImportedCalendar) CalendarFileInfos(org.olat.commons.calendar.model.CalendarFileInfos) ArrayList(java.util.ArrayList) File(java.io.File)

Example 3 with CalendarFileInfos

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

the class ImportCalendarManager method getImportedCalendarInfosForIdentity.

public List<CalendarFileInfos> getImportedCalendarInfosForIdentity(Identity identity, boolean reload) {
    List<CalendarFileInfos> calendars = new ArrayList<CalendarFileInfos>();
    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) {
            if (reload) {
                reloadImportCalendar(importedCalendar, timestamp, filter);
            }
            String calendarId = importedCalendar.getCalendarId();
            File calendarFile = calendarManager.getCalendarFile(CalendarManager.TYPE_USER, calendarId);
            CalendarFileInfos calendarInfos = new CalendarFileInfos(calendarId, CalendarManager.TYPE_USER, calendarFile);
            calendars.add(calendarInfos);
        }
    }
    return calendars;
}
Also used : ImportedCalendar(org.olat.commons.calendar.model.ImportedCalendar) CalendarFileInfos(org.olat.commons.calendar.model.CalendarFileInfos) ArrayList(java.util.ArrayList) File(java.io.File)

Example 4 with CalendarFileInfos

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

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

the class ICalServlet method generateAggregatedCalendar.

/**
 * Collect all the calendars, update the URL properties and the UUID.
 *
 * @param identity
 * @param request
 * @param response
 * @throws IOException
 */
private void generateAggregatedCalendar(Identity identity, HttpServletRequest request, HttpServletResponse response) throws IOException {
    PersonalCalendarManager homeCalendarManager = CoreSpringFactory.getImpl(PersonalCalendarManager.class);
    if (identity == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    } else {
        List<CalendarFileInfos> iCalFiles = homeCalendarManager.getListOfCalendarsFiles(identity);
        DBFactory.getInstance().commitAndCloseSession();
        Agent agent = getAgent(request);
        Writer out = response.getWriter();
        out.write(Calendar.BEGIN);
        out.write(':');
        out.write(Calendar.VCALENDAR);
        out.write(Strings.LINE_SEPARATOR);
        out.write(Version.VERSION_2_0.toString());
        out.write(CalScale.GREGORIAN.toString());
        outputTTL(agent, out);
        Set<String> timezoneIds = new HashSet<>();
        int numOfFiles = iCalFiles.size();
        for (int i = 0; i < numOfFiles; i++) {
            outputCalendar(iCalFiles.get(i), out, agent, timezoneIds);
        }
        if (agent == Agent.outlook) {
            outputTimeZoneForOutlook(timezoneIds, out);
        }
        out.write(Calendar.END);
        out.write(':');
        out.write(Calendar.VCALENDAR);
    }
}
Also used : CalendarFileInfos(org.olat.commons.calendar.model.CalendarFileInfos) Writer(java.io.Writer) HashSet(java.util.HashSet)

Aggregations

CalendarFileInfos (org.olat.commons.calendar.model.CalendarFileInfos)6 File (java.io.File)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 Writer (java.io.Writer)2 CalendarKey (org.olat.commons.calendar.model.CalendarKey)2 CalendarUserConfiguration (org.olat.commons.calendar.model.CalendarUserConfiguration)2 ImportedCalendar (org.olat.commons.calendar.model.ImportedCalendar)2 BusinessGroup (org.olat.group.BusinessGroup)2 SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2