Search in sources :

Example 16 with CalendarGUIModifiedEvent

use of org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent in project OpenOLAT by OpenOLAT.

the class ICalFileCalendarManager method synchronizeCalendarFrom.

@Override
public boolean synchronizeCalendarFrom(InputStream in, String source, Kalendar targetCalendar) {
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
        Calendar inCalendar = new CalendarBuilder().build(reader);
        Kalendar inTmpKalendar = createKalendar("TEMP", UUID.randomUUID().toString(), inCalendar);
        String targetId = "-" + targetCalendar.getType() + "-" + targetCalendar.getCalendarID() + "-";
        OLATResourceable calOres = getOresHelperFor(targetCalendar);
        Boolean updatedSuccessful = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calOres, new SyncerCallback<Boolean>() {

            @Override
            public Boolean execute() {
                // remove event in target calendar which doesn't exist in stream
                Collection<KalendarEvent> currentEvents = targetCalendar.getEvents();
                for (KalendarEvent currentEvent : currentEvents) {
                    if (currentEvent.getExternalSource() != null && source.equals(currentEvent.getExternalSource())) {
                        String eventId = currentEvent.getID();
                        String recurrenceId = currentEvent.getRecurrenceID();
                        if (inTmpKalendar.getEvent(eventId, recurrenceId) == null) {
                            targetCalendar.removeEvent(currentEvent);
                        } else if (eventId.contains(targetId)) {
                            // don't import myself;
                            targetCalendar.removeEvent(currentEvent);
                        }
                    }
                }
                Collection<KalendarEvent> inEvents = inTmpKalendar.getEvents();
                for (KalendarEvent inEvent : inEvents) {
                    if (inEvent.getID().contains(targetId)) {
                        continue;
                    }
                    inEvent.setManagedFlags(new CalendarManagedFlag[] { CalendarManagedFlag.all });
                    inEvent.setExternalSource(source);
                    KalendarEvent currentEvent = targetCalendar.getEvent(inEvent.getID(), inEvent.getRecurrenceID());
                    if (currentEvent == null) {
                        targetCalendar.addEvent(inEvent);
                    } else {
                        // need perhaps more refined synchronization per event
                        targetCalendar.addEvent(inEvent);
                    }
                }
                boolean successfullyPersist = persistCalendar(targetCalendar);
                // inform all controller about calendar change for reload
                CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(targetCalendar), OresHelper.lookupType(CalendarManager.class));
                return new Boolean(successfullyPersist);
            }
        });
        return updatedSuccessful.booleanValue();
    } catch (Exception e) {
        log.error("", e);
        return false;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) CalendarBuilder(net.fortuna.ical4j.data.CalendarBuilder) OLATResourceable(org.olat.core.id.OLATResourceable) Calendar(net.fortuna.ical4j.model.Calendar) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) URISyntaxException(java.net.URISyntaxException) ParseException(java.text.ParseException) FileNotFoundException(java.io.FileNotFoundException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) Kalendar(org.olat.commons.calendar.model.Kalendar) BufferedReader(java.io.BufferedReader) CalendarManagedFlag(org.olat.commons.calendar.CalendarManagedFlag) Collection(java.util.Collection) CalendarGUIModifiedEvent(org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent)

Example 17 with CalendarGUIModifiedEvent

use of org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent in project OpenOLAT by OpenOLAT.

the class ICalFileCalendarManager method addEventTo.

@Override
public boolean addEventTo(final Kalendar cal, final List<KalendarEvent> kalendarEvents) {
    OLATResourceable calOres = getOresHelperFor(cal);
    Boolean persistSuccessful = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calOres, new SyncerCallback<Boolean>() {

        @Override
        public Boolean execute() {
            Kalendar loadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
            for (KalendarEvent kalendarEvent : kalendarEvents) {
                loadedCal.addEvent(kalendarEvent);
                kalendarEvent.resetImmutableDates();
            }
            boolean successfullyPersist = persistCalendar(loadedCal);
            return new Boolean(successfullyPersist);
        }
    });
    // inform all controller about calendar change for reload
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(cal), OresHelper.lookupType(CalendarManager.class));
    return persistSuccessful.booleanValue();
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) Kalendar(org.olat.commons.calendar.model.Kalendar) OLATResourceable(org.olat.core.id.OLATResourceable) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) CalendarGUIModifiedEvent(org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent)

Example 18 with CalendarGUIModifiedEvent

use of org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent in project OpenOLAT by OpenOLAT.

the class ICalFileCalendarManager method updateEventsFrom.

@Override
public boolean updateEventsFrom(Kalendar cal, List<KalendarEvent> kalendarEvents) {
    final OLATResourceable calOres = getOresHelperFor(cal);
    Boolean updatedSuccessful = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calOres, new SyncerCallback<Boolean>() {

        @Override
        public Boolean execute() {
            Kalendar loadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
            for (KalendarEvent kalendarEvent : kalendarEvents) {
                // remove old event
                loadedCal.removeEvent(kalendarEvent);
                // add changed event
                loadedCal.addEvent(kalendarEvent);
            }
            boolean successfullyPersist = persistCalendar(loadedCal);
            // inform all controller about calendar change for reload
            CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(cal), OresHelper.lookupType(CalendarManager.class));
            return successfullyPersist;
        }
    });
    return updatedSuccessful.booleanValue();
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) OLATResourceable(org.olat.core.id.OLATResourceable) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) CalendarGUIModifiedEvent(org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent)

Example 19 with CalendarGUIModifiedEvent

use of org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent in project OpenOLAT by OpenOLAT.

the class CourseOptionsController method doChangeConfig.

private void doChangeConfig(UserRequest ureq) {
    OLATResourceable courseOres = entry.getOlatResource();
    ICourse course = CourseFactory.openCourseEditSession(courseOres.getResourceableId());
    courseConfig = course.getCourseEnvironment().getCourseConfig();
    boolean menuEnabled = menuEl.isSelected(0);
    courseConfig.setMenuEnabled(menuEnabled);
    boolean toolbarEnabled = toolbarEl.isSelected(0);
    courseConfig.setToolbarEnabled(toolbarEnabled);
    boolean enableSearch = searchEl.isSelected(0);
    boolean updateSearch = courseConfig.isCourseSearchEnabled() != enableSearch;
    courseConfig.setCourseSearchEnabled(enableSearch && toolbarEnabled);
    boolean enableChat = chatEl.isSelected(0);
    boolean updateChat = courseConfig.isChatEnabled() != enableChat;
    courseConfig.setChatIsEnabled(enableChat && toolbarEnabled);
    boolean enableCalendar = calendarEl == null ? false : calendarEl.isSelected(0);
    boolean updateCalendar = courseConfig.isCalendarEnabled() != enableCalendar && calendarModule.isEnableCourseToolCalendar();
    courseConfig.setCalendarEnabled(enableCalendar && toolbarEnabled);
    String currentGlossarySoftKey = courseConfig.getGlossarySoftKey();
    RepositoryEntry glossary = (RepositoryEntry) glossaryNameEl.getUserObject();
    String newGlossarySoftKey = (glossary == null || !toolbarEnabled) ? null : glossary.getSoftkey();
    boolean updateGlossary = (currentGlossarySoftKey == null && newGlossarySoftKey != null) || (currentGlossarySoftKey != null && newGlossarySoftKey == null) || (newGlossarySoftKey != null && !newGlossarySoftKey.equals(currentGlossarySoftKey));
    courseConfig.setGlossarySoftKey(newGlossarySoftKey);
    String currentFolderSoftKey = courseConfig.getSharedFolderSoftkey();
    RepositoryEntry folder = (RepositoryEntry) folderNameEl.getUserObject();
    String newFolderSoftKey = folder == null ? null : folder.getSoftkey();
    boolean updateFolder = (currentFolderSoftKey == null && newFolderSoftKey != null) || (currentFolderSoftKey != null && newFolderSoftKey == null) || (currentFolderSoftKey != null && !currentFolderSoftKey.equals(newFolderSoftKey));
    courseConfig.setSharedFolderSoftkey(newFolderSoftKey);
    if (folderReadOnlyEl.isEnabled()) {
        courseConfig.setSharedFolderReadOnlyMount(folderReadOnlyEl.isAtLeastSelected(1));
    } else {
        courseConfig.setSharedFolderReadOnlyMount(true);
    }
    CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
    CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
    if (updateSearch) {
        ILoggingAction loggingAction = enableSearch ? LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_COURSESEARCH_ENABLED : LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_COURSESEARCH_DISABLED;
        ThreadLocalUserActivityLogger.log(loggingAction, getClass());
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CourseConfigEvent(CourseConfigType.search, course.getResourceableId()), course);
    }
    if (updateChat) {
        ILoggingAction loggingAction = enableChat ? LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_IM_ENABLED : LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_IM_DISABLED;
        ThreadLocalUserActivityLogger.log(loggingAction, getClass());
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CourseConfigEvent(CourseConfigType.chat, course.getResourceableId()), course);
    }
    if (updateCalendar) {
        ILoggingAction loggingAction = enableCalendar ? LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_CALENDAR_ENABLED : LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_CALENDAR_DISABLED;
        ThreadLocalUserActivityLogger.log(loggingAction, getClass());
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(), OresHelper.lookupType(CalendarManager.class));
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CourseConfigEvent(CourseConfigType.calendar, course.getResourceableId()), course);
    }
    if (updateGlossary) {
        ILoggingAction loggingAction = (newGlossarySoftKey == null) ? LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_GLOSSARY_DISABLED : LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_GLOSSARY_ENABLED;
        LoggingResourceable lri = null;
        if (newGlossarySoftKey != null) {
            lri = LoggingResourceable.wrapNonOlatResource(StringResourceableType.glossarySoftKey, newGlossarySoftKey, newGlossarySoftKey);
        } else if (currentGlossarySoftKey != null) {
            lri = LoggingResourceable.wrapNonOlatResource(StringResourceableType.glossarySoftKey, currentGlossarySoftKey, currentGlossarySoftKey);
        }
        if (lri != null) {
            ThreadLocalUserActivityLogger.log(loggingAction, getClass(), lri);
        }
        // remove references
        List<Reference> repoRefs = referenceManager.getReferences(course);
        for (Reference ref : repoRefs) {
            if (ref.getUserdata().equals(GlossaryManager.GLOSSARY_REPO_REF_IDENTIFYER)) {
                referenceManager.delete(ref);
            }
        }
        // update references
        if (glossary != null) {
            referenceManager.addReference(course, glossary.getOlatResource(), GlossaryManager.GLOSSARY_REPO_REF_IDENTIFYER);
        }
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CourseConfigEvent(CourseConfigType.glossary, course.getResourceableId()), course);
    }
    if (updateFolder) {
        List<Reference> repoRefs = referenceManager.getReferences(course);
        for (Reference ref : repoRefs) {
            if (ref.getUserdata().equals(SharedFolderManager.SHAREDFOLDERREF)) {
                referenceManager.delete(ref);
            }
        }
        if (folder != null) {
            referenceManager.addReference(course, folder.getOlatResource(), SharedFolderManager.SHAREDFOLDERREF);
            ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_SHARED_FOLDER_REMOVED, getClass(), LoggingResourceable.wrapBCFile(folder.getDisplayname()));
        } else {
            ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_SHARED_FOLDER_ADDED, getClass(), LoggingResourceable.wrapBCFile(""));
        }
    }
    fireEvent(ureq, Event.CHANGED_EVENT);
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) CourseConfigEvent(org.olat.course.config.CourseConfigEvent) OLATResourceable(org.olat.core.id.OLATResourceable) Reference(org.olat.resource.references.Reference) ILoggingAction(org.olat.core.logging.activity.ILoggingAction) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) CalendarGUIModifiedEvent(org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent) LoggingResourceable(org.olat.util.logging.activity.LoggingResourceable)

Example 20 with CalendarGUIModifiedEvent

use of org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent in project openolat by klemens.

the class ICalFileCalendarManager method updateEventAlreadyInSync.

/**
 * @see org.olat.commons.calendar.CalendarManager#updateEventFrom(org.olat.commons.calendar.model.Kalendar, org.olat.commons.calendar.model.KalendarEvent)
 */
@Override
public boolean updateEventAlreadyInSync(final Kalendar cal, final KalendarEvent kalendarEvent) {
    OLATResourceable calOres = getOresHelperFor(cal);
    CoordinatorManager.getInstance().getCoordinator().getSyncer().assertAlreadyDoInSyncFor(calOres);
    Kalendar reloadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
    if (StringHelper.containsNonWhitespace(kalendarEvent.getRecurrenceRule())) {
        Date oldBegin = kalendarEvent.getImmutableBegin();
        Date oldEnd = kalendarEvent.getImmutableEnd();
        KalendarEvent originalEvent = reloadedCal.getEvent(kalendarEvent.getID(), null);
        Date newBegin = kalendarEvent.getBegin();
        Date newEnd = kalendarEvent.getEnd();
        long beginDiff = newBegin.getTime() - oldBegin.getTime();
        long endDiff = newEnd.getTime() - oldEnd.getTime();
        java.util.Calendar cl = java.util.Calendar.getInstance();
        cl.setTime(originalEvent.getBegin());
        cl.add(java.util.Calendar.MILLISECOND, (int) beginDiff);
        kalendarEvent.setBegin(cl.getTime());
        cl.setTime(originalEvent.getEnd());
        cl.add(java.util.Calendar.MILLISECOND, (int) endDiff);
        kalendarEvent.setEnd(cl.getTime());
        List<KalendarEvent> exEvents = new ArrayList<>();
        List<KalendarEvent> allEvents = reloadedCal.getEvents();
        for (KalendarEvent event : allEvents) {
            if (event.getID().equals(kalendarEvent.getID()) && StringHelper.containsNonWhitespace(event.getRecurrenceID())) {
                exEvents.add(event);
            }
        }
        if (exEvents.size() > 0) {
            for (KalendarEvent exEvent : exEvents) {
                try {
                    reloadedCal.removeEvent(exEvent);
                    String recurrenceId = exEvent.getRecurrenceID();
                    RecurrenceId recurId = new RecurrenceId(recurrenceId, tz);
                    Date currentRecurrence = recurId.getDate();
                    java.util.Calendar calc = java.util.Calendar.getInstance();
                    calc.clear();
                    calc.setTime(currentRecurrence);
                    if (beginDiff > 0) {
                        calc.add(java.util.Calendar.MILLISECOND, (int) beginDiff);
                    }
                    Date newRecurrenceDate = calc.getTime();
                    boolean allDay = kalendarEvent.isAllDayEvent();
                    RecurrenceId newRecurId;
                    if (allDay) {
                        newRecurId = new RecurrenceId(tz);
                        newRecurId.setDate(CalendarUtils.createDate(newRecurrenceDate));
                    } else {
                        String startString = CalendarUtils.formatRecurrenceDate(newRecurrenceDate, false);
                        newRecurId = new RecurrenceId(startString, tz);
                    }
                    exEvent.setRecurrenceID(newRecurId.getValue());
                    reloadedCal.addEvent(exEvent);
                } catch (ParseException e) {
                    log.error("", e);
                }
            }
        }
    }
    // remove old event
    reloadedCal.removeEvent(kalendarEvent);
    kalendarEvent.resetImmutableDates();
    // add changed event
    reloadedCal.addEvent(kalendarEvent);
    boolean successfullyPersist = persistCalendar(reloadedCal);
    // inform all controller about calendar change for reload
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(cal), OresHelper.lookupType(CalendarManager.class));
    return successfullyPersist;
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Date(java.util.Date) ExDate(net.fortuna.ical4j.model.property.ExDate) CalendarManager(org.olat.commons.calendar.CalendarManager) Kalendar(org.olat.commons.calendar.model.Kalendar) RecurrenceId(net.fortuna.ical4j.model.property.RecurrenceId) ParseException(java.text.ParseException) CalendarGUIModifiedEvent(org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent)

Aggregations

CalendarGUIModifiedEvent (org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent)26 Kalendar (org.olat.commons.calendar.model.Kalendar)18 KalendarEvent (org.olat.commons.calendar.model.KalendarEvent)18 OLATResourceable (org.olat.core.id.OLATResourceable)18 CalendarManager (org.olat.commons.calendar.CalendarManager)14 Date (java.util.Date)8 ExDate (net.fortuna.ical4j.model.property.ExDate)8 ParseException (java.text.ParseException)6 KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)4 BufferedReader (java.io.BufferedReader)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStreamReader (java.io.InputStreamReader)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CalendarBuilder (net.fortuna.ical4j.data.CalendarBuilder)2 Calendar (net.fortuna.ical4j.model.Calendar)2 Recur (net.fortuna.ical4j.model.Recur)2