Search in sources :

Example 11 with Kalendar

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

the class ICalFileCalendarManager method createAggregatedCalendarConfig.

@Override
public CalendarUserConfiguration createAggregatedCalendarConfig(Identity identity) {
    String token = RandomStringUtils.randomAlphanumeric(6);
    Kalendar calendar = new Kalendar(identity.getKey().toString(), CalendarManager.TYPE_USER_AGGREGATED);
    return calendarUserConfigDao.createCalendarUserConfiguration(calendar, identity, token, true, true);
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar)

Example 12 with Kalendar

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

the class ICalFileCalendarManager method removeEventFrom.

/**
 * @see org.olat.commons.calendar.CalendarManager#removeEventFrom(org.olat.commons.calendar.model.Kalendar, org.olat.commons.calendar.model.KalendarEvent)
 */
@Override
public boolean removeEventFrom(final Kalendar cal, final KalendarEvent kalendarEvent) {
    OLATResourceable calOres = getOresHelperFor(cal);
    Boolean removeSuccessful = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calOres, new SyncerCallback<Boolean>() {

        @Override
        public Boolean execute() {
            String uid = kalendarEvent.getID();
            String recurrenceId = kalendarEvent.getRecurrenceID();
            Kalendar loadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
            if (StringHelper.containsNonWhitespace(recurrenceId)) {
                loadedCal.removeEvent(kalendarEvent);
                KalendarEvent rootEvent = loadedCal.getEvent(kalendarEvent.getID(), null);
                if (rootEvent != null && kalendarEvent instanceof KalendarRecurEvent) {
                    Date recurrenceDate = ((KalendarRecurEvent) kalendarEvent).getOccurenceDate();
                    rootEvent.addRecurrenceExc(recurrenceDate);
                }
            } else {
                for (KalendarEvent kEvent : loadedCal.getEvents()) {
                    if (uid.equals(kEvent.getID())) {
                        loadedCal.removeEvent(kEvent);
                    }
                }
            }
            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 removeSuccessful.booleanValue();
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) Kalendar(org.olat.commons.calendar.model.Kalendar) OLATResourceable(org.olat.core.id.OLATResourceable) KalendarRecurEvent(org.olat.commons.calendar.model.KalendarRecurEvent) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Date(java.util.Date) ExDate(net.fortuna.ical4j.model.property.ExDate) CalendarGUIModifiedEvent(org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent)

Example 13 with Kalendar

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

the class ICalFileCalendarManager method getPersonalCalendar.

@Override
public KalendarRenderWrapper getPersonalCalendar(Identity identity) {
    Kalendar cal = getCalendar(CalendarManager.TYPE_USER, identity.getName());
    String fullName = userManager.getUserDisplayName(identity);
    KalendarRenderWrapper calendarWrapper = new KalendarRenderWrapper(cal, fullName);
    calendarWrapper.setCssClass(KalendarRenderWrapper.CALENDAR_COLOR_BLUE);
    calendarWrapper.setVisible(true);
    return calendarWrapper;
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Example 14 with Kalendar

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

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)

Example 15 with Kalendar

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

the class ICalFileCalendarManager method removeOccurenceOfEvent.

@Override
public boolean removeOccurenceOfEvent(final Kalendar cal, final KalendarRecurEvent kalendarEvent) {
    OLATResourceable calOres = getOresHelperFor(cal);
    Boolean removeSuccessful = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calOres, new SyncerCallback<Boolean>() {

        @Override
        public Boolean execute() {
            String uid = kalendarEvent.getID();
            Date occurenceDate = kalendarEvent.getBegin();
            Kalendar loadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
            KalendarEvent rootEvent = loadedCal.getEvent(kalendarEvent.getID(), null);
            rootEvent.addRecurrenceExc(kalendarEvent.getBegin());
            for (KalendarEvent kEvent : loadedCal.getEvents()) {
                if (uid.equals(kEvent.getID()) && kEvent.getOccurenceDate() != null && occurenceDate.equals(kEvent.getOccurenceDate())) {
                    loadedCal.removeEvent(kEvent);
                }
            }
            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 removeSuccessful.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) Date(java.util.Date) ExDate(net.fortuna.ical4j.model.property.ExDate) 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