Search in sources :

Example 1 with CalendarManager

use of org.olat.commons.calendar.CalendarManager in project OpenOLAT by OpenOLAT.

the class ModifyCourseEvent method clearCalenderSubscriptions.

/**
 * Checks all learning group calendars and the course calendar for publishers (of subscriptions)
 * and sets their state to "1" which indicates that the ressource is deleted.
 */
private static void clearCalenderSubscriptions(OLATResourceable res, ICourse course) {
    // set Publisher state to 1 (= ressource is deleted) for all calendars of the course
    CalendarManager calMan = CoreSpringFactory.getImpl(CalendarManager.class);
    CalendarNotificationManager notificationManager = CoreSpringFactory.getImpl(CalendarNotificationManager.class);
    NotificationsManager nfm = NotificationsManager.getInstance();
    if (course != null) {
        CourseGroupManager courseGroupManager = course.getCourseEnvironment().getCourseGroupManager();
        List<BusinessGroup> learningGroups = courseGroupManager.getAllBusinessGroups();
        // all learning and right group calendars
        for (BusinessGroup bg : learningGroups) {
            KalendarRenderWrapper calRenderWrapper = calMan.getGroupCalendar(bg);
            SubscriptionContext subsContext = notificationManager.getSubscriptionContext(calRenderWrapper);
            Publisher pub = nfm.getPublisher(subsContext);
            if (pub != null) {
                // int 0 is OK -> all other is not OK
                pub.setState(1);
            }
        }
    }
    // the course calendar
    try {
        /**
         * TODO:gs 2010-01-26
         * OLAT-4947: if we do not have an repo entry we get an exception here.
         * This is normal in the case of courseimport and click canceling.
         */
        KalendarRenderWrapper courseCalendar = calMan.getCalendarForDeletion(res);
        if (courseCalendar != null) {
            SubscriptionContext subContext = notificationManager.getSubscriptionContext(courseCalendar, res);
            OLATResourceable oresToDelete = OresHelper.createOLATResourceableInstance(subContext.getResName(), subContext.getResId());
            nfm.deletePublishersOf(oresToDelete);
        }
    } catch (AssertException e) {
    // if we have a broken course (e.g. canceled import or no repo entry somehow) skip calendar deletion...
    }
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) PersistingCourseGroupManager(org.olat.course.groupsandrights.PersistingCourseGroupManager) ImportToCalendarManager(org.olat.commons.calendar.manager.ImportToCalendarManager) CalendarManager(org.olat.commons.calendar.CalendarManager) CalendarNotificationManager(org.olat.commons.calendar.CalendarNotificationManager) AssertException(org.olat.core.logging.AssertException) BusinessGroup(org.olat.group.BusinessGroup) OLATResourceable(org.olat.core.id.OLATResourceable) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Example 2 with CalendarManager

use of org.olat.commons.calendar.CalendarManager in project OpenOLAT by OpenOLAT.

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 3 with CalendarManager

use of org.olat.commons.calendar.CalendarManager in project OpenOLAT by OpenOLAT.

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 4 with CalendarManager

use of org.olat.commons.calendar.CalendarManager in project OpenOLAT by OpenOLAT.

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)

Example 5 with CalendarManager

use of org.olat.commons.calendar.CalendarManager in project OpenOLAT by OpenOLAT.

the class CourseCalendarTest method setUp.

/**
 * SetUp is called before each test.
 */
@Before
public void setUp() throws Exception {
    super.setUp();
    try {
        // create course and persist as OLATResourceImpl
        auth1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-course-cal-one");
        CourseConfigVO config = new CourseConfigVO();
        config.setCalendar(Boolean.TRUE);
        course1 = CoursesWebService.createEmptyCourse(auth1, "course calendar", "course with calendar for REST API testing", config);
        dbInstance.commit();
        ICourse course = CourseFactory.loadCourse(course1.getResourceableId());
        Assert.assertTrue(course.getCourseConfig().isCalendarEnabled());
        CalendarManager calManager = CoreSpringFactory.getImpl(CalendarManager.class);
        KalendarRenderWrapper calendarWrapper = calManager.getCourseCalendar(course);
        Calendar cal = Calendar.getInstance();
        for (int i = 0; i < 2; i++) {
            Date begin = cal.getTime();
            cal.add(Calendar.HOUR_OF_DAY, 1);
            Date end = cal.getTime();
            String eventId = UUID.randomUUID().toString();
            KalendarEvent event = new KalendarEvent(eventId, null, "Unit test " + i, begin, end);
            calManager.addEventTo(calendarWrapper.getKalendar(), event);
            cal.add(Calendar.DATE, 1);
        }
    } catch (Exception e) {
        log.error("Exception in setUp(): " + e);
    }
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) CalendarManager(org.olat.commons.calendar.CalendarManager) Calendar(java.util.Calendar) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) ICourse(org.olat.course.ICourse) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Before(org.junit.Before)

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