Search in sources :

Example 26 with KalendarRenderWrapper

use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project openolat by klemens.

the class ICalFileCalendarManager method getCalendarForDeletion.

@Override
public KalendarRenderWrapper getCalendarForDeletion(OLATResourceable resource) {
    String type;
    if ("CourseModule".equals(resource.getResourceableTypeName())) {
        type = CalendarManager.TYPE_COURSE;
    } else {
        type = CalendarManager.TYPE_GROUP;
    }
    Kalendar cal = getCalendar(type, resource.getResourceableId().toString());
    KalendarRenderWrapper calendarWrapper = new KalendarRenderWrapper(cal, "To delete");
    calendarWrapper.setCssClass(KalendarRenderWrapper.CALENDAR_COLOR_GREEN);
    calendarWrapper.setVisible(true);
    return calendarWrapper;
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Example 27 with KalendarRenderWrapper

use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project openolat by klemens.

the class ICalFileCalendarManager method getImportedCalendar.

@Override
public KalendarRenderWrapper getImportedCalendar(Identity identity, String calendarId) {
    Kalendar cal = getCalendar(CalendarManager.TYPE_USER, calendarId);
    KalendarRenderWrapper calendarWrapper = new KalendarRenderWrapper(cal, calendarId);
    calendarWrapper.setCssClass(KalendarRenderWrapper.CALENDAR_COLOR_BLUE);
    calendarWrapper.setVisible(true);
    calendarWrapper.setImported(true);
    return calendarWrapper;
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Example 28 with KalendarRenderWrapper

use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project openolat by klemens.

the class ImportCalendarManager method importCalendar.

public KalendarRenderWrapper importCalendar(Identity identity, String calendarName, String type, String url) throws IOException {
    File tmpFile = new File(WebappHelper.getTmpDir(), UUID.randomUUID() + ".ics");
    try (InputStream in = new URL(url).openStream()) {
        Files.copy(in, tmpFile.toPath());
    } catch (IOException e) {
        throw e;
    }
    KalendarRenderWrapper calendarWrapper = null;
    Calendar calendar = calendarManager.readCalendar(tmpFile);
    if (calendar != null) {
        String calendarID = getImportedCalendarID(identity, calendarName);
        File calendarFile = calendarManager.getCalendarFile(type, calendarID);
        if (!tmpFile.renameTo(calendarFile)) {
            Files.copy(tmpFile.toPath(), calendarFile.toPath());
        }
        importedCalendarDao.createImportedCalendar(identity, calendarName, calendarID, type, url, new Date());
        calendarWrapper = calendarManager.getImportedCalendar(identity, calendarID);
        calendarWrapper.setDisplayName(calendarName);
        calendarWrapper.setPrivateEventsVisible(true);
    }
    return calendarWrapper;
}
Also used : InputStream(java.io.InputStream) ImportedCalendar(org.olat.commons.calendar.model.ImportedCalendar) Calendar(net.fortuna.ical4j.model.Calendar) IOException(java.io.IOException) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) File(java.io.File) URL(java.net.URL) Date(java.util.Date)

Example 29 with KalendarRenderWrapper

use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project openolat by klemens.

the class ImportCalendarManager method importCalendar.

public KalendarRenderWrapper importCalendar(Identity identity, String calendarName, String type, File file) throws IOException {
    KalendarRenderWrapper calendarWrapper = null;
    Calendar calendar = calendarManager.readCalendar(file);
    if (calendar != null) {
        String calendarID = getImportedCalendarID(identity, calendarName);
        File calendarFile = calendarManager.getCalendarFile(type, calendarID);
        if (!file.renameTo(calendarFile)) {
            Files.copy(file.toPath(), calendarFile.toPath());
        }
        importedCalendarDao.createImportedCalendar(identity, calendarName, calendarID, type, null, new Date());
        calendarWrapper = calendarManager.getImportedCalendar(identity, calendarID);
        calendarWrapper.setDisplayName(calendarName);
        calendarWrapper.setPrivateEventsVisible(true);
    }
    return calendarWrapper;
}
Also used : ImportedCalendar(org.olat.commons.calendar.model.ImportedCalendar) Calendar(net.fortuna.ical4j.model.Calendar) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) File(java.io.File) Date(java.util.Date)

Example 30 with KalendarRenderWrapper

use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper 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)

Aggregations

KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)134 KalendarEvent (org.olat.commons.calendar.model.KalendarEvent)46 ArrayList (java.util.ArrayList)28 Test (org.junit.Test)28 Identity (org.olat.core.id.Identity)26 Date (java.util.Date)24 CalendarUserConfiguration (org.olat.commons.calendar.model.CalendarUserConfiguration)24 Calendar (java.util.Calendar)22 Kalendar (org.olat.commons.calendar.model.Kalendar)22 ICourse (org.olat.course.ICourse)20 File (java.io.File)18 BusinessGroup (org.olat.group.BusinessGroup)16 URI (java.net.URI)14 HttpResponse (org.apache.http.HttpResponse)14 CalendarImportTest (org.olat.commons.calendar.CalendarImportTest)14 URL (java.net.URL)12 EventVO (org.olat.commons.calendar.restapi.EventVO)12 CalendarManager (org.olat.commons.calendar.CalendarManager)10 HttpGet (org.apache.http.client.methods.HttpGet)8 UserRequest (org.olat.core.gui.UserRequest)8