Search in sources :

Example 56 with Kalendar

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

the class CalendarEntryDetailsController method doSave.

private void doSave(UserRequest ureq) {
    // ok, save edited entry
    kalendarEvent = eventForm.getUpdatedKalendarEvent();
    if (isNew) {
        boolean doneSuccessfully = true;
        // this is a new event, add event to calendar
        String calendarID = eventForm.getChoosenKalendarID();
        for (Iterator<KalendarRenderWrapper> iter = availableCalendars.iterator(); iter.hasNext(); ) {
            KalendarRenderWrapper calendarWrapper = iter.next();
            if (!calendarWrapper.getKalendar().getCalendarID().equals(calendarID)) {
                continue;
            }
            Kalendar cal = calendarWrapper.getKalendar();
            boolean result = calendarManager.addEventTo(cal, kalendarEvent);
            if (result == false) {
                // if one failed => done not successfully
                doneSuccessfully = false;
            }
        }
        reportSaveStatus(ureq, doneSuccessfully);
    } else if (kalendarEvent instanceof KalendarRecurEvent && !StringHelper.containsNonWhitespace(kalendarEvent.getRecurrenceID())) {
        updateCtr = new ConfirmUpdateController(ureq, getWindowControl(), (KalendarRecurEvent) kalendarEvent);
        listenTo(updateCtr);
        String title = translate("cal.edit.update");
        cmc = new CloseableModalController(getWindowControl(), translate("close"), updateCtr.getInitialComponent(), true, title);
        listenTo(cmc);
        cmc.activate();
    } else {
        // this is an existing event, so we get the previousely assigned calendar from the event
        Kalendar cal = kalendarEvent.getCalendar();
        boolean doneSuccessfully = calendarManager.updateEventFrom(cal, kalendarEvent);
        reportSaveStatus(ureq, doneSuccessfully);
    }
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) KalendarRecurEvent(org.olat.commons.calendar.model.KalendarRecurEvent) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Example 57 with Kalendar

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

the class CalendarEntryDetailsController method event.

@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == deleteCtr) {
        if (event instanceof CalendarGUIDeleteEvent) {
            doDelete((CalendarGUIDeleteEvent) event);
            cmc.deactivate();
            cleanUp();
            fireEvent(ureq, Event.DONE_EVENT);
        } else {
            cmc.deactivate();
            cleanUp();
        }
    } else if (source == activeLinkProvider) {
        if (kalendarEvent.getCalendar() != null) {
            fireEvent(ureq, Event.DONE_EVENT);
        }
    } else if (source == eventForm) {
        if (event == Event.DONE_EVENT) {
            doSave(ureq);
        } else if ("delete".equals(event.getCommand())) {
            doConfirmDelete(ureq);
        } else if (event == Event.CANCELLED_EVENT) {
            eventForm.setEntry(kalendarEvent);
            // user canceled, finish workflow
            fireEvent(ureq, Event.DONE_EVENT);
        }
    } else if (source == updateCtr) {
        if (event instanceof CalendarGUIUpdateEvent) {
            doUpdate((CalendarGUIUpdateEvent) event);
            cmc.deactivate();
            cleanUp();
            fireEvent(ureq, Event.DONE_EVENT);
        } else {
            cmc.deactivate();
            cleanUp();
        }
    } else if (source == customMediaChooserCtr) {
        boolean doneSuccessfully = true;
        if (event instanceof URLChoosenEvent) {
            URLChoosenEvent urlEvent = (URLChoosenEvent) event;
            String url = urlEvent.getURL();
            List<KalendarEventLink> links = kalendarEvent.getKalendarEventLinks();
            String provider = customMediaChooserCtr.getClass().getSimpleName();
            String id = url;
            String displayName = StringHelper.containsNonWhitespace(urlEvent.getDisplayName()) ? urlEvent.getDisplayName() : url;
            String uri = url.contains("://") ? url : (Settings.getServerContextPathURI() + url);
            String iconCssClass = urlEvent.getIconCssClass();
            if (!StringHelper.containsNonWhitespace(iconCssClass)) {
                iconCssClass = CSSHelper.createFiletypeIconCssClassFor(url);
            }
            links.add(new KalendarEventLink(provider, id, displayName, uri, iconCssClass));
            Kalendar cal = kalendarEvent.getCalendar();
            doneSuccessfully = calendarManager.updateEventFrom(cal, kalendarEvent);
        }
        if (doneSuccessfully) {
            fireEvent(ureq, event);
        } else {
            showError("cal.error.save");
            fireEvent(ureq, Event.FAILED_EVENT);
        }
    } else if (source == externalLinksController || source == mediaLinksController) {
        // save externals links
        Kalendar cal = kalendarEvent.getCalendar();
        if (kalendarEvent.getCalendar() != null) {
            boolean doneSuccessfully = calendarManager.updateEventFrom(cal, kalendarEvent);
            if (doneSuccessfully) {
                fireEvent(ureq, Event.DONE_EVENT);
            } else {
                showError("cal.error.save");
                fireEvent(ureq, Event.FAILED_EVENT);
            }
        }
    } else if (cmc == source) {
        cleanUp();
    }
}
Also used : CalendarGUIDeleteEvent(org.olat.commons.calendar.ui.events.CalendarGUIDeleteEvent) Kalendar(org.olat.commons.calendar.model.Kalendar) CalendarGUIUpdateEvent(org.olat.commons.calendar.ui.events.CalendarGUIUpdateEvent) URLChoosenEvent(org.olat.core.commons.controllers.linkchooser.URLChoosenEvent) KalendarEventLink(org.olat.commons.calendar.model.KalendarEventLink)

Example 58 with Kalendar

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

the class CalendarPersonalConfigurationController method doDeleteCalendar.

private void doDeleteCalendar(UserRequest ureq, CalendarPersonalConfigurationRow row) {
    if (!row.isImported())
        return;
    Kalendar calendar = row.getWrapper().getKalendar();
    importCalendarManager.deleteCalendar(getIdentity(), calendar);
    List<CalendarPersonalConfigurationRow> currentRows = model.getObjects();
    currentRows.remove(row);
    model.setObjects(currentRows);
    tableEl.reloadData();
    fireEvent(ureq, new CalendarGUIRemoveEvent(row.getWrapper()));
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) CalendarGUIRemoveEvent(org.olat.commons.calendar.ui.events.CalendarGUIRemoveEvent)

Example 59 with Kalendar

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

the class CalendarNotificationHandler method createSubscriptionInfo.

@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
    SubscriptionInfo si = null;
    Publisher p = subscriber.getPublisher();
    Date latestNews = p.getLatestNewsDate();
    // can't be loaded when already deleted
    if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
        Long id = p.getResId();
        String type = p.getSubidentifier();
        try {
            Translator translator = Util.createPackageTranslator(CalendarModule.class, locale);
            String calType = null;
            String title = null;
            if (type.equals(CalendarController.ACTION_CALENDAR_COURSE)) {
                RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance("CourseModule", id), false);
                if (re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
                    return NotificationsManager.getInstance().getNoSubscriptionInfo();
                }
                String displayName = re.getDisplayname();
                calType = CalendarManager.TYPE_COURSE;
                title = translator.translate("cal.notifications.header.course", new String[] { displayName });
            } else if (type.equals(CalendarController.ACTION_CALENDAR_GROUP)) {
                BusinessGroup group = businessGroupDao.load(id);
                calType = CalendarManager.TYPE_GROUP;
                if (group == null) {
                    return notificationsManager.getNoSubscriptionInfo();
                }
                title = translator.translate("cal.notifications.header.group", new String[] { group.getName() });
            }
            if (calType != null) {
                Formatter form = Formatter.getInstance(locale);
                si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, CSS_CLASS_CALENDAR_ICON), null);
                String bPath;
                if (StringHelper.containsNonWhitespace(p.getBusinessPath())) {
                    bPath = p.getBusinessPath();
                } else if ("CalendarManager.course".equals(p.getResName())) {
                    try {
                        OLATResourceable ores = OresHelper.createOLATResourceableInstance(CourseModule.getCourseTypeName(), p.getResId());
                        RepositoryEntry re = repositoryManager.lookupRepositoryEntry(ores, true);
                        // Fallback
                        bPath = "[RepositoryEntry:" + re.getKey() + "]";
                    } catch (Exception e) {
                        log.error("Error processing calendar notifications of publisher:" + p.getKey(), e);
                        return notificationsManager.getNoSubscriptionInfo();
                    }
                } else {
                    // cannot make link without business path
                    return notificationsManager.getNoSubscriptionInfo();
                }
                Kalendar cal = calendarManager.getCalendar(calType, id.toString());
                Collection<KalendarEvent> calEvents = cal.getEvents();
                for (KalendarEvent kalendarEvent : calEvents) {
                    if (showEvent(compareDate, kalendarEvent)) {
                        log.debug("found a KalendarEvent: " + kalendarEvent.getSubject() + " with time: " + kalendarEvent.getBegin() + " modified before: " + compareDate.toString(), null);
                        // found a modified event in this calendar
                        Date modDate = null;
                        if (kalendarEvent.getLastModified() > 0) {
                            modDate = new Date(kalendarEvent.getLastModified());
                        } else if (kalendarEvent.getCreated() > 0) {
                            modDate = new Date(kalendarEvent.getCreated());
                        } else if (kalendarEvent.getBegin() != null) {
                            modDate = kalendarEvent.getBegin();
                        }
                        String subject = kalendarEvent.getSubject();
                        String author = kalendarEvent.getCreatedBy();
                        if (author == null)
                            author = "";
                        String location = "";
                        if (StringHelper.containsNonWhitespace(kalendarEvent.getLocation())) {
                            location = kalendarEvent.getLocation() == null ? "" : translator.translate("cal.notifications.location", new String[] { kalendarEvent.getLocation() });
                        }
                        String dateStr;
                        if (kalendarEvent.isAllDayEvent()) {
                            dateStr = form.formatDate(kalendarEvent.getBegin());
                        } else {
                            dateStr = form.formatDate(kalendarEvent.getBegin()) + " - " + form.formatDate(kalendarEvent.getEnd());
                        }
                        String desc = translator.translate("cal.notifications.entry", new String[] { subject, dateStr, location, author });
                        String businessPath = bPath + "[path=" + kalendarEvent.getID() + ":0]";
                        String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
                        SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, CSS_CLASS_CALENDAR_ICON);
                        si.addSubscriptionListItem(subListItem);
                    }
                }
            }
        } catch (Exception e) {
            log.error("Unexpected exception", e);
            checkPublisher(p);
            si = notificationsManager.getNoSubscriptionInfo();
        }
    } else {
        si = notificationsManager.getNoSubscriptionInfo();
    }
    return si;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) OLATResourceable(org.olat.core.id.OLATResourceable) Formatter(org.olat.core.util.Formatter) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) Publisher(org.olat.core.commons.services.notifications.Publisher) RepositoryEntry(org.olat.repository.RepositoryEntry) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem) Date(java.util.Date) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Kalendar(org.olat.commons.calendar.model.Kalendar) Translator(org.olat.core.gui.translator.Translator)

Example 60 with Kalendar

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

the class CopyEventToCalendarController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    for (MultipleSelectionElement copyEl : copyEls) {
        if (copyEl.isEnabled() && copyEl.isAtLeastSelected(1)) {
            KalendarRenderWrapper calendarWrapper = (KalendarRenderWrapper) copyEl.getUserObject();
            Kalendar cal = calendarWrapper.getKalendar();
            KalendarEvent clonedKalendarEvent = (KalendarEvent) XStreamHelper.xstreamClone(kalendarEvent);
            if (clonedKalendarEvent.getKalendarEventLinks().size() > 0) {
                clonedKalendarEvent.setKalendarEventLinks(new ArrayList<KalendarEventLink>());
            }
            calendarManager.addEventTo(cal, clonedKalendarEvent);
        }
    }
    fireEvent(ureq, Event.DONE_EVENT);
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) Kalendar(org.olat.commons.calendar.model.Kalendar) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) KalendarEventLink(org.olat.commons.calendar.model.KalendarEventLink) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Aggregations

Kalendar (org.olat.commons.calendar.model.Kalendar)126 KalendarEvent (org.olat.commons.calendar.model.KalendarEvent)68 Identity (org.olat.core.id.Identity)40 Date (java.util.Date)38 Test (org.junit.Test)26 CalendarManager (org.olat.commons.calendar.CalendarManager)24 KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)22 ArrayList (java.util.ArrayList)20 CalendarImportTest (org.olat.commons.calendar.CalendarImportTest)20 OLATResourceable (org.olat.core.id.OLATResourceable)20 CalendarGUIModifiedEvent (org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent)18 Calendar (java.util.Calendar)14 CalendarUserConfiguration (org.olat.commons.calendar.model.CalendarUserConfiguration)12 URISyntaxException (java.net.URISyntaxException)10 ParseException (java.text.ParseException)10 ExDate (net.fortuna.ical4j.model.property.ExDate)10 IOException (java.io.IOException)8 InputStream (java.io.InputStream)8 ICourse (org.olat.course.ICourse)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8