Search in sources :

Example 16 with Kalendar

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

the class ICalFileCalendarManager method updateCalendar.

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

        @Override
        public Boolean execute() {
            Map<KalendarEventKey, KalendarEvent> uidToEvent = new HashMap<>();
            for (KalendarEvent event : cal.getEvents()) {
                if (StringHelper.containsNonWhitespace(event.getID())) {
                    uidToEvent.put(new KalendarEventKey(event), event);
                }
            }
            Kalendar loadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
            for (KalendarEvent importedEvent : importedCal.getEvents()) {
                KalendarEventKey uid = new KalendarEventKey(importedEvent);
                if (uidToEvent.containsKey(uid)) {
                    // remove old event
                    loadedCal.removeEvent(importedEvent);
                    // add changed event
                    loadedCal.addEvent(importedEvent);
                } else {
                    loadedCal.addEvent(importedEvent);
                }
            }
            boolean successfullyPersist = persistCalendar(cal);
            // inform all controller about calendar change for reload
            CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(cal), OresHelper.lookupType(CalendarManager.class));
            return new Boolean(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) KalendarEventKey(org.olat.commons.calendar.model.KalendarEventKey) Map(java.util.Map) HashMap(java.util.HashMap) CalendarGUIModifiedEvent(org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent)

Example 17 with Kalendar

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

the class ICalFileCalendarManager method createKalendar.

protected Kalendar createKalendar(String type, String calendarID, Calendar calendar) {
    Kalendar cal = new Kalendar(calendarID, type);
    for (Iterator<?> iter = calendar.getComponents().iterator(); iter.hasNext(); ) {
        Object comp = iter.next();
        if (comp instanceof VEvent) {
            VEvent vevent = (VEvent) comp;
            KalendarEvent calEvent = getKalendarEvent(vevent);
            cal.addEvent(calEvent);
        } else if (comp instanceof VTimeZone) {
            log.info("createKalendar: VTimeZone Component is not supported and will not be added to calender");
            log.debug("createKalendar: VTimeZone=" + comp);
        } else {
            log.warn("createKalendar: unknown Component=" + comp);
        }
    }
    return cal;
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) Kalendar(org.olat.commons.calendar.model.Kalendar) VTimeZone(net.fortuna.ical4j.model.component.VTimeZone) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent)

Example 18 with Kalendar

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

the class LectureServiceImpl method unsyncInternalCalendar.

/*
	private void unsyncParticipantsCalendar(RepositoryEntry entry) {
		List<Identity> participants = getParticipants(entry);
		unsyncInternalCalendar(entry, participants);
	}
	*/
private void unsyncInternalCalendar(RepositoryEntry entry, List<Identity> identities) {
    String prefix = generateExternalIdPrefix(entry);
    for (Identity identity : identities) {
        Kalendar cal = calendarMgr.getCalendar(CalendarManager.TYPE_USER, identity.getName());
        List<KalendarEvent> events = new ArrayList<>(cal.getEvents());
        for (KalendarEvent event : events) {
            if (event.getExternalId() != null && event.getExternalId().startsWith(prefix)) {
                calendarMgr.removeEventFrom(cal, event);
            }
        }
        lectureParticipantSummaryDao.updateCalendarSynchronization(entry, identity);
    }
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Identity(org.olat.core.id.Identity)

Example 19 with Kalendar

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

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

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

the class LectureServiceImpl method unsyncCourseCalendar.

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

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