Search in sources :

Example 46 with Kalendar

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

the class LectureServiceImpl method fullSyncCourseCalendar.

private void fullSyncCourseCalendar(RepositoryEntry entry) {
    List<LectureBlock> blocks = getLectureBlocks(entry);
    Map<String, LectureBlock> externalIds = blocks.stream().collect(Collectors.toMap(b -> generateExternalId(b, entry), b -> b));
    Kalendar cal = calendarMgr.getCalendar(CalendarManager.TYPE_COURSE, entry.getOlatResource().getResourceableId().toString());
    String prefix = generateExternalIdPrefix(entry);
    List<KalendarEvent> events = new ArrayList<>(cal.getEvents());
    for (KalendarEvent event : events) {
        String externalId = event.getExternalId();
        if (StringHelper.containsNonWhitespace(externalId) && externalId.startsWith(prefix)) {
            if (externalIds.containsKey(externalId)) {
                if (updateEvent(externalIds.get(externalId), event)) {
                    calendarMgr.updateEventFrom(cal, event);
                }
                externalIds.remove(externalId);
            } else {
                calendarMgr.removeEventFrom(cal, event);
            }
        }
    }
    // add new calendar events
    List<KalendarEvent> eventsToAdd = new ArrayList<>();
    for (Map.Entry<String, LectureBlock> entryToAdd : externalIds.entrySet()) {
        eventsToAdd.add(createEvent(entryToAdd.getValue(), entry));
    }
    if (eventsToAdd.size() > 0) {
        calendarMgr.addEventTo(cal, eventsToAdd);
    }
}
Also used : Util(org.olat.core.util.Util) LectureParticipantSummary(org.olat.modules.lecture.LectureParticipantSummary) LectureBlockRollCallSearchParameters(org.olat.modules.lecture.LectureBlockRollCallSearchParameters) Date(java.util.Date) I18nManager(org.olat.core.util.i18n.I18nManager) RepositoryEntryRef(org.olat.repository.RepositoryEntryRef) LectureBlockAuditLog(org.olat.modules.lecture.LectureBlockAuditLog) Autowired(org.springframework.beans.factory.annotation.Autowired) IdentityRef(org.olat.basesecurity.IdentityRef) MailContextImpl(org.olat.core.util.mail.MailContextImpl) RepositoryEntryLectureConfiguration(org.olat.modules.lecture.RepositoryEntryLectureConfiguration) Locale(java.util.Locale) GroupDAO(org.olat.basesecurity.manager.GroupDAO) Map(java.util.Map) Group(org.olat.basesecurity.Group) LectureBlockToGroup(org.olat.modules.lecture.LectureBlockToGroup) LectureBlockStatistics(org.olat.modules.lecture.model.LectureBlockStatistics) MailTemplate(org.olat.core.util.mail.MailTemplate) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) OLog(org.olat.core.logging.OLog) Translator(org.olat.core.gui.translator.Translator) LectureBlock(org.olat.modules.lecture.LectureBlock) LectureBlockWithTeachers(org.olat.modules.lecture.model.LectureBlockWithTeachers) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) Set(java.util.Set) LectureBlockImpl(org.olat.modules.lecture.model.LectureBlockImpl) UUID(java.util.UUID) AggregatedLectureBlocksStatistics(org.olat.modules.lecture.model.AggregatedLectureBlocksStatistics) Collectors(java.util.stream.Collectors) VelocityContext(org.apache.velocity.VelocityContext) MailManager(org.olat.core.util.mail.MailManager) LectureService(org.olat.modules.lecture.LectureService) List(java.util.List) Identity(org.olat.core.id.Identity) ParticipantAndLectureSummary(org.olat.modules.lecture.model.ParticipantAndLectureSummary) IdentityImpl(org.olat.basesecurity.IdentityImpl) MailContext(org.olat.core.util.mail.MailContext) LectureBlockIdentityStatistics(org.olat.modules.lecture.model.LectureBlockIdentityStatistics) Settings(org.olat.core.helpers.Settings) MailBundle(org.olat.core.util.mail.MailBundle) LectureBlockAndRollCall(org.olat.modules.lecture.model.LectureBlockAndRollCall) Action(org.olat.modules.lecture.LectureBlockAuditLog.Action) HashMap(java.util.HashMap) CalendarManagedFlag(org.olat.commons.calendar.CalendarManagedFlag) Reason(org.olat.modules.lecture.Reason) RepositoryEntry(org.olat.repository.RepositoryEntry) LecturesBlockSearchParameters(org.olat.modules.lecture.model.LecturesBlockSearchParameters) ArrayList(java.util.ArrayList) Kalendar(org.olat.commons.calendar.model.Kalendar) HashSet(java.util.HashSet) Calendar(java.util.Calendar) Service(org.springframework.stereotype.Service) StringHelper(org.olat.core.util.StringHelper) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall) RepositoryEntryDAO(org.olat.repository.manager.RepositoryEntryDAO) LectureBlockToTeacher(org.olat.modules.lecture.model.LectureBlockToTeacher) CalendarManager(org.olat.commons.calendar.CalendarManager) LectureBlockRef(org.olat.modules.lecture.LectureBlockRef) LectureBlockStatus(org.olat.modules.lecture.LectureBlockStatus) LectureStatisticsSearchParameters(org.olat.modules.lecture.model.LectureStatisticsSearchParameters) Formatter(org.olat.core.util.Formatter) MailerResult(org.olat.core.util.mail.MailerResult) LectureAdminController(org.olat.modules.lecture.ui.LectureAdminController) LectureModule(org.olat.modules.lecture.LectureModule) Iterator(java.util.Iterator) LectureBlockRollCallRef(org.olat.modules.lecture.LectureBlockRollCallRef) File(java.io.File) UserManager(org.olat.user.UserManager) DB(org.olat.core.commons.persistence.DB) BusinessGroup(org.olat.group.BusinessGroup) DeletableGroupData(org.olat.group.DeletableGroupData) LectureRollCallStatus(org.olat.modules.lecture.LectureRollCallStatus) Tracing(org.olat.core.logging.Tracing) ConfigurationHelper(org.olat.modules.lecture.ui.ConfigurationHelper) UserDataDeletable(org.olat.user.UserDataDeletable) LectureBlock(org.olat.modules.lecture.LectureBlock) Kalendar(org.olat.commons.calendar.model.Kalendar) ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Map(java.util.Map) HashMap(java.util.HashMap)

Example 47 with Kalendar

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

the class LectureServiceImpl method syncCourseCalendar.

private void syncCourseCalendar(LectureBlock lectureBlock, RepositoryEntry entry) {
    Kalendar cal = calendarMgr.getCalendar(CalendarManager.TYPE_COURSE, entry.getOlatResource().getResourceableId().toString());
    syncEvent(lectureBlock, entry, cal);
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar)

Example 48 with Kalendar

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

the class WeeklyCalendarController method doResize.

private void doResize(UserRequest ureq, KalendarEvent calEvent, Long minuteDelta, Boolean allDay) {
    if (calEvent instanceof KalendarRecurEvent && !StringHelper.containsNonWhitespace(calEvent.getRecurrenceID())) {
        updateCtr = new ConfirmUpdateController(ureq, getWindowControl(), (KalendarRecurEvent) calEvent, 0L, minuteDelta, allDay, false);
        listenTo(updateCtr);
        String title = translate("cal.edit.update");
        cmc = new CloseableModalController(getWindowControl(), translate("close"), updateCtr.getInitialComponent(), true, title);
        listenTo(cmc);
        cmc.activate();
    } else {
        Kalendar cal = calEvent.getCalendar();
        calEvent.setEnd(doMove(calEvent.getEnd(), 0L, minuteDelta));
        if (allDay != null && calEvent.isAllDayEvent() != allDay.booleanValue()) {
            calEvent.setAllDayEvent(allDay.booleanValue());
        }
        calendarManager.updateEventFrom(cal, calEvent);
        calendarEl.getComponent().setDirty(true);
    }
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) KalendarRecurEvent(org.olat.commons.calendar.model.KalendarRecurEvent) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)

Example 49 with Kalendar

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

the class WeeklyCalendarController method doMove.

private void doMove(UserRequest ureq, KalendarEvent calEvent, Long dayDelta, Long minuteDelta, Boolean allDay) {
    if (calEvent instanceof KalendarRecurEvent && !StringHelper.containsNonWhitespace(calEvent.getRecurrenceID())) {
        updateCtr = new ConfirmUpdateController(ureq, getWindowControl(), (KalendarRecurEvent) calEvent, dayDelta, minuteDelta, allDay, true);
        listenTo(updateCtr);
        String title = translate("cal.edit.update");
        cmc = new CloseableModalController(getWindowControl(), translate("close"), updateCtr.getInitialComponent(), true, title);
        listenTo(cmc);
        cmc.activate();
    } else {
        Kalendar cal = calEvent.getCalendar();
        calEvent.setBegin(doMove(calEvent.getBegin(), dayDelta, minuteDelta));
        calEvent.setEnd(doMove(calEvent.getEnd(), dayDelta, minuteDelta));
        if (allDay != null && calEvent.isAllDayEvent() != allDay.booleanValue()) {
            calEvent.setAllDayEvent(allDay.booleanValue());
        }
        calendarManager.updateEventFrom(cal, calEvent);
        calendarEl.getComponent().setDirty(true);
    }
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) KalendarRecurEvent(org.olat.commons.calendar.model.KalendarRecurEvent) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)

Example 50 with Kalendar

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

the class WeeklyCalendarController method event.

@Override
public void event(UserRequest ureq, Controller source, Event event) {
    Kalendar affectedCal = null;
    if (dirty) {
        dirty = false;
        fireEvent(ureq, new CalendarGUIModifiedEvent());
    }
    if (source == editController) {
        affectedCal = editController.getKalendarEvent().getCalendar();
        cmc.deactivate();
        calendarEl.getComponent().setDirty(true);
        // do logging if affectedCal not null
        if (affectedCal != null) {
            ThreadLocalUserActivityLogger.log(getCalLoggingAction(), getClass(), LoggingResourceable.wrap(ureq.getIdentity()), LoggingResourceable.wrap(affectedCal));
        }
        cleanUp();
    } else if (source == eventDetailsCtr) {
        if (event instanceof CalendarGUIEditEvent) {
            eventCalloutCtr.deactivate();
            cleanUp();
            CalendarGUIEditEvent editEvent = (CalendarGUIEditEvent) event;
            pushEditEventController(ureq, editEvent.getKalendarEvent(), editEvent.getKalendarRenderWrapper());
        } else if (event == Event.DONE_EVENT) {
            eventCalloutCtr.deactivate();
            cleanUp();
        }
    } else if (source == updateCtr) {
        if (event instanceof CalendarGUIUpdateEvent) {
            doUpdate((CalendarGUIUpdateEvent) event, updateCtr.getKalendarEvent(), updateCtr.getDayDelta(), updateCtr.getMinuteDelta(), updateCtr.getAllDay(), updateCtr.getChangeBegin());
        }
        cmc.deactivate();
        cleanUp();
    } else if (source == printCtrl) {
        if (event instanceof CalendarGUIPrintEvent) {
            CalendarGUIPrintEvent printEvent = (CalendarGUIPrintEvent) event;
            if (printEvent.getFrom() != null && printEvent.getTo() != null) {
                doPrint(printEvent.getFrom(), printEvent.getTo());
            }
        }
        eventCalloutCtr.deactivate();
        cleanUp();
    } else if (source == cmc) {
        calendarEl.getComponent().setDirty(true);
        cleanUp();
    } else if (source == dbcSequence) {
        if (event != Event.CANCELLED_EVENT) {
            int pos = DialogBoxUIFactory.getButtonPos(event);
            CalendarGUIEditEvent guiEvent = (CalendarGUIEditEvent) dbcSequence.getUserObject();
            KalendarRenderWrapper kalendarWrapper = guiEvent.getKalendarRenderWrapper();
            KalendarEvent kalendarEvent = guiEvent.getKalendarEvent();
            if (pos == 0) {
                // edit the sequence
                // load the parent event of this sequence
                KalendarEvent parentEvent = kalendarWrapper.getKalendar().getEvent(kalendarEvent.getID(), kalendarEvent.getRecurrenceID());
                pushEditEventController(ureq, parentEvent, kalendarWrapper);
            } else if (pos == 1) {
                // delete a single event of the sequence
                deleteSingleYesNoController = activateYesNoDialog(ureq, null, translate("cal.delete.dialogtext"), deleteSingleYesNoController);
                deleteSingleYesNoController.setUserObject(kalendarEvent);
            } else if (pos == 2) {
                // delete the whole sequence
                deleteSequenceYesNoController = activateYesNoDialog(ureq, null, translate("cal.delete.dialogtext.sequence"), deleteSequenceYesNoController);
                deleteSequenceYesNoController.setUserObject(kalendarEvent);
            }
        }
        dbcSequence.dispose();
    } else if (source == deleteSingleYesNoController) {
        if (DialogBoxUIFactory.isYesEvent(event)) {
            KalendarEvent kalendarEvent = (KalendarEvent) deleteSingleYesNoController.getUserObject();
            affectedCal = kalendarEvent.getCalendar();
            KalendarEvent kEvent = affectedCal.getEvent(kalendarEvent.getID(), kalendarEvent.getRecurrenceID());
            kEvent.addRecurrenceExc(kalendarEvent.getBegin());
            calendarManager.updateEventFrom(affectedCal, kEvent);
            deleteSingleYesNoController.dispose();
            calendarEl.getComponent().setDirty(true);
        }
    } else if (source == deleteSequenceYesNoController) {
        if (DialogBoxUIFactory.isYesEvent(event)) {
            KalendarEvent kalendarEvent = (KalendarEvent) deleteSequenceYesNoController.getUserObject();
            affectedCal = kalendarEvent.getCalendar();
            calendarManager.removeEventFrom(affectedCal, kalendarEvent);
            deleteSequenceYesNoController.dispose();
            calendarEl.getComponent().setDirty(true);
        }
    } else if (configurationCtrl == source) {
        if (event instanceof CalendarGUIImportEvent) {
            CalendarGUIImportEvent importEvent = (CalendarGUIImportEvent) event;
            calendarWrappers.add(importEvent.getCalendar());
            calendarEl.setCalendars(calendarWrappers);
        } else if (event instanceof CalendarGUIRemoveEvent) {
            CalendarGUIRemoveEvent removeEvent = (CalendarGUIRemoveEvent) event;
            calendarWrappers.remove(removeEvent.getCalendar());
            calendarEl.setCalendars(calendarWrappers);
        } else if (event instanceof CalendarGUISettingEvent) {
            calendarEl.setCalendars(calendarWrappers);
        }
    } else if (eventCalloutCtr == source) {
        cleanUp();
    } else if (eventDetailsCtr == source) {
    }
    if (calendarEl.getComponent().isDirty()) {
        if (subsContext != null) {
            // group or course calendar -> prepared subscription context is the right one
            NotificationsManager.getInstance().markPublisherNews(subsContext, ureq.getIdentity(), true);
        } else if (caller.equals(CALLER_HOME) && affectedCal != null) {
            // one can add/edit/remove dates of group and course calendars from the home calendar view -> choose right subscription context
            for (KalendarRenderWrapper calWrapper : calendarWrappers) {
                if (affectedCal == calWrapper.getKalendar()) {
                    SubscriptionContext tmpSubsContext = calendarNotificationsManager.getSubscriptionContext(calWrapper);
                    NotificationsManager.getInstance().markPublisherNews(tmpSubsContext, ureq.getIdentity(), true);
                }
            }
        }
    }
}
Also used : CalendarGUIEditEvent(org.olat.commons.calendar.ui.events.CalendarGUIEditEvent) Kalendar(org.olat.commons.calendar.model.Kalendar) CalendarGUIPrintEvent(org.olat.commons.calendar.ui.events.CalendarGUIPrintEvent) CalendarGUISettingEvent(org.olat.commons.calendar.ui.events.CalendarGUISettingEvent) CalendarGUIUpdateEvent(org.olat.commons.calendar.ui.events.CalendarGUIUpdateEvent) CalendarGUIImportEvent(org.olat.commons.calendar.ui.events.CalendarGUIImportEvent) CalendarGUIRemoveEvent(org.olat.commons.calendar.ui.events.CalendarGUIRemoveEvent) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) CalendarGUIModifiedEvent(org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent)

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