use of org.olat.commons.calendar.model.ImportedCalendar in project openolat by klemens.
the class ImportedCalendarDAOTest method createImportedCalendar.
@Test
public void createImportedCalendar() {
Identity user = JunitTestHelper.createAndPersistIdentityAsRndUser("Imp-cal-1");
String calendarId = UUID.randomUUID().toString();
String type = "imported-test";
String url = "http://www.openolat.org/calendar.ics";
ImportedCalendar importedCalendar = importedCalendarDao.createImportedCalendar(user, "Imported calendar", calendarId, type, url, new Date());
Assert.assertNotNull(importedCalendar);
dbInstance.commit();
Assert.assertNotNull(importedCalendar.getKey());
Assert.assertNotNull(importedCalendar.getCreationDate());
Assert.assertNotNull(importedCalendar.getLastModified());
Assert.assertNotNull(importedCalendar.getLastUpdate());
Assert.assertEquals("Imported calendar", importedCalendar.getDisplayName());
Assert.assertEquals(user, importedCalendar.getIdentity());
Assert.assertEquals(calendarId, importedCalendar.getCalendarId());
Assert.assertEquals(type, importedCalendar.getType());
Assert.assertEquals(url, importedCalendar.getUrl());
}
use of org.olat.commons.calendar.model.ImportedCalendar in project openolat by klemens.
the class OLATUpgrade_10_4_0 method processImportedCalendars.
private void processImportedCalendars(Property property) {
Identity identity = property.getIdentity();
String calendarPartialId = property.getName();
String calendarId = identity.getName() + "_" + calendarPartialId;
String url = property.getStringValue();
List<ImportedCalendar> currentCalendars = importedCalendarDao.getImportedCalendar(identity, calendarId, CalendarManager.TYPE_USER);
if (currentCalendars.isEmpty()) {
Date importDate;
if (property.getLongValue() != null) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(property.getLongValue().longValue());
importDate = calendar.getTime();
} else {
importDate = new Date();
}
importedCalendarDao.createImportedCalendar(identity, calendarPartialId, calendarId, CalendarManager.TYPE_USER, url, importDate);
}
}
use of org.olat.commons.calendar.model.ImportedCalendar in project openolat by klemens.
the class ImportCalendarManager method getImportedCalendarsForIdentity.
/**
* Get imported calendars for a user.
* @param ureq
* @return
*/
public List<KalendarRenderWrapper> getImportedCalendarsForIdentity(Identity identity, boolean reload) {
// initialize the calendars list
List<KalendarRenderWrapper> calendars = new ArrayList<KalendarRenderWrapper>();
if (calendarModule.isEnabled() && calendarModule.isEnablePersonalCalendar()) {
long timestamp = System.currentTimeMillis();
List<ImportedCalendar> importedCalendars = importedCalendarDao.getImportedCalendars(identity);
KalendarEventFilter filter = new KalendarEventFilter(identity, importedCalendars);
for (ImportedCalendar importedCalendar : importedCalendars) {
try {
if (reload) {
reloadImportCalendar(importedCalendar, timestamp, filter);
}
String calendarId = importedCalendar.getCalendarId();
KalendarRenderWrapper calendarWrapper = calendarManager.getImportedCalendar(identity, calendarId);
calendarWrapper.setDisplayName(importedCalendar.getDisplayName());
calendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
calendarWrapper.setImported(true);
CalendarUserConfiguration config = calendarManager.findCalendarConfigForIdentity(calendarWrapper.getKalendar(), identity);
if (config != null) {
calendarWrapper.setConfiguration(config);
}
calendars.add(calendarWrapper);
} catch (Exception e) {
log.error("Cannot read an imported file", e);
}
}
Collections.sort(calendars, KalendarComparator.getInstance());
}
return calendars;
}
use of org.olat.commons.calendar.model.ImportedCalendar in project openolat by klemens.
the class ImportCalendarManager method getImportedCalendarInfosForIdentity.
public List<CalendarFileInfos> getImportedCalendarInfosForIdentity(Identity identity, boolean reload) {
List<CalendarFileInfos> calendars = new ArrayList<CalendarFileInfos>();
if (calendarModule.isEnabled() && calendarModule.isEnablePersonalCalendar()) {
long timestamp = System.currentTimeMillis();
List<ImportedCalendar> importedCalendars = importedCalendarDao.getImportedCalendars(identity);
KalendarEventFilter filter = new KalendarEventFilter(identity, importedCalendars);
for (ImportedCalendar importedCalendar : importedCalendars) {
if (reload) {
reloadImportCalendar(importedCalendar, timestamp, filter);
}
String calendarId = importedCalendar.getCalendarId();
File calendarFile = calendarManager.getCalendarFile(CalendarManager.TYPE_USER, calendarId);
CalendarFileInfos calendarInfos = new CalendarFileInfos(calendarId, CalendarManager.TYPE_USER, calendarFile);
calendars.add(calendarInfos);
}
}
return calendars;
}
use of org.olat.commons.calendar.model.ImportedCalendar in project OpenOLAT by OpenOLAT.
the class ImportedCalendarDAOTest method getImportedCalendars.
@Test
public void getImportedCalendars() {
Identity user = JunitTestHelper.createAndPersistIdentityAsRndUser("Imp-cal-4");
String calendarId = UUID.randomUUID().toString();
ImportedCalendar importedCalendar1 = importedCalendarDao.createImportedCalendar(user, "Imported calendar 3", calendarId, "rnd-3", null, new Date());
ImportedCalendar importedCalendar2 = importedCalendarDao.createImportedCalendar(user, "Imported calendar 4", UUID.randomUUID().toString(), "rnd-4", "http://www.openolat.org/calendar4.ics", new Date());
// noise
Identity noiseUser = JunitTestHelper.createAndPersistIdentityAsRndUser("Imp-cal-4");
ImportedCalendar noiseImportedCalendar = importedCalendarDao.createImportedCalendar(noiseUser, "Imported calendar 3", calendarId, "rnd-3", null, new Date());
dbInstance.commit();
List<ImportedCalendar> importedCalendars = importedCalendarDao.getImportedCalendars(user);
Assert.assertNotNull(importedCalendars);
Assert.assertEquals(2, importedCalendars.size());
Assert.assertTrue(importedCalendars.contains(importedCalendar1));
Assert.assertTrue(importedCalendars.contains(importedCalendar2));
Assert.assertFalse(importedCalendars.contains(noiseImportedCalendar));
}
Aggregations