Search in sources :

Example 86 with Kalendar

use of org.olat.commons.calendar.model.Kalendar in project OpenOLAT by OpenOLAT.

the class CalendarEntryDetailsController method event.

@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == deleteCtr) {
        if (event instanceof CalendarGUIDeleteEvent) {
            doDelete((CalendarGUIDeleteEvent) event);
            cmc.deactivate();
            cleanUp();
            fireEvent(ureq, Event.DONE_EVENT);
        } else {
            cmc.deactivate();
            cleanUp();
        }
    } else if (source == activeLinkProvider) {
        if (kalendarEvent.getCalendar() != null) {
            fireEvent(ureq, Event.DONE_EVENT);
        }
    } else if (source == eventForm) {
        if (event == Event.DONE_EVENT) {
            doSave(ureq);
        } else if ("delete".equals(event.getCommand())) {
            doConfirmDelete(ureq);
        } else if (event == Event.CANCELLED_EVENT) {
            eventForm.setEntry(kalendarEvent);
            // user canceled, finish workflow
            fireEvent(ureq, Event.DONE_EVENT);
        }
    } else if (source == updateCtr) {
        if (event instanceof CalendarGUIUpdateEvent) {
            doUpdate((CalendarGUIUpdateEvent) event);
            cmc.deactivate();
            cleanUp();
            fireEvent(ureq, Event.DONE_EVENT);
        } else {
            cmc.deactivate();
            cleanUp();
        }
    } else if (source == customMediaChooserCtr) {
        boolean doneSuccessfully = true;
        if (event instanceof URLChoosenEvent) {
            URLChoosenEvent urlEvent = (URLChoosenEvent) event;
            String url = urlEvent.getURL();
            List<KalendarEventLink> links = kalendarEvent.getKalendarEventLinks();
            String provider = customMediaChooserCtr.getClass().getSimpleName();
            String id = url;
            String displayName = StringHelper.containsNonWhitespace(urlEvent.getDisplayName()) ? urlEvent.getDisplayName() : url;
            String uri = url.contains("://") ? url : (Settings.getServerContextPathURI() + url);
            String iconCssClass = urlEvent.getIconCssClass();
            if (!StringHelper.containsNonWhitespace(iconCssClass)) {
                iconCssClass = CSSHelper.createFiletypeIconCssClassFor(url);
            }
            links.add(new KalendarEventLink(provider, id, displayName, uri, iconCssClass));
            Kalendar cal = kalendarEvent.getCalendar();
            doneSuccessfully = calendarManager.updateEventFrom(cal, kalendarEvent);
        }
        if (doneSuccessfully) {
            fireEvent(ureq, event);
        } else {
            showError("cal.error.save");
            fireEvent(ureq, Event.FAILED_EVENT);
        }
    } else if (source == externalLinksController || source == mediaLinksController) {
        // save externals links
        Kalendar cal = kalendarEvent.getCalendar();
        if (kalendarEvent.getCalendar() != null) {
            boolean doneSuccessfully = calendarManager.updateEventFrom(cal, kalendarEvent);
            if (doneSuccessfully) {
                fireEvent(ureq, Event.DONE_EVENT);
            } else {
                showError("cal.error.save");
                fireEvent(ureq, Event.FAILED_EVENT);
            }
        }
    } else if (cmc == source) {
        cleanUp();
    }
}
Also used : CalendarGUIDeleteEvent(org.olat.commons.calendar.ui.events.CalendarGUIDeleteEvent) Kalendar(org.olat.commons.calendar.model.Kalendar) CalendarGUIUpdateEvent(org.olat.commons.calendar.ui.events.CalendarGUIUpdateEvent) URLChoosenEvent(org.olat.core.commons.controllers.linkchooser.URLChoosenEvent) KalendarEventLink(org.olat.commons.calendar.model.KalendarEventLink)

Example 87 with Kalendar

use of org.olat.commons.calendar.model.Kalendar in project OpenOLAT by OpenOLAT.

the class DENManager method getDENEvents.

/**
 * Returns all generated Events for this course and node
 * @param courseId
 * @param sourseNodeId
 * @return List of all KalendarEvent in this date enrollment
 */
protected List<KalendarEvent> getDENEvents(Long courseId, String sourceNodeId) {
    List<KalendarEvent> denEvents = new ArrayList<KalendarEvent>();
    ICourse course = CourseFactory.loadCourse(courseId);
    CalendarManager calManager = CoreSpringFactory.getImpl(CalendarManager.class);
    Kalendar cal = calManager.getCourseCalendar(course).getKalendar();
    Collection<KalendarEvent> colEvents = cal.getEvents();
    for (KalendarEvent event : colEvents) {
        String eventSourceNodeId = event.getSourceNodeId();
        if (eventSourceNodeId != null) {
            if (eventSourceNodeId.equals(sourceNodeId))
                denEvents.add(event);
        }
    }
    return denEvents;
}
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)

Example 88 with Kalendar

use of org.olat.commons.calendar.model.Kalendar in project OpenOLAT by OpenOLAT.

the class DENManager method persistDENSettings.

/**
 * Persists settings of the date enrollment
 * @param lstEvents
 * @param course
 * @param denNode
 */
public void persistDENSettings(List<KalendarEvent> lstEvents, OLATResourceable ores, DENCourseNode denNode) {
    ICourse course = CourseFactory.loadCourse(ores);
    CalendarManager calManager = CoreSpringFactory.getImpl(CalendarManager.class);
    Kalendar cal = calManager.getCourseCalendar(course).getKalendar();
    String sourceNode = denNode.getIdent();
    // remove deleted events
    Collection<KalendarEvent> allEvents = new ArrayList<KalendarEvent>(cal.getEvents());
    for (KalendarEvent event : allEvents) {
        if (event.getSourceNodeId() != null) {
            if (event.getSourceNodeId().equals(sourceNode) && !lstEvents.contains(event)) {
                removeDateInUserCalendar(event);
                calManager.removeEventFrom(cal, event);
            }
        }
    }
    for (KalendarEvent newEvent : lstEvents) {
        createKalendarEventLinks(course, denNode, newEvent);
        KalendarEvent oldEvent = cal.getEvent(newEvent.getID(), newEvent.getRecurrenceID());
        // new event?
        if (oldEvent != null) {
            // event is already in the calendar so first remove it
            calManager.removeEventFrom(cal, oldEvent);
        }
        // now add the event to the course calendar
        calManager.addEventTo(cal, newEvent);
        // update event in user calendars
        addDateInUserCalendar(newEvent);
    }
}
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)

Example 89 with Kalendar

use of org.olat.commons.calendar.model.Kalendar in project OpenOLAT by OpenOLAT.

the class DENManager method doEnroll.

/**
 * Enrolls an user into a specific calendar event
 * @param identity
 * @param event
 * @param course
 * @param courseNode
 * @param allowOverfill
 * @return status
 */
public DENStatus doEnroll(final Identity identity, final KalendarEvent event, final OLATResourceable ores, final DENCourseNode courseNode, final boolean allowOverfill) {
    final DENStatus status = new DENStatus();
    ICourse course = CourseFactory.loadCourse(ores);
    CalendarManager calManager = CoreSpringFactory.getImpl(CalendarManager.class);
    final Kalendar cal = calManager.getCourseCalendar(course).getKalendar();
    OLATResourceable calRes = calManager.getOresHelperFor(cal);
    // reload calendar events
    final List<KalendarEvent> denEvents = getDENEvents(ores.getResourceableId(), courseNode.getIdent());
    CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calRes, new SyncerExecutor() {

        public void execute() {
            boolean error = false;
            // try to find choosen calendar event in the reloaded event list
            KalendarEvent reloadEvent = event;
            for (Iterator<KalendarEvent> iterator = denEvents.iterator(); iterator.hasNext(); ) {
                KalendarEvent kalendarEvent = iterator.next();
                if (event.getID().equals(kalendarEvent.getID())) {
                    reloadEvent = kalendarEvent;
                    break;
                } else if (!iterator.hasNext()) {
                    // cannot find reloaded calendar event
                    status.setEnrolled(false);
                    status.setErrorMessage(DENStatus.ERROR_GENERAL);
                    error = true;
                }
            }
            Collection<KalendarEvent> collEvents = cal.getEvents();
            // check if date is already full
            if (!error && !allowOverfill && isDateFull(reloadEvent)) {
                status.setEnrolled(false);
                status.setErrorMessage(DENStatus.ERROR_FULL);
                error = true;
            }
            // check if identity is already enrolled
            if (!error && isAlreadyEnrolled(identity, collEvents, courseNode)) {
                status.setEnrolled(false);
                status.setErrorMessage(DENStatus.ERROR_ALREADY_ENROLLED);
                error = true;
            }
            // enroll in event
            if (!error) {
                if (reloadEvent.getParticipants() != null && reloadEvent.getParticipants().length > 0) {
                    int currLength = reloadEvent.getParticipants().length;
                    // one to add
                    String[] partsNew = new String[currLength + 1];
                    String[] partsOld = reloadEvent.getParticipants();
                    for (int i = 0; i < partsOld.length; i++) {
                        partsNew[i] = partsOld[i];
                    }
                    partsNew[partsNew.length - 1] = identity.getName();
                    reloadEvent.setParticipants(partsNew);
                } else {
                    String[] partsNew = new String[] { identity.getName() };
                    reloadEvent.setParticipants(partsNew);
                }
                // save calendar event
                boolean successfullyDone = calManager.updateEventAlreadyInSync(cal, reloadEvent);
                if (!successfullyDone) {
                    status.setEnrolled(false);
                    status.setErrorMessage(DENStatus.ERROR_PERSISTING);
                }
                status.setEnrolled(true);
            }
        }
    });
    // success
    return status;
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) Kalendar(org.olat.commons.calendar.model.Kalendar) OLATResourceable(org.olat.core.id.OLATResourceable) Iterator(java.util.Iterator) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Collection(java.util.Collection) ICourse(org.olat.course.ICourse) SyncerExecutor(org.olat.core.util.coordinate.SyncerExecutor)

Example 90 with Kalendar

use of org.olat.commons.calendar.model.Kalendar in project OpenOLAT by OpenOLAT.

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)

Aggregations

Kalendar (org.olat.commons.calendar.model.Kalendar)126 KalendarEvent (org.olat.commons.calendar.model.KalendarEvent)68 Identity (org.olat.core.id.Identity)40 Date (java.util.Date)38 Test (org.junit.Test)26 CalendarManager (org.olat.commons.calendar.CalendarManager)24 KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)22 ArrayList (java.util.ArrayList)20 CalendarImportTest (org.olat.commons.calendar.CalendarImportTest)20 OLATResourceable (org.olat.core.id.OLATResourceable)20 CalendarGUIModifiedEvent (org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent)18 Calendar (java.util.Calendar)14 CalendarUserConfiguration (org.olat.commons.calendar.model.CalendarUserConfiguration)12 URISyntaxException (java.net.URISyntaxException)10 ParseException (java.text.ParseException)10 ExDate (net.fortuna.ical4j.model.property.ExDate)10 IOException (java.io.IOException)8 InputStream (java.io.InputStream)8 ICourse (org.olat.course.ICourse)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8