Search in sources :

Example 6 with CalendarManager

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;
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) CalendarManager(org.olat.commons.calendar.CalendarManager) 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) Identity(org.olat.core.id.Identity)

Example 7 with CalendarManager

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();
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 8 with CalendarManager

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();
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest)

Example 9 with CalendarManager

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;
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Example 10 with CalendarManager

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;
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) KalendarRecurEvent(org.olat.commons.calendar.model.KalendarRecurEvent) Calendar(java.util.Calendar) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Date(java.util.Date)

Aggregations

CalendarManager (org.olat.commons.calendar.CalendarManager)28 KalendarEvent (org.olat.commons.calendar.model.KalendarEvent)20 ArrayList (java.util.ArrayList)12 Kalendar (org.olat.commons.calendar.model.Kalendar)12 ICourse (org.olat.course.ICourse)12 KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)10 CalendarUserConfiguration (org.olat.commons.calendar.model.CalendarUserConfiguration)6 Identity (org.olat.core.id.Identity)6 Calendar (java.util.Calendar)4 Date (java.util.Date)4 BaseSecurity (org.olat.basesecurity.BaseSecurity)4 UserRequest (org.olat.core.gui.UserRequest)4 OLATResourceable (org.olat.core.id.OLATResourceable)4 CourseGroupManager (org.olat.course.groupsandrights.CourseGroupManager)4 BusinessGroup (org.olat.group.BusinessGroup)4 RestSecurityHelper.getUserRequest (org.olat.restapi.security.RestSecurityHelper.getUserRequest)4 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2