Search in sources :

Example 1 with ImportedToCalendar

use of org.olat.commons.calendar.model.ImportedToCalendar in project OpenOLAT by OpenOLAT.

the class ImportedToCalendarDAO method createImportedToCalendar.

public ImportedToCalendar createImportedToCalendar(String toCalendarId, String toType, String url, Date lastUpdate) {
    ImportedToCalendar calendar = new ImportedToCalendar();
    calendar.setCreationDate(new Date());
    calendar.setLastModified(calendar.getCreationDate());
    calendar.setLastUpdate(lastUpdate);
    calendar.setToCalendarId(toCalendarId);
    calendar.setToType(toType);
    calendar.setUrl(url);
    dbInstance.getCurrentEntityManager().persist(calendar);
    return calendar;
}
Also used : ImportedToCalendar(org.olat.commons.calendar.model.ImportedToCalendar) Date(java.util.Date)

Example 2 with ImportedToCalendar

use of org.olat.commons.calendar.model.ImportedToCalendar in project OpenOLAT by OpenOLAT.

the class ImportedToCalendarDAO method delete.

public void delete(ImportedToCalendar importedToCalendar) {
    ImportedToCalendar reloadedImportedToCalendar = dbInstance.getCurrentEntityManager().getReference(ImportedToCalendar.class, importedToCalendar.getKey());
    dbInstance.getCurrentEntityManager().remove(reloadedImportedToCalendar);
}
Also used : ImportedToCalendar(org.olat.commons.calendar.model.ImportedToCalendar)

Example 3 with ImportedToCalendar

use of org.olat.commons.calendar.model.ImportedToCalendar in project OpenOLAT by OpenOLAT.

the class OLATUpgrade_10_4_0 method processImportedCalendarsTo.

private void processImportedCalendarsTo(Property property) {
    // the calendar are imported in an existent calendar
    // urls are | separated
    String calendarId = property.getName();
    String type = property.getResourceTypeName();
    if ("user".equals(type)) {
        // don't convert this, they have there own synchronization mechanism
        return;
    }
    String importUrls = property.getTextValue();
    if (StringHelper.containsNonWhitespace(importUrls) && StringHelper.containsNonWhitespace(calendarId) && StringHelper.containsNonWhitespace(type)) {
        for (StringTokenizer tokenizer = new StringTokenizer(importUrls, "|"); tokenizer.hasMoreTokens(); ) {
            String importUrl = tokenizer.nextToken();
            List<ImportedToCalendar> currentCalendars = importedToCalendarDao.getImportedToCalendars(calendarId, type, importUrl);
            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();
                }
                importedToCalendarDao.createImportedToCalendar(calendarId, type, importUrl, importDate);
            }
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ImportedToCalendar(org.olat.commons.calendar.model.ImportedToCalendar) ImportedCalendar(org.olat.commons.calendar.model.ImportedCalendar) Calendar(java.util.Calendar) ImportedToCalendar(org.olat.commons.calendar.model.ImportedToCalendar) Date(java.util.Date)

Example 4 with ImportedToCalendar

use of org.olat.commons.calendar.model.ImportedToCalendar in project OpenOLAT by OpenOLAT.

the class ImportedToCalendarDAOTest method getImportedToCalendars_byCalendarIdTypeAndUrl.

@Test
public void getImportedToCalendars_byCalendarIdTypeAndUrl() {
    String toCalendarId = UUID.randomUUID().toString();
    String toType = "to-rnd-2";
    String url = "http://www.openolat.org/importedto/calendar2.ics";
    ImportedToCalendar importToCalendar = importedToCalendarDao.createImportedToCalendar(toCalendarId, toType, url, new Date());
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(importToCalendar);
    List<ImportedToCalendar> loadedToCalendars = importedToCalendarDao.getImportedToCalendars(toCalendarId, toType, url);
    Assert.assertNotNull(loadedToCalendars);
    Assert.assertEquals(1, loadedToCalendars.size());
    Assert.assertTrue(loadedToCalendars.contains(importToCalendar));
    // paranoia check
    ImportedToCalendar loadedToCalendar = loadedToCalendars.get(0);
    Assert.assertEquals(importToCalendar, loadedToCalendar);
    Assert.assertEquals(importToCalendar.getKey(), loadedToCalendar.getKey());
    Assert.assertNotNull(loadedToCalendar.getCreationDate());
    Assert.assertNotNull(loadedToCalendar.getLastModified());
    Assert.assertNotNull(loadedToCalendar.getLastUpdate());
    Assert.assertEquals(toCalendarId, loadedToCalendar.getToCalendarId());
    Assert.assertEquals(toType, loadedToCalendar.getToType());
    Assert.assertEquals(url, loadedToCalendar.getUrl());
}
Also used : ImportedToCalendar(org.olat.commons.calendar.model.ImportedToCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 5 with ImportedToCalendar

use of org.olat.commons.calendar.model.ImportedToCalendar in project openolat by klemens.

the class ImportedToCalendarDAOTest method getImportedToCalendars_byCalendarIdTypeAndUrl.

@Test
public void getImportedToCalendars_byCalendarIdTypeAndUrl() {
    String toCalendarId = UUID.randomUUID().toString();
    String toType = "to-rnd-2";
    String url = "http://www.openolat.org/importedto/calendar2.ics";
    ImportedToCalendar importToCalendar = importedToCalendarDao.createImportedToCalendar(toCalendarId, toType, url, new Date());
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(importToCalendar);
    List<ImportedToCalendar> loadedToCalendars = importedToCalendarDao.getImportedToCalendars(toCalendarId, toType, url);
    Assert.assertNotNull(loadedToCalendars);
    Assert.assertEquals(1, loadedToCalendars.size());
    Assert.assertTrue(loadedToCalendars.contains(importToCalendar));
    // paranoia check
    ImportedToCalendar loadedToCalendar = loadedToCalendars.get(0);
    Assert.assertEquals(importToCalendar, loadedToCalendar);
    Assert.assertEquals(importToCalendar.getKey(), loadedToCalendar.getKey());
    Assert.assertNotNull(loadedToCalendar.getCreationDate());
    Assert.assertNotNull(loadedToCalendar.getLastModified());
    Assert.assertNotNull(loadedToCalendar.getLastUpdate());
    Assert.assertEquals(toCalendarId, loadedToCalendar.getToCalendarId());
    Assert.assertEquals(toType, loadedToCalendar.getToType());
    Assert.assertEquals(url, loadedToCalendar.getUrl());
}
Also used : ImportedToCalendar(org.olat.commons.calendar.model.ImportedToCalendar) Date(java.util.Date) Test(org.junit.Test)

Aggregations

ImportedToCalendar (org.olat.commons.calendar.model.ImportedToCalendar)16 Date (java.util.Date)12 Test (org.junit.Test)6 InputStream (java.io.InputStream)4 URL (java.net.URL)4 Kalendar (org.olat.commons.calendar.model.Kalendar)4 Calendar (java.util.Calendar)2 StringTokenizer (java.util.StringTokenizer)2 ImportedCalendar (org.olat.commons.calendar.model.ImportedCalendar)2