use of org.olat.commons.calendar.model.ImportedCalendar in project OpenOLAT by OpenOLAT.
the class ImportedCalendarDAOTest method deleteImportedCalendar.
@Test
public void deleteImportedCalendar() {
Identity user = JunitTestHelper.createAndPersistIdentityAsRndUser("Imp-cal-5");
String calendarId = UUID.randomUUID().toString();
ImportedCalendar importedCalendar1 = importedCalendarDao.createImportedCalendar(user, "Imported calendar 5", calendarId, "rnd-3", null, new Date());
ImportedCalendar importedCalendar2 = importedCalendarDao.createImportedCalendar(user, "Imported calendar 6", UUID.randomUUID().toString(), "rnd-4", "http://www.openolat.org/calendar5.ics", new Date());
// noise
Identity noiseUser = JunitTestHelper.createAndPersistIdentityAsRndUser("Imp-cal-6");
ImportedCalendar noiseImportedCalendar = importedCalendarDao.createImportedCalendar(noiseUser, "Imported calendar 7", calendarId, "rnd-3", null, new Date());
dbInstance.commit();
// check
List<ImportedCalendar> importedCalendars = importedCalendarDao.getImportedCalendars(user);
Assert.assertEquals(2, importedCalendars.size());
List<ImportedCalendar> noiseImportedCalendars = importedCalendarDao.getImportedCalendars(noiseUser);
Assert.assertEquals(1, noiseImportedCalendars.size());
// delete
importedCalendarDao.deleteImportedCalendar(user, calendarId, "rnd-3");
dbInstance.commitAndCloseSession();
// check the the first imported calendar is really deleted
List<ImportedCalendar> reloadedCalendars = importedCalendarDao.getImportedCalendars(user);
Assert.assertEquals(1, reloadedCalendars.size());
Assert.assertFalse(reloadedCalendars.contains(importedCalendar1));
Assert.assertTrue(reloadedCalendars.contains(importedCalendar2));
Assert.assertFalse(reloadedCalendars.contains(noiseImportedCalendar));
// noise must still have its calendar
List<ImportedCalendar> noiseReloadedCalendars = importedCalendarDao.getImportedCalendars(noiseUser);
Assert.assertEquals(1, noiseReloadedCalendars.size());
Assert.assertFalse(noiseReloadedCalendars.contains(importedCalendar1));
Assert.assertFalse(noiseReloadedCalendars.contains(importedCalendar2));
Assert.assertTrue(noiseReloadedCalendars.contains(noiseImportedCalendar));
}
use of org.olat.commons.calendar.model.ImportedCalendar in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
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 OpenOLAT.
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 OpenOLAT.
the class ImportedCalendarDAO method createImportedCalendar.
public ImportedCalendar createImportedCalendar(Identity owner, String displayName, String calendarId, String type, String url, Date lastUpdate) {
ImportedCalendar calendar = new ImportedCalendar();
calendar.setCreationDate(new Date());
calendar.setLastModified(calendar.getCreationDate());
calendar.setLastUpdate(lastUpdate);
calendar.setDisplayName(displayName);
calendar.setCalendarId(calendarId);
calendar.setType(type);
calendar.setUrl(url);
calendar.setIdentity(owner);
dbInstance.getCurrentEntityManager().persist(calendar);
return calendar;
}
Aggregations