Search in sources :

Example 96 with Kalendar

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

the class LectureServiceImpl method unsyncInternalCalendar.

private void unsyncInternalCalendar(RepositoryEntry entry) {
    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)) {
            calendarMgr.removeEventFrom(cal, event);
        }
    }
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent)

Example 97 with Kalendar

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

the class CalendarUserConfigurationDAOTest method getCalendarUserConfigurations.

@Test
public void getCalendarUserConfigurations() {
    Identity user = JunitTestHelper.createAndPersistIdentityAsRndUser("Cal-2");
    String calendarId = UUID.randomUUID().toString();
    Kalendar calendar = new Kalendar(calendarId, CalendarManager.TYPE_COURSE);
    CalendarUserConfiguration config = calendarDao.createCalendarUserConfiguration(calendar, user);
    dbInstance.commit();
    Assert.assertNotNull(config);
    // retrieve
    List<CalendarUserConfiguration> configList = calendarDao.getCalendarUserConfigurations(user);
    Assert.assertNotNull(configList);
    Assert.assertEquals(1, configList.size());
    Assert.assertEquals(config, configList.get(0));
    // paranoia check
    CalendarUserConfiguration loadedConfig = configList.get(0);
    Assert.assertNotNull(loadedConfig.getCreationDate());
    Assert.assertNotNull(loadedConfig.getLastModified());
    Assert.assertEquals(config.getKey(), loadedConfig.getKey());
    Assert.assertEquals(calendarId, loadedConfig.getCalendarId());
    Assert.assertEquals(CalendarManager.TYPE_COURSE, loadedConfig.getType());
    Assert.assertEquals(user, loadedConfig.getIdentity());
    Assert.assertTrue(loadedConfig.isVisible());
    Assert.assertTrue(loadedConfig.isInAggregatedFeed());
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 98 with Kalendar

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

the class ICalFileCalendarManagerTest method updateCalendar.

@Test
public void updateCalendar() throws ValidationException, IOException {
    Identity test = JunitTestHelper.createAndPersistIdentityAsRndUser("u1-");
    Kalendar cal = calendarManager.getPersonalCalendar(test).getKalendar();
    String eventIdMarker = "id-marker-event";
    // 1. Add a standard event, not managed
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.MILLISECOND, 0);
    Date start = calendar.getTime();
    calendar.add(Calendar.HOUR_OF_DAY, 1);
    Date end = calendar.getTime();
    KalendarEvent markerEvent = new KalendarEvent(eventIdMarker, null, "markerEvent", start, end);
    calendarManager.addEventTo(cal, markerEvent);
    // 2. Update with a first calendar
    Kalendar baseCalendar = calendarManager.createCalendar("user", "first-update");
    String eventId1 = "event-1";
    KalendarEvent event1 = new KalendarEvent(eventId1, null, "event 1", start, end);
    baseCalendar.addEvent(event1);
    String eventId2 = "event-2";
    KalendarEvent event2 = new KalendarEvent(eventId2, null, "event 2", start, end);
    baseCalendar.addEvent(event2);
    calendarManager.updateCalendar(cal, baseCalendar);
    // 3. Update with a second calendar
    Kalendar updateCalendar = calendarManager.createCalendar("user", "first-update");
    KalendarEvent event1alt = new KalendarEvent(eventId1, null, "event 1 alt", start, end);
    updateCalendar.addEvent(event1alt);
    String eventId3 = "event-3";
    KalendarEvent event3 = new KalendarEvent(eventId3, null, "event 3", start, end);
    updateCalendar.addEvent(event3);
    calendarManager.updateCalendar(cal, updateCalendar);
    // Check
    emptyCalendarCache();
    Kalendar reloadedCal = calendarManager.getPersonalCalendar(test).getKalendar();
    KalendarEvent marker = reloadedCal.getEvent(eventIdMarker, null);
    Assert.assertNotNull(marker);
    Assert.assertEquals("markerEvent", marker.getSubject());
    KalendarEvent reloaded1 = reloadedCal.getEvent(eventId1, null);
    Assert.assertNotNull(reloaded1);
    Assert.assertEquals("event 1 alt", reloaded1.getSubject());
    KalendarEvent reloaded2 = reloadedCal.getEvent(eventId2, null);
    Assert.assertNotNull(reloaded2);
    Assert.assertEquals("event 2", reloaded2.getSubject());
    KalendarEvent reloaded3 = reloadedCal.getEvent(eventId3, null);
    Assert.assertNotNull(reloaded3);
    Assert.assertEquals("event 3", reloaded3.getSubject());
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) Calendar(java.util.Calendar) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Identity(org.olat.core.id.Identity) Date(java.util.Date) CalendarImportTest(org.olat.commons.calendar.CalendarImportTest) Test(org.junit.Test)

Example 99 with Kalendar

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

the class ICalFileCalendarManagerTest method synchronizeCalendarFrom.

@Test
public void synchronizeCalendarFrom() throws ValidationException, IOException {
    Identity test = JunitTestHelper.createAndPersistIdentityAsRndUser("s1-");
    Kalendar cal = calendarManager.getPersonalCalendar(test).getKalendar();
    String eventId1 = "id-not-managed-event";
    // 1. Add a standard event, not managed
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.MILLISECOND, 0);
    Date start = calendar.getTime();
    calendar.add(Calendar.HOUR_OF_DAY, 1);
    Date end = calendar.getTime();
    KalendarEvent notManagedEvent = new KalendarEvent(eventId1, null, "testEvent", start, end);
    calendarManager.addEventTo(cal, notManagedEvent);
    // 2. Synchronize with a first calendar
    Kalendar baseCalendar = calendarManager.createCalendar("user", "first-sync");
    String eventIdManaged1 = "managed-event-1";
    KalendarEvent managedEvent1 = new KalendarEvent(eventIdManaged1, null, "managedEvent", start, end);
    baseCalendar.addEvent(managedEvent1);
    String eventIdManaged2 = "managed-event-2";
    KalendarEvent managedEvent2 = new KalendarEvent(eventIdManaged2, null, "managedEvent", start, end);
    baseCalendar.addEvent(managedEvent2);
    ByteArrayOutputStream os1 = new ByteArrayOutputStream();
    new CalendarOutputter(false).output(calendarManager.buildCalendar(baseCalendar), os1);
    InputStream in1 = new ByteArrayInputStream(os1.toByteArray());
    calendarManager.synchronizeCalendarFrom(in1, "http://localhost:8080/unittest", cal);
    in1.close();
    // 3. Synchronize with a second calendar
    Kalendar resyncCalendar = calendarManager.createCalendar("user", "first-sync");
    KalendarEvent managedEvent1Alt = new KalendarEvent(eventIdManaged1, null, "managedEvent resync", start, end);
    resyncCalendar.addEvent(managedEvent1Alt);
    String eventIdManaged3 = "managed-event-3";
    KalendarEvent managedEvent3 = new KalendarEvent(eventIdManaged3, null, "managedEvent 3", start, end);
    resyncCalendar.addEvent(managedEvent3);
    ByteArrayOutputStream os2 = new ByteArrayOutputStream();
    new CalendarOutputter(false).output(calendarManager.buildCalendar(resyncCalendar), os2);
    InputStream in2 = new ByteArrayInputStream(os2.toByteArray());
    calendarManager.synchronizeCalendarFrom(in2, "http://localhost:8080/unittest", cal);
    in2.close();
    emptyCalendarCache();
    // check
    Kalendar synchedCal = calendarManager.getPersonalCalendar(test).getKalendar();
    KalendarEvent notManagedEvent1 = synchedCal.getEvent(eventId1, null);
    Assert.assertNotNull(notManagedEvent1);
    Assert.assertEquals("testEvent", notManagedEvent1.getSubject());
    KalendarEvent event1 = synchedCal.getEvent(eventIdManaged1, null);
    Assert.assertNotNull(event1);
    Assert.assertEquals("managedEvent resync", event1.getSubject());
    KalendarEvent event2 = synchedCal.getEvent(eventIdManaged2, null);
    Assert.assertNull(event2);
    KalendarEvent event3 = synchedCal.getEvent(eventIdManaged3, null);
    Assert.assertNotNull(event3);
    Assert.assertEquals("managedEvent 3", event3.getSubject());
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Calendar(java.util.Calendar) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CalendarOutputter(net.fortuna.ical4j.data.CalendarOutputter) Identity(org.olat.core.id.Identity) Date(java.util.Date) CalendarImportTest(org.olat.commons.calendar.CalendarImportTest) Test(org.junit.Test)

Example 100 with Kalendar

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

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