Search in sources :

Example 36 with KalendarEvent

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

the class DENListTableDataModel method getValueAt.

@Override
public Object getValueAt(int row, int col) {
    KalendarEvent event = getObject(row);
    switch(col) {
        case 0:
            return event.getSubject();
        case 1:
            return event.getBegin();
        case // duration
        2:
            Date begin = event.getBegin();
            Date end = event.getEnd();
            long milliSeconds = denManager.getDuration(begin, end);
            return denManager.formatDuration(milliSeconds, translator);
        case 3:
            return event.getLocation();
        case 4:
            return event.getComment();
        case 5:
            // participants
            StringBuilder names = new StringBuilder();
            if (event.getParticipants() != null && event.getParticipants().length > 0) {
                for (String participant : event.getParticipants()) {
                    if (names.length() > 0)
                        names.append("<br/>");
                    String fullName = userManager.getUserDisplayName(participant);
                    if (StringHelper.containsNonWhitespace(fullName)) {
                        names.append(fullName);
                    }
                }
            }
            return names.toString();
        case 6:
            // usernames
            StringBuilder usernames = new StringBuilder();
            if (event.getParticipants() != null && event.getParticipants().length > 0) {
                for (String participant : event.getParticipants()) {
                    if (usernames.length() > 0)
                        usernames.append("<br/>");
                    usernames.append(participant);
                }
            }
            return usernames.toString();
        case 7:
            return Boolean.TRUE;
        default:
            return "error";
    }
}
Also used : KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Date(java.util.Date)

Example 37 with KalendarEvent

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

the class DENManageDatesController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    ICourse course = CourseFactory.loadCourse(ores);
    if (manageDatesForm == source) {
        // generate the dates and put them into the table
        editTableDataList = denManager.generateDates(manageDatesForm.getSubject(), manageDatesForm.getComment(), manageDatesForm.getLocation(), manageDatesForm.getDuration(), manageDatesForm.getPause(), manageDatesForm.getBeginDate(), manageDatesForm.getRetakes(), manageDatesForm.getNumParts(), editTableDataList, denCourseNode.getIdent());
        denManager.persistDENSettings(editTableDataList, course, denCourseNode);
        editDENTable.setTableDataModel(editTableData);
    } else if (source == editDENTable) {
        TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
        selectedDates = tmse.getSelection();
        // clicked button to edit one date or more dates
        if (tmse.getAction().equals(DENEditTableDataModel.CHANGE_ACTION) && selectedDates.cardinality() > 0) {
            if (selectedDates.cardinality() == 1) {
                // if only one date is choosen, we can prefill some entries
                removeAsListenerAndDispose(editSingleDateForm);
                editSingleDateForm = new DENDatesForm(ureq, getWindowControl(), getTranslator(), DENDatesForm.EDIT_SINGLE_DATE_LAYOUT);
                listenTo(editSingleDateForm);
                // in this case only one date is possible
                KalendarEvent calEvent = editTableData.getObjects(selectedDates).get(0);
                editSingleDateForm.setSubject(calEvent.getSubject());
                editSingleDateForm.setComment(calEvent.getComment());
                editSingleDateForm.setLocation(calEvent.getLocation());
                editSingleDateForm.setNumParts(calEvent.getNumParticipants());
                editSingleDateForm.setFormDate(calEvent.getBegin());
                editSingleDateForm.setDuration(denManager.getDurationAsString(calEvent));
                removeAsListenerAndDispose(editDateModalCntrll);
                editDateModalCntrll = new CloseableModalController(getWindowControl(), "close", editSingleDateForm.getInitialComponent(), true, translate("dates.edit"));
                listenTo(editDateModalCntrll);
            } else if (selectedDates.cardinality() > 1) {
                removeAsListenerAndDispose(editMultipleDatesForm);
                editMultipleDatesForm = new DENDatesForm(ureq, getWindowControl(), getTranslator(), DENDatesForm.EDIT_MULTIPLE_DATES_LAYOUT);
                listenTo(editMultipleDatesForm);
                removeAsListenerAndDispose(editDateModalCntrll);
                editDateModalCntrll = new CloseableModalController(getWindowControl(), "close", editMultipleDatesForm.getInitialComponent(), true, translate("dates.edit"));
                listenTo(editDateModalCntrll);
            }
            // persist dates
            denManager.persistDENSettings(editTableData.getObjects(), course, denCourseNode);
            editDateModalCntrll.activate();
        } else if (tmse.getAction().equals(DENEditTableDataModel.DELETE_ACTION)) {
            // delete selected dates
            editTableData.removeEntries(tmse.getSelection());
            editDENTable.setTableDataModel(editTableData);
            // persist dates
            denManager.persistDENSettings(editTableData.getObjects(), course, denCourseNode);
        }
    } else if (source == editSingleDateForm) {
        // save changes for one date
        editTableData.setObjects(denManager.updateDateInList(editSingleDateForm.getSubject(), editSingleDateForm.getComment(), editSingleDateForm.getLocation(), editSingleDateForm.getDuration(), editSingleDateForm.getBeginDate(), editSingleDateForm.getNumParts(), editTableData.getObjects(), // only one bit is set
        selectedDates.nextSetBit(0)));
        editDENTable.setTableDataModel(editTableData);
        denManager.persistDENSettings(editTableData.getObjects(), course, denCourseNode);
        editDateModalCntrll.deactivate();
    } else if (source == editMultipleDatesForm) {
        // save changes for multiple dates
        editTableData.setObjects(denManager.updateMultipleDatesInList(editMultipleDatesForm.getSubject(), editMultipleDatesForm.getComment(), editMultipleDatesForm.getLocation(), editMultipleDatesForm.getMovementGap(), editMultipleDatesForm.getNumParts(), editTableData.getObjects(), selectedDates));
        editDENTable.setTableDataModel(editTableData);
        denManager.persistDENSettings(editTableData.getObjects(), course, denCourseNode);
        editDateModalCntrll.deactivate();
    }
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) ICourse(org.olat.course.ICourse)

Example 38 with KalendarEvent

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

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 39 with KalendarEvent

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

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 40 with KalendarEvent

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

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)

Aggregations

KalendarEvent (org.olat.commons.calendar.model.KalendarEvent)172 Date (java.util.Date)80 Kalendar (org.olat.commons.calendar.model.Kalendar)68 Test (org.junit.Test)48 KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)46 Identity (org.olat.core.id.Identity)46 ArrayList (java.util.ArrayList)42 Calendar (java.util.Calendar)40 CalendarImportTest (org.olat.commons.calendar.CalendarImportTest)34 CalendarManager (org.olat.commons.calendar.CalendarManager)32 OLATResourceable (org.olat.core.id.OLATResourceable)20 CalendarGUIModifiedEvent (org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent)18 File (java.io.File)16 ExDate (net.fortuna.ical4j.model.property.ExDate)16 ICourse (org.olat.course.ICourse)16 URI (java.net.URI)14 HttpResponse (org.apache.http.HttpResponse)14 URL (java.net.URL)12 KalendarRecurEvent (org.olat.commons.calendar.model.KalendarRecurEvent)12 EventVO (org.olat.commons.calendar.restapi.EventVO)12