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());
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations