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);
}
}
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());
}
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);
}
}
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;
}
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);
}
}
Aggregations