Search in sources :

Example 51 with KalendarEvent

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

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 52 with KalendarEvent

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

the class CalWebService method deleteEventByCalendar.

@DELETE
@Path("events/{eventId}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_FORM_URLENCODED, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response deleteEventByCalendar(@PathParam("eventId") String eventId, @Context HttpServletRequest httpRequest) {
    UserRequest ureq = getUserRequest(httpRequest);
    if (!ureq.getUserSession().isAuthenticated()) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    if (calendar == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    } else if (!hasWriteAccess(calendar)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    CalendarManager calendarManager = CoreSpringFactory.getImpl(CalendarManager.class);
    if (eventId == null) {
        return Response.ok().status(Status.NOT_FOUND).build();
    } else {
        KalendarEvent kalEvent = calendar.getKalendar().getEvent(eventId, null);
        if (kalEvent == null) {
            return Response.ok().status(Status.NOT_FOUND).build();
        } else {
            calendarManager.removeEventFrom(calendar.getKalendar(), kalEvent);
        }
    }
    return Response.ok().build();
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 53 with KalendarEvent

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

the class WeeklyCalendarController method pushAddEventController.

private void pushAddEventController(CalendarGUIAddEvent addEvent, UserRequest ureq) {
    if (editController != null || ureq.getUserSession().getRoles().isGuestOnly()) {
        return;
    }
    removeAsListenerAndDispose(cmc);
    removeAsListenerAndDispose(editController);
    KalendarRenderWrapper calendarWrapper = calendarEl.getCalendar(addEvent.getCalendarID());
    List<KalendarRenderWrapper> copyCalendarWrappers = new ArrayList<>(calendarWrappers);
    boolean isReadOnly = calendarWrapper == null ? true : calendarWrapper.getAccess() == KalendarRenderWrapper.ACCESS_READ_ONLY;
    for (KalendarRenderWrapper copyCalendarWrapper : copyCalendarWrappers) {
        isReadOnly &= copyCalendarWrapper.getAccess() == KalendarRenderWrapper.ACCESS_READ_ONLY;
    }
    if (!isReadOnly) {
        // create new KalendarEvent
        KalendarEvent newEvent;
        Date begin = addEvent.getStartDate();
        String eventId = CodeHelper.getGlobalForeverUniqueID();
        if (addEvent.getEndDate() == null) {
            newEvent = new KalendarEvent(eventId, "", begin, (1000 * 60 * 60 * 1));
        } else {
            newEvent = new KalendarEvent(eventId, null, "", begin, addEvent.getEndDate());
        }
        if (calendarWrapper != null && (calendarWrapper.getKalendar().getType().equals(CalendarManager.TYPE_COURSE) || calendarWrapper.getKalendar().getType().equals(CalendarManager.TYPE_GROUP))) {
            newEvent.setClassification(KalendarEvent.CLASS_PUBLIC);
        }
        newEvent.setAllDayEvent(addEvent.isAllDayEvent());
        String lastName = ureq.getIdentity().getUser().getProperty(UserConstants.LASTNAME, getLocale());
        String firstName = ureq.getIdentity().getUser().getProperty(UserConstants.FIRSTNAME, getLocale());
        newEvent.setCreatedBy(firstName + " " + lastName);
        newEvent.setCreated(new Date().getTime());
        editController = new CalendarEntryDetailsController(ureq, newEvent, calendarWrapper, copyCalendarWrappers, true, caller, getWindowControl());
        listenTo(editController);
        cmc = new CloseableModalController(getWindowControl(), translate("close"), editController.getInitialComponent());
        listenTo(cmc);
        cmc.activate();
        // set logging action
        setCalLoggingAction(CalendarLoggingAction.CALENDAR_ENTRY_CREATED);
    }
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) Date(java.util.Date)

Example 54 with KalendarEvent

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

the class WeeklyCalendarController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (source == calendarEl) {
        if (event instanceof CalendarGUIEditEvent) {
            CalendarGUIEditEvent guiEvent = (CalendarGUIEditEvent) event;
            KalendarEvent kalendarEvent = guiEvent.getKalendarEvent();
            if (kalendarEvent == null) {
                // event already deleted
                getWindowControl().setError(translate("cal.error.eventDeleted"));
                return;
            }
            String recurrence = kalendarEvent.getRecurrenceRule();
            boolean isImported = false;
            KalendarRenderWrapper kalendarRenderWrapper = guiEvent.getKalendarRenderWrapper();
            if (kalendarRenderWrapper != null) {
                isImported = kalendarRenderWrapper.isImported();
            }
            if (!isImported && recurrence != null && !recurrence.equals("")) {
                List<String> btnLabels = new ArrayList<>(3);
                btnLabels.add(translate("cal.edit.dialog.sequence"));
                btnLabels.add(translate("cal.edit.dialog.delete.single"));
                btnLabels.add(translate("cal.edit.dialog.delete.sequence"));
                if (dbcSequence != null) {
                    dbcSequence.dispose();
                }
                dbcSequence = DialogBoxUIFactory.createGenericDialog(ureq, getWindowControl(), translate("cal.edit.dialog.title"), translate("cal.edit.dialog.text"), btnLabels);
                dbcSequence.addControllerListener(this);
                dbcSequence.setUserObject(guiEvent);
                dbcSequence.activate();
                return;
            }
            KalendarRenderWrapper kalendarWrapper = guiEvent.getKalendarRenderWrapper();
            pushEditEventController(ureq, kalendarEvent, kalendarWrapper);
        } else if (event instanceof CalendarGUIAddEvent) {
            pushAddEventController((CalendarGUIAddEvent) event, ureq);
        } else if (event instanceof CalendarGUISelectEvent) {
            CalendarGUISelectEvent selectEvent = (CalendarGUISelectEvent) event;
            if (selectEvent.getKalendarEvent() != null) {
                doOpenEventCallout(ureq, selectEvent.getKalendarEvent(), selectEvent.getKalendarRenderWrapper(), selectEvent.getTargetDomId());
            }
        } else if (event instanceof CalendarGUIMoveEvent) {
            CalendarGUIMoveEvent moveEvent = (CalendarGUIMoveEvent) event;
            doMove(ureq, moveEvent.getKalendarEvent(), moveEvent.getDayDelta(), moveEvent.getMinuteDelta(), moveEvent.getAllDay());
        } else if (event instanceof CalendarGUIResizeEvent) {
            CalendarGUIResizeEvent resizeEvent = (CalendarGUIResizeEvent) event;
            doResize(ureq, resizeEvent.getKalendarEvent(), resizeEvent.getMinuteDelta(), resizeEvent.getAllDay());
        } else if (event instanceof CalendarGUIFormEvent) {
            String cmd = event.getCommand();
            if (CalendarGUIFormEvent.CONFIGURE.equals(cmd)) {
                doConfigure(ureq);
            } else if (CalendarGUIFormEvent.AGGREGATED_FEED.equals(cmd)) {
                CalendarGUIFormEvent guiEvent = (CalendarGUIFormEvent) event;
                doOpenAggregatedFeedUrl(ureq, guiEvent.getTargetDomId());
            }
        } else if (event instanceof CalendarGUIPrintEvent) {
            CalendarGUIPrintEvent printEvent = (CalendarGUIPrintEvent) event;
            if (printEvent.getFrom() != null && printEvent.getTo() != null) {
                doPrint(printEvent.getFrom(), printEvent.getTo());
            } else if (printEvent.getTargetDomId() != null) {
                doPrintEventCallout(ureq, printEvent.getTargetDomId());
            }
        }
    }
    super.formInnerEvent(ureq, source, event);
}
Also used : CalendarGUIAddEvent(org.olat.commons.calendar.ui.events.CalendarGUIAddEvent) CalendarGUIEditEvent(org.olat.commons.calendar.ui.events.CalendarGUIEditEvent) CalendarGUIResizeEvent(org.olat.commons.calendar.ui.events.CalendarGUIResizeEvent) ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) CalendarGUIMoveEvent(org.olat.commons.calendar.ui.events.CalendarGUIMoveEvent) CalendarGUIPrintEvent(org.olat.commons.calendar.ui.events.CalendarGUIPrintEvent) CalendarGUISelectEvent(org.olat.commons.calendar.ui.events.CalendarGUISelectEvent) CalendarGUIFormEvent(org.olat.commons.calendar.ui.events.CalendarGUIFormEvent)

Example 55 with KalendarEvent

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

the class WeeklyCalendarController method event.

@Override
public void event(UserRequest ureq, Controller source, Event event) {
    Kalendar affectedCal = null;
    if (dirty) {
        dirty = false;
        fireEvent(ureq, new CalendarGUIModifiedEvent());
    }
    if (source == editController) {
        affectedCal = editController.getKalendarEvent().getCalendar();
        cmc.deactivate();
        calendarEl.getComponent().setDirty(true);
        // do logging if affectedCal not null
        if (affectedCal != null) {
            ThreadLocalUserActivityLogger.log(getCalLoggingAction(), getClass(), LoggingResourceable.wrap(ureq.getIdentity()), LoggingResourceable.wrap(affectedCal));
        }
        cleanUp();
    } else if (source == eventDetailsCtr) {
        if (event instanceof CalendarGUIEditEvent) {
            eventCalloutCtr.deactivate();
            cleanUp();
            CalendarGUIEditEvent editEvent = (CalendarGUIEditEvent) event;
            pushEditEventController(ureq, editEvent.getKalendarEvent(), editEvent.getKalendarRenderWrapper());
        } else if (event == Event.DONE_EVENT) {
            eventCalloutCtr.deactivate();
            cleanUp();
        }
    } else if (source == updateCtr) {
        if (event instanceof CalendarGUIUpdateEvent) {
            doUpdate((CalendarGUIUpdateEvent) event, updateCtr.getKalendarEvent(), updateCtr.getDayDelta(), updateCtr.getMinuteDelta(), updateCtr.getAllDay(), updateCtr.getChangeBegin());
        }
        cmc.deactivate();
        cleanUp();
    } else if (source == printCtrl) {
        if (event instanceof CalendarGUIPrintEvent) {
            CalendarGUIPrintEvent printEvent = (CalendarGUIPrintEvent) event;
            if (printEvent.getFrom() != null && printEvent.getTo() != null) {
                doPrint(printEvent.getFrom(), printEvent.getTo());
            }
        }
        eventCalloutCtr.deactivate();
        cleanUp();
    } else if (source == cmc) {
        calendarEl.getComponent().setDirty(true);
        cleanUp();
    } else if (source == dbcSequence) {
        if (event != Event.CANCELLED_EVENT) {
            int pos = DialogBoxUIFactory.getButtonPos(event);
            CalendarGUIEditEvent guiEvent = (CalendarGUIEditEvent) dbcSequence.getUserObject();
            KalendarRenderWrapper kalendarWrapper = guiEvent.getKalendarRenderWrapper();
            KalendarEvent kalendarEvent = guiEvent.getKalendarEvent();
            if (pos == 0) {
                // edit the sequence
                // load the parent event of this sequence
                KalendarEvent parentEvent = kalendarWrapper.getKalendar().getEvent(kalendarEvent.getID(), kalendarEvent.getRecurrenceID());
                pushEditEventController(ureq, parentEvent, kalendarWrapper);
            } else if (pos == 1) {
                // delete a single event of the sequence
                deleteSingleYesNoController = activateYesNoDialog(ureq, null, translate("cal.delete.dialogtext"), deleteSingleYesNoController);
                deleteSingleYesNoController.setUserObject(kalendarEvent);
            } else if (pos == 2) {
                // delete the whole sequence
                deleteSequenceYesNoController = activateYesNoDialog(ureq, null, translate("cal.delete.dialogtext.sequence"), deleteSequenceYesNoController);
                deleteSequenceYesNoController.setUserObject(kalendarEvent);
            }
        }
        dbcSequence.dispose();
    } else if (source == deleteSingleYesNoController) {
        if (DialogBoxUIFactory.isYesEvent(event)) {
            KalendarEvent kalendarEvent = (KalendarEvent) deleteSingleYesNoController.getUserObject();
            affectedCal = kalendarEvent.getCalendar();
            KalendarEvent kEvent = affectedCal.getEvent(kalendarEvent.getID(), kalendarEvent.getRecurrenceID());
            kEvent.addRecurrenceExc(kalendarEvent.getBegin());
            calendarManager.updateEventFrom(affectedCal, kEvent);
            deleteSingleYesNoController.dispose();
            calendarEl.getComponent().setDirty(true);
        }
    } else if (source == deleteSequenceYesNoController) {
        if (DialogBoxUIFactory.isYesEvent(event)) {
            KalendarEvent kalendarEvent = (KalendarEvent) deleteSequenceYesNoController.getUserObject();
            affectedCal = kalendarEvent.getCalendar();
            calendarManager.removeEventFrom(affectedCal, kalendarEvent);
            deleteSequenceYesNoController.dispose();
            calendarEl.getComponent().setDirty(true);
        }
    } else if (configurationCtrl == source) {
        if (event instanceof CalendarGUIImportEvent) {
            CalendarGUIImportEvent importEvent = (CalendarGUIImportEvent) event;
            calendarWrappers.add(importEvent.getCalendar());
            calendarEl.setCalendars(calendarWrappers);
        } else if (event instanceof CalendarGUIRemoveEvent) {
            CalendarGUIRemoveEvent removeEvent = (CalendarGUIRemoveEvent) event;
            calendarWrappers.remove(removeEvent.getCalendar());
            calendarEl.setCalendars(calendarWrappers);
        } else if (event instanceof CalendarGUISettingEvent) {
            calendarEl.setCalendars(calendarWrappers);
        }
    } else if (eventCalloutCtr == source) {
        cleanUp();
    } else if (eventDetailsCtr == source) {
    }
    if (calendarEl.getComponent().isDirty()) {
        if (subsContext != null) {
            // group or course calendar -> prepared subscription context is the right one
            NotificationsManager.getInstance().markPublisherNews(subsContext, ureq.getIdentity(), true);
        } else if (caller.equals(CALLER_HOME) && affectedCal != null) {
            // one can add/edit/remove dates of group and course calendars from the home calendar view -> choose right subscription context
            for (KalendarRenderWrapper calWrapper : calendarWrappers) {
                if (affectedCal == calWrapper.getKalendar()) {
                    SubscriptionContext tmpSubsContext = calendarNotificationsManager.getSubscriptionContext(calWrapper);
                    NotificationsManager.getInstance().markPublisherNews(tmpSubsContext, ureq.getIdentity(), true);
                }
            }
        }
    }
}
Also used : CalendarGUIEditEvent(org.olat.commons.calendar.ui.events.CalendarGUIEditEvent) Kalendar(org.olat.commons.calendar.model.Kalendar) CalendarGUIPrintEvent(org.olat.commons.calendar.ui.events.CalendarGUIPrintEvent) CalendarGUISettingEvent(org.olat.commons.calendar.ui.events.CalendarGUISettingEvent) CalendarGUIUpdateEvent(org.olat.commons.calendar.ui.events.CalendarGUIUpdateEvent) CalendarGUIImportEvent(org.olat.commons.calendar.ui.events.CalendarGUIImportEvent) CalendarGUIRemoveEvent(org.olat.commons.calendar.ui.events.CalendarGUIRemoveEvent) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) CalendarGUIModifiedEvent(org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent)

Aggregations

KalendarEvent (org.olat.commons.calendar.model.KalendarEvent)172 Date (java.util.Date)80 Kalendar (org.olat.commons.calendar.model.Kalendar)68 Test (org.junit.Test)48 KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)46 Identity (org.olat.core.id.Identity)46 ArrayList (java.util.ArrayList)42 Calendar (java.util.Calendar)40 CalendarImportTest (org.olat.commons.calendar.CalendarImportTest)34 CalendarManager (org.olat.commons.calendar.CalendarManager)32 OLATResourceable (org.olat.core.id.OLATResourceable)20 CalendarGUIModifiedEvent (org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent)18 File (java.io.File)16 ExDate (net.fortuna.ical4j.model.property.ExDate)16 ICourse (org.olat.course.ICourse)16 URI (java.net.URI)14 HttpResponse (org.apache.http.HttpResponse)14 URL (java.net.URL)12 KalendarRecurEvent (org.olat.commons.calendar.model.KalendarRecurEvent)12 EventVO (org.olat.commons.calendar.restapi.EventVO)12