Search in sources :

Example 41 with Kalendar

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

the class ICalFileCalendarManagerTest method testWithinOneDay.

@Test
public void testWithinOneDay() throws IOException {
    Identity test = JunitTestHelper.createAndPersistIdentityAsRndUser("ical-4-");
    Kalendar cal = calendarManager.getPersonalCalendar(test).getKalendar();
    // 1. Test Today Event
    String eventId = "short-" + UUID.randomUUID();
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.HOUR_OF_DAY, 14);
    Date start = calendar.getTime();
    calendar.set(Calendar.HOUR_OF_DAY, 15);
    Date end = calendar.getTime();
    KalendarEvent testEvent = new KalendarEvent(eventId, null, "Short Event", start, end);
    calendarManager.addEventTo(cal, testEvent);
    // Next days event
    String nextEventId = "long-" + UUID.randomUUID();
    calendar = Calendar.getInstance();
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.add(Calendar.DATE, 3);
    calendar.set(Calendar.HOUR, 8);
    Date nextStart = calendar.getTime();
    calendar = Calendar.getInstance();
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.add(Calendar.DATE, 6);
    calendar.set(Calendar.HOUR_OF_DAY, 18);
    Date nextEnd = calendar.getTime();
    KalendarEvent nextEvent = new KalendarEvent(nextEventId, null, "Long Event", nextStart, nextEnd);
    calendarManager.addEventTo(cal, nextEvent);
    // 2. reload and test
    emptyCalendarCache();
    KalendarEvent reloadedEvent = calendarManager.getPersonalCalendar(test).getKalendar().getEvent(eventId, null);
    Assert.assertNotNull(reloadedEvent);
    Assert.assertEquals("Short Event", reloadedEvent.getSubject());
    Assert.assertEquals(start, reloadedEvent.getBegin());
    Assert.assertEquals(end, reloadedEvent.getEnd());
    Assert.assertTrue(reloadedEvent.isToday());
    Assert.assertTrue(reloadedEvent.isWithinOneDay());
    Assert.assertFalse(reloadedEvent.isAllDayEvent());
    KalendarEvent reloadedNextEvent = calendarManager.getPersonalCalendar(test).getKalendar().getEvent(nextEventId, null);
    Assert.assertNotNull(reloadedNextEvent);
    Assert.assertEquals("Long Event", reloadedNextEvent.getSubject());
    Assert.assertEquals(nextStart, reloadedNextEvent.getBegin());
    Assert.assertEquals(nextEnd, reloadedNextEvent.getEnd());
    Assert.assertFalse(reloadedNextEvent.isToday());
    Assert.assertFalse(reloadedNextEvent.isWithinOneDay());
    Assert.assertFalse(reloadedNextEvent.isAllDayEvent());
}
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 42 with Kalendar

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

the class OLATUpgrade_10_4_0 method processCalendarProperty.

private void processCalendarProperty(Property property) {
    String calendarId;
    Identity identity = property.getIdentity();
    String resourceType = property.getResourceTypeName();
    if (StringHelper.containsNonWhitespace(resourceType) && property.getResourceTypeId() != null) {
        calendarId = property.getResourceTypeId().toString();
    } else {
        resourceType = CalendarManager.TYPE_USER;
        calendarId = identity.getName();
    }
    CalendarUserConfiguration config = calendarUserConfigurationDao.getCalendarUserConfiguration(identity, calendarId, resourceType);
    if (config == null) {
        String token = property.getStringValue();
        Kalendar mockCal = new Kalendar(calendarId, resourceType);
        calendarUserConfigurationDao.createCalendarUserConfiguration(mockCal, identity, token, true, true);
    }
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) Identity(org.olat.core.id.Identity)

Example 43 with Kalendar

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

the class OLATUpgrade_10_4_0 method processKalendarConfig.

private void processKalendarConfig(Identity identity, String calendarId, KalendarConfig config) {
    Kalendar cal;
    CalendarUserConfiguration userConfig;
    if (StringHelper.isLong(calendarId)) {
        // guess if it's a course or a group calendar
        if (calendarMgr.getCalendarFile(CalendarManager.TYPE_COURSE, calendarId) != null) {
            cal = new Kalendar(calendarId, CalendarManager.TYPE_COURSE);
        } else if (calendarMgr.getCalendarFile(CalendarManager.TYPE_GROUP, calendarId) != null) {
            cal = new Kalendar(calendarId, CalendarManager.TYPE_GROUP);
        } else {
            return;
        }
    } else {
        // personal calendar
        cal = new Kalendar(calendarId, CalendarManager.TYPE_USER);
    }
    userConfig = calendarUserConfigurationDao.getCalendarUserConfiguration(identity, cal.getCalendarID(), cal.getType());
    if (userConfig == null) {
        userConfig = calendarUserConfigurationDao.createCalendarUserConfiguration(cal, identity);
        userConfig.setCssClass(config.getCss());
        userConfig.setVisible(config.isVis());
        userConfig = calendarUserConfigurationDao.update(userConfig);
    }
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration)

Example 44 with Kalendar

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

the class LectureServiceImpl method syncInternalCalendar.

private void syncInternalCalendar(LectureBlock lectureBlock, List<Identity> identities) {
    RepositoryEntry entry = lectureBlock.getEntry();
    for (Identity identity : identities) {
        Kalendar cal = calendarMgr.getCalendar(CalendarManager.TYPE_USER, identity.getName());
        syncEvent(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)

Example 45 with Kalendar

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

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)

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