use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project OpenOLAT by OpenOLAT.
the class ImportCalendarManager method importCalendar.
public KalendarRenderWrapper importCalendar(Identity identity, String calendarName, String type, File file) throws IOException {
KalendarRenderWrapper calendarWrapper = null;
Calendar calendar = calendarManager.readCalendar(file);
if (calendar != null) {
String calendarID = getImportedCalendarID(identity, calendarName);
File calendarFile = calendarManager.getCalendarFile(type, calendarID);
if (!file.renameTo(calendarFile)) {
Files.copy(file.toPath(), calendarFile.toPath());
}
importedCalendarDao.createImportedCalendar(identity, calendarName, calendarID, type, null, new Date());
calendarWrapper = calendarManager.getImportedCalendar(identity, calendarID);
calendarWrapper.setDisplayName(calendarName);
calendarWrapper.setPrivateEventsVisible(true);
}
return calendarWrapper;
}
use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper 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.ui.components.KalendarRenderWrapper in project OpenOLAT by OpenOLAT.
the class UserCalendarWebService method getCalendar.
private KalendarRenderWrapper getCalendar(UserRequest ureq, String calendarId) {
int typeIndex = calendarId.indexOf('_');
if (typeIndex <= 0 || (typeIndex + 1 >= calendarId.length())) {
return null;
}
CalendarModule calendarModule = CoreSpringFactory.getImpl(CalendarModule.class);
if (!calendarModule.isEnabled()) {
return null;
}
String type = calendarId.substring(0, typeIndex);
String id = calendarId.substring(typeIndex + 1);
KalendarRenderWrapper wrapper = null;
if ("group".equals(type) && calendarModule.isEnableGroupCalendar()) {
Long groupId = Long.parseLong(id);
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
BusinessGroup group = bgs.loadBusinessGroup(groupId);
if (bgs.isIdentityInBusinessGroup(ureq.getIdentity(), group)) {
CollaborationManager collaborationManager = CoreSpringFactory.getImpl(CollaborationManager.class);
wrapper = collaborationManager.getCalendar(group, ureq, false);
}
} else if ("course".equals(type) && (calendarModule.isEnableCourseElementCalendar() || calendarModule.isEnableCourseToolCalendar())) {
Long courseId = Long.parseLong(id);
IdentityEnvironment ienv = new IdentityEnvironment();
ienv.setIdentity(ureq.getIdentity());
ienv.setRoles(ureq.getUserSession().getRoles());
ICourse course = CourseFactory.loadCourse(courseId);
UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
wrapper = CourseCalendars.getCourseCalendarWrapper(ureq, userCourseEnv, null);
} else if ("user".equals(type) && calendarModule.isEnablePersonalCalendar()) {
if (id.equals(ureq.getIdentity().getName())) {
wrapper = getPersonalCalendar(ureq.getIdentity());
} else if (isAdmin(ureq.getHttpReq())) {
Identity identity = BaseSecurityManager.getInstance().findIdentityByName(id);
wrapper = getPersonalCalendar(identity);
}
}
return wrapper;
}
use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project OpenOLAT by OpenOLAT.
the class UserCalendarWebService method getCalendarWebService.
@Path("{calendarId}")
public CalWebService getCalendarWebService(@PathParam("calendarId") String calendarId, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
UserRequest ureq = getUserRequest(httpRequest);
if (ureq.getIdentity() == null || !ureq.getUserSession().isAuthenticated()) {
throw new WebApplicationException(Response.serverError().status(Status.UNAUTHORIZED).build());
} else if (!ureq.getIdentity().getKey().equals(identityKey) && !isAdmin(httpRequest)) {
throw new WebApplicationException(Response.serverError().status(Status.UNAUTHORIZED).build());
}
KalendarRenderWrapper calendar = getCalendar(ureq, calendarId);
if (calendar == null) {
throw new WebApplicationException(Response.serverError().status(Status.NOT_FOUND).build());
} else if (!hasReadAccess(calendar)) {
throw new WebApplicationException(Response.serverError().status(Status.UNAUTHORIZED).build());
}
return new CalWebService(calendar);
}
use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project OpenOLAT by OpenOLAT.
the class UserCalendarWebService method getCalendars.
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getCalendars(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
UserRequest ureq = getUserRequest(httpRequest);
if (ureq.getIdentity() == null || !ureq.getUserSession().isAuthenticated()) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
} else if (!ureq.getIdentity().getKey().equals(identityKey) && !isAdmin(httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
CollectCalendars visitor = new CollectCalendars();
getCalendars(visitor, ureq);
List<KalendarRenderWrapper> wrappers = visitor.getWrappers();
CalendarVO[] voes = new CalendarVO[wrappers.size()];
int count = 0;
for (KalendarRenderWrapper wrapper : wrappers) {
voes[count++] = new CalendarVO(wrapper, hasWriteAccess(wrapper));
}
return Response.ok(voes).build();
}
Aggregations