Search in sources :

Example 91 with Kalendar

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

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)

Example 92 with Kalendar

use of org.olat.commons.calendar.model.Kalendar 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 93 with Kalendar

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

the class CourseCalendarController method needToDifferentiateManagedEvents.

private boolean needToDifferentiateManagedEvents(List<KalendarRenderWrapper> calednarWrappers) {
    boolean hasManaged = false;
    for (KalendarRenderWrapper wrapper : calednarWrappers) {
        Kalendar cal = wrapper.getKalendar();
        hasManaged |= cal.hasManagedEvents();
    }
    return hasManaged;
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Example 94 with Kalendar

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

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 95 with Kalendar

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

the class LectureServiceImpl method unsyncInternalCalendar.

private void unsyncInternalCalendar(LectureBlock lectureBlock, List<Identity> identities) {
    RepositoryEntry entry = lectureBlock.getEntry();
    for (Identity identity : identities) {
        Kalendar cal = calendarMgr.getCalendar(CalendarManager.TYPE_USER, identity.getName());
        unsyncEvent(lectureBlock, entry, cal);
        lectureParticipantSummaryDao.updateCalendarSynchronization(entry, identity);
    }
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity)

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