use of org.olat.commons.calendar.model.ImportedCalendar in project OpenOLAT by OpenOLAT.
the class ImportedCalendarDAOTest method updateImportedCalendar.
@Test
public void updateImportedCalendar() {
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 up", calendarId, type, url, new Date());
Assert.assertNotNull(importedCalendar);
dbInstance.commit();
// update
importedCalendar.setDisplayName("Imported calendar updated");
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, 1);
importedCalendar.setLastUpdate(cal.getTime());
ImportedCalendar updatedCalendar = importedCalendarDao.update(importedCalendar);
dbInstance.commit();
// check
Assert.assertEquals(importedCalendar, updatedCalendar);
Assert.assertEquals(importedCalendar.getKey(), updatedCalendar.getKey());
Assert.assertTrue(new Date().before(updatedCalendar.getLastUpdate()));
Assert.assertEquals("Imported calendar updated", updatedCalendar.getDisplayName());
Assert.assertEquals(user, updatedCalendar.getIdentity());
Assert.assertEquals(calendarId, updatedCalendar.getCalendarId());
Assert.assertEquals(type, updatedCalendar.getType());
Assert.assertEquals(url, updatedCalendar.getUrl());
// reload and check
List<ImportedCalendar> reloadedCalendars = importedCalendarDao.getImportedCalendar(user, calendarId, type);
Assert.assertNotNull(reloadedCalendars);
Assert.assertEquals(1, reloadedCalendars.size());
Assert.assertTrue(reloadedCalendars.contains(importedCalendar));
// paranoia check
ImportedCalendar reloadedCalendar = reloadedCalendars.get(0);
Assert.assertNotNull(reloadedCalendar.getCreationDate());
Assert.assertNotNull(reloadedCalendar.getLastModified());
Assert.assertTrue(new Date().before(reloadedCalendar.getLastUpdate()));
Assert.assertEquals(importedCalendar.getKey(), reloadedCalendar.getKey());
Assert.assertEquals("Imported calendar updated", reloadedCalendar.getDisplayName());
Assert.assertEquals(user, reloadedCalendar.getIdentity());
Assert.assertEquals(calendarId, reloadedCalendar.getCalendarId());
Assert.assertEquals(type, reloadedCalendar.getType());
Assert.assertEquals(url, reloadedCalendar.getUrl());
}
use of org.olat.commons.calendar.model.ImportedCalendar in project OpenOLAT by OpenOLAT.
the class ImportedCalendarDAOTest method getImportedCalendar.
@Test
public void getImportedCalendar() {
Identity user = JunitTestHelper.createAndPersistIdentityAsRndUser("Imp-cal-2");
String calendarId = UUID.randomUUID().toString();
String type = "imported-test-2";
String url = "http://www.openolat.org/calendar1.ics";
ImportedCalendar importedCalendar = importedCalendarDao.createImportedCalendar(user, "Imported calendar 2", calendarId, type, url, new Date());
Assert.assertNotNull(importedCalendar);
dbInstance.commit();
List<ImportedCalendar> calendars = importedCalendarDao.getImportedCalendar(user, calendarId, type);
Assert.assertNotNull(calendars);
Assert.assertEquals(1, calendars.size());
Assert.assertTrue(calendars.contains(importedCalendar));
// paranoia check
ImportedCalendar reloadedCalendar = calendars.get(0);
Assert.assertNotNull(reloadedCalendar.getCreationDate());
Assert.assertNotNull(reloadedCalendar.getLastModified());
Assert.assertNotNull(reloadedCalendar.getLastUpdate());
Assert.assertEquals(importedCalendar.getKey(), reloadedCalendar.getKey());
Assert.assertEquals("Imported calendar 2", reloadedCalendar.getDisplayName());
Assert.assertEquals(user, reloadedCalendar.getIdentity());
Assert.assertEquals(calendarId, reloadedCalendar.getCalendarId());
Assert.assertEquals(type, reloadedCalendar.getType());
Assert.assertEquals(url, reloadedCalendar.getUrl());
}
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 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;
}
Aggregations