Search in sources :

Example 21 with CalendarUserConfiguration

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

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

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

the class CalendarUserConfigurationDAOTest method getCalendarUserConfigurations_byTypes.

@Test
public void getCalendarUserConfigurations_byTypes() {
    Identity user = JunitTestHelper.createAndPersistIdentityAsRndUser("Cal-3");
    String calendarId = UUID.randomUUID().toString();
    Kalendar courseCalendar = new Kalendar(calendarId, CalendarManager.TYPE_COURSE);
    CalendarUserConfiguration courseCalConfig = calendarDao.createCalendarUserConfiguration(courseCalendar, user);
    Kalendar groupCalendar = new Kalendar(calendarId, CalendarManager.TYPE_GROUP);
    CalendarUserConfiguration groupCalConfig = calendarDao.createCalendarUserConfiguration(groupCalendar, user);
    Kalendar personalCalendar = new Kalendar(user.getName(), CalendarManager.TYPE_USER);
    CalendarUserConfiguration personalCalConfig = calendarDao.createCalendarUserConfiguration(personalCalendar, user);
    dbInstance.commit();
    Assert.assertNotNull(courseCalConfig);
    // get all
    List<CalendarUserConfiguration> configList = calendarDao.getCalendarUserConfigurations(user);
    Assert.assertNotNull(configList);
    Assert.assertEquals(3, configList.size());
    Assert.assertTrue(configList.contains(courseCalConfig));
    Assert.assertTrue(configList.contains(groupCalConfig));
    Assert.assertTrue(configList.contains(personalCalConfig));
    // get course
    List<CalendarUserConfiguration> courseConfigList = calendarDao.getCalendarUserConfigurations(user, CalendarManager.TYPE_COURSE);
    Assert.assertNotNull(courseConfigList);
    Assert.assertEquals(1, courseConfigList.size());
    Assert.assertTrue(courseConfigList.contains(courseCalConfig));
    // null check
    List<CalendarUserConfiguration> nullConfigList = calendarDao.getCalendarUserConfigurations(user, (String) null);
    Assert.assertNotNull(nullConfigList);
    Assert.assertEquals(3, nullConfigList.size());
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 23 with CalendarUserConfiguration

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

the class OLATUpgrade_10_4_0 method processCalendarProperty.

private void processCalendarProperty(Property property) {
    String calendarId;
    Identity identity = property.getIdentity();
    String resourceType = property.getResourceTypeName();
    if (StringHelper.containsNonWhitespace(resourceType) && property.getResourceTypeId() != null) {
        calendarId = property.getResourceTypeId().toString();
    } else {
        resourceType = CalendarManager.TYPE_USER;
        calendarId = identity.getName();
    }
    CalendarUserConfiguration config = calendarUserConfigurationDao.getCalendarUserConfiguration(identity, calendarId, resourceType);
    if (config == null) {
        String token = property.getStringValue();
        Kalendar mockCal = new Kalendar(calendarId, resourceType);
        calendarUserConfigurationDao.createCalendarUserConfiguration(mockCal, identity, token, true, true);
    }
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) Identity(org.olat.core.id.Identity)

Example 24 with CalendarUserConfiguration

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

the class CourseCalendarController method getListOfCalendarWrappers.

private List<KalendarRenderWrapper> getListOfCalendarWrappers(UserRequest ureq) {
    List<KalendarRenderWrapper> calendars = new ArrayList<>();
    // add course calendar
    ICourse course = CourseFactory.loadCourse(userCourseEnv.getCourseEnvironment().getCourseGroupManager().getCourseEntry());
    courseKalendarWrapper = calendarManager.getCourseCalendar(course);
    CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
    Roles roles = ureq.getUserSession().getRoles();
    boolean isPrivileged = !userCourseEnv.isCourseReadOnly() && (roles.isOLATAdmin() || userCourseEnv.isAdmin() || repositoryManager.isInstitutionalRessourceManagerFor(getIdentity(), roles, cgm.getCourseEntry()));
    if (isPrivileged) {
        courseKalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
        courseKalendarWrapper.setPrivateEventsVisible(true);
    } else {
        courseKalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
        courseKalendarWrapper.setPrivateEventsVisible(userCourseEnv.isAdmin() || userCourseEnv.isCoach() || userCourseEnv.isParticipant());
    }
    CalendarUserConfiguration config = calendarManager.findCalendarConfigForIdentity(courseKalendarWrapper.getKalendar(), getIdentity());
    if (config != null) {
        courseKalendarWrapper.setConfiguration(config);
    }
    // add link provider
    CourseLinkProviderController clpc = new CourseLinkProviderController(course, Collections.<ICourse>singletonList(course), ureq, getWindowControl());
    courseKalendarWrapper.setLinkProvider(clpc);
    calendars.add(courseKalendarWrapper);
    // add course group calendars
    // learning groups
    List<BusinessGroup> ownerGroups = cgm.getOwnedBusinessGroups(getIdentity());
    addCalendars(ownerGroups, !userCourseEnv.isCourseReadOnly(), clpc, calendars);
    List<BusinessGroup> attendedGroups = cgm.getParticipatingBusinessGroups(getIdentity());
    for (Iterator<BusinessGroup> ownerGroupsIterator = ownerGroups.iterator(); ownerGroupsIterator.hasNext(); ) {
        BusinessGroup ownerGroup = ownerGroupsIterator.next();
        if (attendedGroups.contains(ownerGroup))
            attendedGroups.remove(ownerGroup);
    }
    addCalendars(attendedGroups, false, clpc, calendars);
    return calendars;
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) Roles(org.olat.core.id.Roles) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Example 25 with CalendarUserConfiguration

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

the class ICalFileCalendarManager method saveCalendarConfigForIdentity.

@Override
public void saveCalendarConfigForIdentity(KalendarRenderWrapper wrapper, Identity identity) {
    Kalendar calendar = wrapper.getKalendar();
    CalendarUserConfiguration configuration = calendarUserConfigDao.getCalendarUserConfiguration(identity, calendar.getCalendarID(), calendar.getType());
    if (configuration == null) {
        configuration = calendarUserConfigDao.createCalendarUserConfiguration(wrapper.getKalendar(), identity, wrapper.getToken(), wrapper.isInAggregatedFeed(), wrapper.isVisible());
    } else {
        configuration.setVisible(wrapper.isVisible());
        configuration.setCssClass(wrapper.getCssClass());
        configuration.setToken(wrapper.getToken());
        configuration.setInAggregatedFeed(wrapper.isInAggregatedFeed());
        configuration = calendarUserConfigDao.update(configuration);
    }
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration)

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