Search in sources :

Example 21 with CalendarManager

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

the class DENManager method addDateInUserCalendar.

/**
 * Add this event in the calendar of an enrolled user
 * @param newEvent
 */
private void addDateInUserCalendar(KalendarEvent newEvent) {
    String[] participants = newEvent.getParticipants();
    // no users to update, cancel
    if (participants == null)
        return;
    BaseSecurity manager = BaseSecurityManager.getInstance();
    CalendarManager calManager = CoreSpringFactory.getImpl(CalendarManager.class);
    for (String participant : participants) {
        Identity identity = manager.findIdentityByName(participant);
        if (identity != null) {
            Kalendar userCal = calManager.getPersonalCalendar(identity).getKalendar();
            List<KalendarEvent> userEvents = new ArrayList<>();
            userEvents.addAll(userCal.getEvents());
            String eventId = CodeHelper.getGlobalForeverUniqueID();
            KalendarEvent userNewEvent = new KalendarEvent(eventId, null, newEvent.getSubject(), newEvent.getBegin(), newEvent.getEnd());
            userNewEvent.setLocation(newEvent.getLocation());
            userNewEvent.setSourceNodeId(newEvent.getSourceNodeId());
            userNewEvent.setClassification(KalendarEvent.CLASS_PRIVATE);
            List<KalendarEventLink> kalendarEventLinks = userNewEvent.getKalendarEventLinks();
            kalendarEventLinks.clear();
            kalendarEventLinks.addAll(newEvent.getKalendarEventLinks());
            calManager.addEventTo(userCal, userNewEvent);
        }
    }
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) Kalendar(org.olat.commons.calendar.model.Kalendar) ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) KalendarEventLink(org.olat.commons.calendar.model.KalendarEventLink) Identity(org.olat.core.id.Identity) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 22 with CalendarManager

use of org.olat.commons.calendar.CalendarManager 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);
    }
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) CalendarKey(org.olat.commons.calendar.model.CalendarKey) BusinessGroup(org.olat.group.BusinessGroup) CollaborationTools(org.olat.collaboration.CollaborationTools) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) CollaborationToolsFactory(org.olat.collaboration.CollaborationToolsFactory)

Example 23 with CalendarManager

use of org.olat.commons.calendar.CalendarManager in project openolat by klemens.

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)

Example 24 with CalendarManager

use of org.olat.commons.calendar.CalendarManager in project openolat by klemens.

the class DENManager method removeDateInUserCalendar.

/**
 * Removes this event in all calendars of enrolled users
 * @param oldEvent
 */
private void removeDateInUserCalendar(KalendarEvent oldEvent) {
    String[] participants = oldEvent.getParticipants();
    // no users to update, cancel
    if (participants == null)
        return;
    BaseSecurity manager = BaseSecurityManager.getInstance();
    CalendarManager calManager = CoreSpringFactory.getImpl(CalendarManager.class);
    for (String participant : participants) {
        Identity identity = manager.findIdentityByName(participant);
        if (identity != null) {
            Kalendar userCal = calManager.getPersonalCalendar(identity).getKalendar();
            List<KalendarEvent> userEvents = new ArrayList<>();
            userEvents.addAll(userCal.getEvents());
            for (KalendarEvent userEvent : userEvents) {
                String sourceNodeId = userEvent.getSourceNodeId();
                if (sourceNodeId != null && sourceNodeId.equals(oldEvent.getSourceNodeId())) {
                    calManager.removeEventFrom(userCal, userEvent);
                }
            }
        }
    }
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) Kalendar(org.olat.commons.calendar.model.Kalendar) ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Identity(org.olat.core.id.Identity) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 25 with CalendarManager

use of org.olat.commons.calendar.CalendarManager in project openolat by klemens.

the class DENManager method cancelEnroll.

/**
 * Deletes the already enrolled user from the date
 * @param identity
 * @param event
 * @param course
 * @param userCourseEnv
 * @return status
 */
public DENStatus cancelEnroll(Identity identity, KalendarEvent event, OLATResourceable ores) {
    DENStatus status = new DENStatus();
    ICourse course = CourseFactory.loadCourse(ores);
    CalendarManager calManager = CoreSpringFactory.getImpl(CalendarManager.class);
    Kalendar cal = calManager.getCourseCalendar(course).getKalendar();
    // check if identity is enrolled
    if (!isEnrolledInDate(identity, event)) {
        status.setCancelled(false);
        status.setErrorMessage(DENStatus.ERROR_NOT_ENROLLED);
    }
    // cancel enroll in calendar entry
    if (event.getParticipants() != null) {
        int currLength = event.getParticipants().length;
        if (currLength > 0) {
            // more than one are enrolled
            // one to delete
            List<String> partsNew = new ArrayList<>(currLength);
            String[] partsOld = event.getParticipants();
            String identityName = identity.getName();
            for (String partOld : partsOld) {
                if (!partOld.equals(identityName)) {
                    partsNew.add(partOld);
                }
            }
            event.setParticipants(partsNew.toArray(new String[partsNew.size()]));
        }
        // save calendar event
        boolean successfullyDone = calManager.updateEventFrom(cal, event);
        if (!successfullyDone) {
            status.setCancelled(false);
            status.setErrorMessage(DENStatus.ERROR_PERSISTING);
            return status;
        }
    } else {
        // no one to cancel
        status.setCancelled(false);
        status.setErrorMessage(DENStatus.ERROR_GENERAL);
        return status;
    }
    status.setCancelled(true);
    // delete date from the users calendar
    Kalendar userCal = calManager.getPersonalCalendar(identity).getKalendar();
    Collection<KalendarEvent> userEvents = userCal.getEvents();
    String sourceNodeId = event.getSourceNodeId();
    for (KalendarEvent userEvent : userEvents) {
        String eventSourceNodeId = userEvent.getSourceNodeId();
        if (eventSourceNodeId != null && eventSourceNodeId.equals(sourceNodeId)) {
            calManager.removeEventFrom(userCal, userEvent);
            break;
        }
    }
    // success
    return status;
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) Kalendar(org.olat.commons.calendar.model.Kalendar) ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) ICourse(org.olat.course.ICourse)

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