Search in sources :

Example 1 with ImportedCalendar

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());
}
Also used : ImportedCalendar(org.olat.commons.calendar.model.ImportedCalendar) ImportedCalendar(org.olat.commons.calendar.model.ImportedCalendar) Calendar(java.util.Calendar) Identity(org.olat.core.id.Identity) Date(java.util.Date) Test(org.junit.Test)

Example 2 with ImportedCalendar

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());
}
Also used : ImportedCalendar(org.olat.commons.calendar.model.ImportedCalendar) Identity(org.olat.core.id.Identity) Date(java.util.Date) Test(org.junit.Test)

Example 3 with ImportedCalendar

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;
}
Also used : ImportedCalendar(org.olat.commons.calendar.model.ImportedCalendar) ArrayList(java.util.ArrayList) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) IOException(java.io.IOException)

Example 4 with ImportedCalendar

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;
}
Also used : ImportedCalendar(org.olat.commons.calendar.model.ImportedCalendar) CalendarFileInfos(org.olat.commons.calendar.model.CalendarFileInfos) ArrayList(java.util.ArrayList) File(java.io.File)

Example 5 with ImportedCalendar

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;
}
Also used : ImportedCalendar(org.olat.commons.calendar.model.ImportedCalendar) CalendarFileInfos(org.olat.commons.calendar.model.CalendarFileInfos) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

ImportedCalendar (org.olat.commons.calendar.model.ImportedCalendar)18 Date (java.util.Date)14 Identity (org.olat.core.id.Identity)12 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)4 Calendar (java.util.Calendar)4 File (java.io.File)2 IOException (java.io.IOException)2 CalendarFileInfos (org.olat.commons.calendar.model.CalendarFileInfos)2 CalendarUserConfiguration (org.olat.commons.calendar.model.CalendarUserConfiguration)2 ImportedToCalendar (org.olat.commons.calendar.model.ImportedToCalendar)2 KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)2