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