Search in sources :

Example 56 with KalendarEvent

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

the class CalendarPrintMapper method renderEvent.

private void renderEvent(StringBuilder sb, KalendarEventRenderWrapper eventWrapper, Date dayStart, Date dayEnd) {
    KalendarEvent event = eventWrapper.getEvent();
    // check if event is private and user allowed to see it
    if (event.getClassification() == KalendarEvent.CLASS_PRIVATE && !eventWrapper.getKalendarRenderWrapper().isPrivateEventsVisible()) {
        return;
    }
    // Show all PUBLIC and FREEBUSY events
    String escapedSubject = Formatter.escWithBR(event.getSubject()).toString();
    escapedSubject = escapedSubject.replace('\r', ' ');
    sb.append("<li class=\"o_cal_event\">\n");
    sb.append("<div class=\"o_cal_class " + eventWrapper.getCssClass() + "\">&nbsp;</div>\n");
    // time
    sb.append("<div class=\"o_cal_time\"><span>\n");
    if (event.isAllDayEvent()) {
        sb.append(translator.translate("cal.form.allday"));
    } else {
        // set start and end times for events spanning more than one day
        Date begin = event.getBegin();
        Date end = event.getEnd();
        if (begin.before(dayStart)) {
            begin = dayStart;
        }
        if (end == null || end.after(dayEnd)) {
            end = dayEnd;
        }
        sb.append(StringHelper.formatLocaleTime(begin, translator.getLocale()));
        sb.append(" - ");
        sb.append(StringHelper.formatLocaleTime(end, translator.getLocale()));
    }
    sb.append("</span></div>\n");
    // and should not be applied to imported calendars)
    if (eventWrapper.getKalendarRenderWrapper().isPrivateEventsVisible() || event.getClassification() == KalendarEvent.CLASS_PUBLIC || eventWrapper.getKalendarRenderWrapper().isImported()) {
        // event name (subject)
        // firefox doesn't break lines with only <br />, we need <p>
        sb.append("<div class=\"o_cal_subject\"><p>");
        sb.append(escapedSubject.replace("<br />", "</p><p>"));
        sb.append("</p></div>\n");
        // location
        if (StringHelper.containsNonWhitespace(event.getLocation())) {
            sb.append("<div class=\"o_cal_location\"><span>\n<strong>");
            sb.append(translator.translate("cal.form.location") + "</strong>: ");
            sb.append(StringHelper.escapeHtml(event.getLocation()));
            sb.append("</span></div>\n");
        }
        // description
        if (StringHelper.containsNonWhitespace(event.getDescription())) {
            sb.append("<div class=\"o_cal_description\"><span>\n<strong>");
            sb.append(translator.translate("cal.form.description") + "</strong>: ");
            sb.append(StringHelper.escapeHtml(event.getDescription()));
            sb.append("</span></div>\n");
        }
    } else {
        // for free-busy events where user has not the right to see the private stuff
        // show only a message
        sb.append("<div class=\"o_cal_freebusy\"><p>");
        sb.append(translator.translate("cal.form.subject.hidden"));
        sb.append("</p></div>\n");
    }
    sb.append("</li>\n");
}
Also used : KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Date(java.util.Date)

Example 57 with KalendarEvent

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

the class UserCalendarWebService method getEvents.

@GET
@Path("events")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getEvents(@PathParam("identityKey") Long identityKey, @QueryParam("start") @DefaultValue("0") Integer start, @QueryParam("limit") @DefaultValue("25") Integer limit, @QueryParam("onlyFuture") @DefaultValue("false") Boolean onlyFuture, @Context HttpServletRequest httpRequest, @Context Request request) {
    UserRequest ureq = getUserRequest(httpRequest);
    if (ureq.getIdentity() == null || !ureq.getUserSession().isAuthenticated()) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    } else if (!ureq.getIdentity().getKey().equals(identityKey) && !isAdmin(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    CollectCalendars visitor = new CollectCalendars();
    getCalendars(visitor, ureq);
    List<KalendarRenderWrapper> wrappers = visitor.getWrappers();
    List<EventVO> events = new ArrayList<>();
    for (KalendarRenderWrapper wrapper : wrappers) {
        Collection<KalendarEvent> kalEvents = wrapper.getKalendar().getEvents();
        for (KalendarEvent kalEvent : kalEvents) {
            EventVO eventVo = new EventVO(kalEvent);
            events.add(eventVo);
        }
    }
    return processEvents(events, onlyFuture, start, limit, httpRequest, request);
}
Also used : ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 58 with KalendarEvent

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

the class FullCalendarElement method doSelect.

private void doSelect(UserRequest ureq, String eventId, String targetDomId) {
    KalendarEvent event = component.getCalendarEvent(eventId);
    if (component.isOccurenceOfCalendarEvent(eventId)) {
        String uid = component.getCalendarEventUid(eventId);
        KalendarRenderWrapper cal = component.getCalendarById(uid);
        KalendarRecurEvent recurEvent = getCurrenceKalendarEvent(cal, eventId);
        getRootForm().fireFormEvent(ureq, new CalendarGUISelectEvent(this, recurEvent, cal, targetDomId));
    } else if (component.isReccurenceOfCalendarEvent(eventId)) {
        String uid = component.getCalendarEventUid(eventId);
        KalendarRenderWrapper cal = component.getCalendarById(uid);
        KalendarRecurEvent recurEvent = getCurrenceKalendarEvent(cal, eventId);
        getRootForm().fireFormEvent(ureq, new CalendarGUISelectEvent(this, recurEvent, cal, targetDomId));
    } else {
        KalendarRenderWrapper calWrapper = component.getCalendarByNormalizedId(eventId);
        getRootForm().fireFormEvent(ureq, new CalendarGUISelectEvent(this, event, calWrapper, targetDomId));
    }
}
Also used : KalendarRecurEvent(org.olat.commons.calendar.model.KalendarRecurEvent) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) CalendarGUISelectEvent(org.olat.commons.calendar.ui.events.CalendarGUISelectEvent)

Example 59 with KalendarEvent

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

the class FullCalendarElement method getCurrenceKalendarEvent.

private KalendarRecurEvent getCurrenceKalendarEvent(KalendarRenderWrapper cal, String eventId) {
    boolean privateEventsVisible = cal.isPrivateEventsVisible();
    CalendarManager calendarManager = CoreSpringFactory.getImpl(CalendarManager.class);
    Date currentDate = component.getCurrentDate();
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(currentDate);
    calendar.add(Calendar.MONTH, -2);
    Date from = calendar.getTime();
    calendar.add(Calendar.MONTH, +4);
    Date to = calendar.getTime();
    List<KalendarEvent> events = calendarManager.getEvents(cal.getKalendar(), from, to, privateEventsVisible);
    for (KalendarEvent event : events) {
        if (event instanceof KalendarRecurEvent) {
            KalendarRecurEvent kEvent = (KalendarRecurEvent) event;
            if (eventId.equals(FullCalendarComponent.normalizeId(event))) {
                return kEvent;
            }
        }
    }
    return null;
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) KalendarRecurEvent(org.olat.commons.calendar.model.KalendarRecurEvent) Calendar(java.util.Calendar) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Date(java.util.Date)

Example 60 with KalendarEvent

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

the class ICalFileCalendarManager method removeFutureOfEvent.

@Override
public boolean removeFutureOfEvent(Kalendar cal, KalendarRecurEvent kalendarEvent) {
    OLATResourceable calOres = getOresHelperFor(cal);
    Boolean removeSuccessful = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calOres, new SyncerCallback<Boolean>() {

        @Override
        public Boolean execute() {
            boolean successfullyPersist = false;
            try {
                String uid = kalendarEvent.getID();
                Date occurenceDate = kalendarEvent.getOccurenceDate();
                Kalendar loadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
                KalendarEvent rootEvent = loadedCal.getEvent(kalendarEvent.getID(), null);
                String rRule = rootEvent.getRecurrenceRule();
                Recur recur = new Recur(rRule);
                recur.setUntil(CalendarUtils.createDate(occurenceDate));
                RRule rrule = new RRule(recur);
                rootEvent.setRecurrenceRule(rrule.getValue());
                for (KalendarEvent kEvent : loadedCal.getEvents()) {
                    if (uid.equals(kEvent.getID()) && StringHelper.containsNonWhitespace(kEvent.getRecurrenceID()) && occurenceDate.before(kEvent.getBegin())) {
                        loadedCal.removeEvent(kEvent);
                    }
                }
                successfullyPersist = persistCalendar(loadedCal);
            } catch (ParseException e) {
                log.error("", e);
            }
            return new Boolean(successfullyPersist);
        }
    });
    // inform all controller about calendar change for reload
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(cal), OresHelper.lookupType(CalendarManager.class));
    return removeSuccessful.booleanValue();
}
Also used : RRule(net.fortuna.ical4j.model.property.RRule) OLATResourceable(org.olat.core.id.OLATResourceable) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Date(java.util.Date) ExDate(net.fortuna.ical4j.model.property.ExDate) CalendarManager(org.olat.commons.calendar.CalendarManager) Kalendar(org.olat.commons.calendar.model.Kalendar) ParseException(java.text.ParseException) CalendarGUIModifiedEvent(org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent) Recur(net.fortuna.ical4j.model.Recur)

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