use of org.olat.commons.calendar.CalendarManager in project OpenOLAT by OpenOLAT.
the class CourseCalendars method getCourseCalendarWrapper.
/**
* Return only the course calendar without any group calendar
* @param ureq
* @param wControl
* @param ores
* @param ne
* @return
*/
public static KalendarRenderWrapper getCourseCalendarWrapper(UserRequest ureq, UserCourseEnvironment courseEnv, NodeEvaluation ne) {
CalendarManager calendarManager = CoreSpringFactory.getImpl(CalendarManager.class);
// add course calendar
ICourse course = CourseFactory.loadCourse(courseEnv.getCourseEnvironment().getCourseResourceableId());
KalendarRenderWrapper courseKalendarWrapper = calendarManager.getCourseCalendar(course);
CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
Identity identity = ureq.getIdentity();
Roles roles = ureq.getUserSession().getRoles();
boolean isPrivileged = !courseEnv.isCourseReadOnly() && (roles.isOLATAdmin() || courseEnv.isAdmin() || (ne != null && ne.isCapabilityAccessible(CalCourseNode.EDIT_CONDITION_ID)) || RepositoryManager.getInstance().isInstitutionalRessourceManagerFor(identity, roles, cgm.getCourseEntry()));
if (isPrivileged) {
courseKalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
courseKalendarWrapper.setPrivateEventsVisible(true);
} else {
courseKalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
courseKalendarWrapper.setPrivateEventsVisible(courseEnv.isAdmin() || courseEnv.isCoach() || courseEnv.isParticipant());
}
CalendarUserConfiguration config = calendarManager.findCalendarConfigForIdentity(courseKalendarWrapper.getKalendar(), ureq.getIdentity());
if (config != null) {
courseKalendarWrapper.setConfiguration(config);
}
return courseKalendarWrapper;
}
use of org.olat.commons.calendar.CalendarManager in project openolat by klemens.
the class CalWebService method deleteEventByCalendar.
@DELETE
@Path("events/{eventId}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_FORM_URLENCODED, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response deleteEventByCalendar(@PathParam("eventId") String eventId, @Context HttpServletRequest httpRequest) {
UserRequest ureq = getUserRequest(httpRequest);
if (!ureq.getUserSession().isAuthenticated()) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
if (calendar == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!hasWriteAccess(calendar)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
CalendarManager calendarManager = CoreSpringFactory.getImpl(CalendarManager.class);
if (eventId == null) {
return Response.ok().status(Status.NOT_FOUND).build();
} else {
KalendarEvent kalEvent = calendar.getKalendar().getEvent(eventId, null);
if (kalEvent == null) {
return Response.ok().status(Status.NOT_FOUND).build();
} else {
calendarManager.removeEventFrom(calendar.getKalendar(), kalEvent);
}
}
return Response.ok().build();
}
use of org.olat.commons.calendar.CalendarManager in project openolat by klemens.
the class CalWebService method addEventsByCalendar.
private Response addEventsByCalendar(List<EventVO> events, HttpServletRequest httpRequest) {
UserRequest ureq = getUserRequest(httpRequest);
if (!ureq.getUserSession().isAuthenticated()) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
if (calendar == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!hasWriteAccess(calendar)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
List<KalendarEvent> kalEventToAdd = new ArrayList<>();
List<KalendarEvent> kalEventToUpdate = new ArrayList<>();
CalendarManager calendarManager = CoreSpringFactory.getImpl(CalendarManager.class);
for (EventVO event : events) {
KalendarEvent kalEvent;
if (!StringHelper.containsNonWhitespace(event.getId())) {
String id = UUID.randomUUID().toString();
kalEvent = new KalendarEvent(id, event.getRecurrenceId(), event.getSubject(), event.getBegin(), event.getEnd());
transfer(event, kalEvent);
kalEventToAdd.add(kalEvent);
} else {
kalEvent = calendar.getKalendar().getEvent(event.getId(), event.getRecurrenceId());
if (kalEvent == null) {
kalEvent = new KalendarEvent(event.getId(), event.getRecurrenceId(), event.getSubject(), event.getBegin(), event.getEnd());
transfer(event, kalEvent);
kalEventToAdd.add(kalEvent);
} else {
kalEvent.setBegin(event.getBegin());
kalEvent.setEnd(event.getEnd());
kalEvent.setSubject(event.getSubject());
transfer(event, kalEvent);
kalEventToUpdate.add(kalEvent);
}
}
}
if (kalEventToAdd.size() > 0) {
calendarManager.addEventTo(calendar.getKalendar(), kalEventToAdd);
}
if (kalEventToUpdate.size() > 0) {
calendarManager.updateEventsFrom(calendar.getKalendar(), kalEventToUpdate);
}
return Response.ok().build();
}
use of org.olat.commons.calendar.CalendarManager in project openolat by klemens.
the class UserCalendarWebService method getPersonalCalendar.
private KalendarRenderWrapper getPersonalCalendar(Identity identity) {
// get the personal calendar
CalendarManager calendarManager = CoreSpringFactory.getImpl(CalendarManager.class);
KalendarRenderWrapper calendarWrapper = calendarManager.getPersonalCalendar(identity);
calendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
calendarWrapper.setPrivateEventsVisible(true);
CalendarUserConfiguration config = calendarManager.findCalendarConfigForIdentity(calendarWrapper.getKalendar(), identity);
if (config != null) {
calendarWrapper.setConfiguration(config);
}
return calendarWrapper;
}
use of org.olat.commons.calendar.CalendarManager in project openolat by klemens.
the class FullCalendarElement method getCurrenceKalendarEvent.
private KalendarRecurEvent getCurrenceKalendarEvent(KalendarRenderWrapper cal, String eventId) {
boolean privateEventsVisible = cal.isPrivateEventsVisible();
CalendarManager calendarManager = CoreSpringFactory.getImpl(CalendarManager.class);
Date currentDate = component.getCurrentDate();
Calendar calendar = Calendar.getInstance();
calendar.setTime(currentDate);
calendar.add(Calendar.MONTH, -2);
Date from = calendar.getTime();
calendar.add(Calendar.MONTH, +4);
Date to = calendar.getTime();
List<KalendarEvent> events = calendarManager.getEvents(cal.getKalendar(), from, to, privateEventsVisible);
for (KalendarEvent event : events) {
if (event instanceof KalendarRecurEvent) {
KalendarRecurEvent kEvent = (KalendarRecurEvent) event;
if (eventId.equals(FullCalendarComponent.normalizeId(event))) {
return kEvent;
}
}
}
return null;
}
Aggregations