Search in sources :

Example 26 with CalendarUserConfiguration

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

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 27 with CalendarUserConfiguration

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

the class ICalServlet method getIcalDocument.

/**
 * Reads in the appropriate ics file, depending upon the pathInfo:<br>
 * <ul>
 * 	<li>/aggregated/<config key>/AUTH_TOKEN.ics</li>
 *  <li>/user/<user_name>/AUTH_TOKEN.ics</li>
 *  <li>/group/<user_name>/AUTH_TOKEN/<group_id>.ics</li>
 *  <li>/course/<user_name>/AUTH_TOKEN/<course_unique_id>.ics</li>
 * </ul>
 *
 * @param pathInfo
 * @return Calendar
 */
private void getIcalDocument(String requestUrl, HttpServletRequest request, HttpServletResponse response) throws ValidationException, IOException {
    // get the individual path tokens
    String pathInfo;
    int icsIndex = requestUrl.indexOf(".ics");
    if (icsIndex > 0) {
        pathInfo = requestUrl.substring(0, icsIndex);
    } else {
        pathInfo = requestUrl;
    }
    String[] pathInfoTokens = pathInfo.split("/");
    if (pathInfoTokens.length < 4) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, requestUrl);
        return;
    }
    String calendarType = pathInfoTokens[1];
    String userName = pathInfoTokens[2];
    String authToken = pathInfoTokens[3];
    String calendarID;
    if (CalendarManager.TYPE_COURSE.equals(calendarType) || CalendarManager.TYPE_GROUP.equals(calendarType)) {
        if (pathInfoTokens.length < 5) {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST, requestUrl);
            return;
        }
        calendarID = pathInfoTokens[4];
    } else if (CalendarManager.TYPE_USER.equals(calendarType)) {
        if (pathInfoTokens.length < 5) {
            calendarID = userName;
        } else {
            calendarID = pathInfoTokens[4];
        }
    } else if (CalendarManager.TYPE_USER_AGGREGATED.equals(calendarType)) {
        calendarID = userName;
    } else {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, requestUrl);
        log.warn("Type not supported: " + pathInfo);
        return;
    }
    try {
        response.setCharacterEncoding("UTF-8");
        setCacheControl(response);
    } catch (Exception e) {
        log.error("", e);
    }
    CalendarManager calendarManager = CoreSpringFactory.getImpl(CalendarManager.class);
    if (CalendarManager.TYPE_USER_AGGREGATED.equals(calendarType)) {
        // check the authentication token
        CalendarUserConfiguration config = calendarManager.getCalendarUserConfiguration(Long.parseLong(userName));
        String savedToken = config == null ? null : config.getToken();
        if (authToken == null || savedToken == null || !savedToken.equals(authToken)) {
            log.warn("Authenticity Check failed for the ical feed path: " + pathInfo);
            response.sendError(HttpServletResponse.SC_UNAUTHORIZED, requestUrl);
        } else {
            generateAggregatedCalendar(config.getIdentity(), request, response);
        }
    } else if (calendarManager.calendarExists(calendarType, calendarID)) {
        // check the authentication token
        String savedToken = null;
        if (StringHelper.isLong(userName)) {
            CalendarUserConfiguration config = calendarManager.getCalendarUserConfiguration(Long.parseLong(userName));
            savedToken = config == null ? null : config.getToken();
        }
        if (savedToken == null) {
            savedToken = calendarManager.getCalendarToken(calendarType, calendarID, userName);
        }
        if (authToken == null || savedToken == null || !savedToken.equals(authToken)) {
            log.warn("Authenticity Check failed for the ical feed path: " + pathInfo);
            response.sendError(HttpServletResponse.SC_UNAUTHORIZED, requestUrl);
        } else {
            // read and return the calendar file
            Calendar calendar = calendarManager.readCalendar(calendarType, calendarID);
            DBFactory.getInstance().commitAndCloseSession();
            outputCalendar(calendar, request, response);
        }
    } else {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, requestUrl);
    }
}
Also used : Calendar(net.fortuna.ical4j.model.Calendar) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) ValidationException(net.fortuna.ical4j.model.ValidationException) ServletException(javax.servlet.ServletException) URISyntaxException(java.net.URISyntaxException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) ParserException(net.fortuna.ical4j.data.ParserException) IOException(java.io.IOException)

Example 28 with CalendarUserConfiguration

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

the class CalendarUserConfigurationDAO method createCalendarUserConfiguration.

/**
 * Create and persist an user configuration
 * @param calendar
 * @param identity
 * @param token
 * @param aggregated
 * @param visible
 * @return
 */
public CalendarUserConfiguration createCalendarUserConfiguration(Kalendar calendar, Identity identity, String token, boolean aggregated, boolean visible) {
    CalendarUserConfiguration config = new CalendarUserConfiguration();
    config.setCreationDate(new Date());
    config.setLastModified(config.getCreationDate());
    config.setCalendarId(calendar.getCalendarID());
    config.setType(calendar.getType());
    config.setToken(token);
    config.setIdentity(identity);
    config.setInAggregatedFeed(aggregated);
    config.setVisible(visible);
    dbInstance.getCurrentEntityManager().persist(config);
    return config;
}
Also used : CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) Date(java.util.Date)

Example 29 with CalendarUserConfiguration

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

the class WeeklyCalendarController method getAggregatedCalendarUrl.

private String getAggregatedCalendarUrl() {
    List<CalendarUserConfiguration> configurations = calendarManager.getCalendarUserConfigurationsList(getIdentity(), CalendarManager.TYPE_USER_AGGREGATED);
    CalendarUserConfiguration config;
    if (configurations.isEmpty()) {
        config = calendarManager.createAggregatedCalendarConfig(getIdentity());
    } else if (StringHelper.containsNonWhitespace(configurations.get(0).getToken())) {
        config = configurations.get(0);
    } else {
        config = configurations.get(0);
        config.setToken(RandomStringUtils.randomAlphanumeric(6));
        config = calendarManager.saveCalendarConfig(config);
    }
    return Settings.getServerContextPathURI() + "/ical/" + CalendarManager.TYPE_USER_AGGREGATED + "/" + config.getKey() + "/" + config.getToken() + ".ics";
}
Also used : CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration)

Example 30 with CalendarUserConfiguration

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

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