use of org.olat.commons.calendar.model.KalendarEvent in project openolat by klemens.
the class ICalFileCalendarManager method getEvents.
@Override
public List<KalendarEvent> getEvents(Kalendar calendar, Date from, Date to, boolean privateEventsVisible) {
List<KalendarEvent> allEvents = calendar.getEvents();
List<KalendarEvent> events = new ArrayList<>(128);
Map<String, List<KalendarRecurEvent>> idToRecurringEvents = new HashMap<>();
// first pass, ignore events with recurrenceId
for (KalendarEvent event : allEvents) {
if (!privateEventsVisible && event.getClassification() == KalendarEvent.CLASS_PRIVATE) {
continue;
}
if (StringHelper.containsNonWhitespace(event.getRecurrenceID())) {
continue;
}
if (StringHelper.containsNonWhitespace(event.getRecurrenceRule())) {
List<KalendarRecurEvent> recurringEvents = getRecurringEventsInPeriod(event, from, to, tz);
if (recurringEvents.size() > 0) {
idToRecurringEvents.put(event.getID(), recurringEvents);
for (KalendarRecurEvent recurEvent : recurringEvents) {
events.add(recurEvent);
}
}
} else if (isInRange(from, to, event)) {
events.add(event);
}
}
// process events with recurrenceId
for (KalendarEvent event : allEvents) {
if (!StringHelper.containsNonWhitespace(event.getRecurrenceID())) {
continue;
}
String id = event.getID();
if (idToRecurringEvents.containsKey(id)) {
VEvent vEvent = getVEvent(event);
RecurrenceId recurrenceId = vEvent.getRecurrenceId();
net.fortuna.ical4j.model.Date startDate = recurrenceId.getDate();
if (startDate instanceof net.fortuna.ical4j.model.DateTime) {
List<KalendarRecurEvent> recurringEvents = idToRecurringEvents.get(id);
for (KalendarRecurEvent recurEvent : recurringEvents) {
Date beginDate = recurEvent.getBegin();
if (beginDate.equals(startDate)) {
recurEvent.setRecurrenceEvent(event);
}
}
} else {
List<KalendarRecurEvent> recurringEvents = idToRecurringEvents.get(id);
for (KalendarRecurEvent recurEvent : recurringEvents) {
Date beginDate = recurEvent.getBegin();
net.fortuna.ical4j.model.Date occDate = CalendarUtils.createDate(beginDate);
if (occDate.equals(startDate)) {
recurEvent.setRecurrenceEvent(event);
}
}
}
}
}
return events;
}
use of org.olat.commons.calendar.model.KalendarEvent in project openolat by klemens.
the class ICalFileCalendarManager method createKalendarEventRecurringOccurence.
@Override
public KalendarEvent createKalendarEventRecurringOccurence(KalendarRecurEvent recurEvent) {
KalendarEvent rootEvent = recurEvent.getCalendar().getEvent(recurEvent.getID(), null);
VEvent vEvent = getVEvent(recurEvent);
PropertyList vEventProperties = vEvent.getProperties();
for (Iterator<?> objIt = vEventProperties.iterator(); objIt.hasNext(); ) {
Object property = objIt.next();
if (property instanceof RRule || property instanceof ExDate) {
objIt.remove();
}
}
try {
Kalendar calendar = recurEvent.getCalendar();
Date startDate = recurEvent.getOccurenceDate();
String startString = CalendarUtils.formatRecurrenceDate(startDate, rootEvent.isAllDayEvent());
RecurrenceId recurId;
if (rootEvent.isAllDayEvent()) {
recurId = new RecurrenceId(tz);
recurId.setDate(CalendarUtils.createDate(startDate));
} else {
recurId = new RecurrenceId(startString, tz);
}
vEventProperties.add(recurId);
KalendarEvent kEvent = getKalendarEvent(vEvent);
kEvent.setKalendar(calendar);
return kEvent;
} catch (ParseException e) {
log.error("", e);
return null;
}
}
use of org.olat.commons.calendar.model.KalendarEvent 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;
}
use of org.olat.commons.calendar.model.KalendarEvent in project openolat by klemens.
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();
}
use of org.olat.commons.calendar.model.KalendarEvent in project openolat by klemens.
the class CalWebService method addEventsByCalendar.
private Response addEventsByCalendar(List<EventVO> events, 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();
}
List<KalendarEvent> kalEventToAdd = new ArrayList<>();
List<KalendarEvent> kalEventToUpdate = new ArrayList<>();
CalendarManager calendarManager = CoreSpringFactory.getImpl(CalendarManager.class);
for (EventVO event : events) {
KalendarEvent kalEvent;
if (!StringHelper.containsNonWhitespace(event.getId())) {
String id = UUID.randomUUID().toString();
kalEvent = new KalendarEvent(id, event.getRecurrenceId(), event.getSubject(), event.getBegin(), event.getEnd());
transfer(event, kalEvent);
kalEventToAdd.add(kalEvent);
} else {
kalEvent = calendar.getKalendar().getEvent(event.getId(), event.getRecurrenceId());
if (kalEvent == null) {
kalEvent = new KalendarEvent(event.getId(), event.getRecurrenceId(), event.getSubject(), event.getBegin(), event.getEnd());
transfer(event, kalEvent);
kalEventToAdd.add(kalEvent);
} else {
kalEvent.setBegin(event.getBegin());
kalEvent.setEnd(event.getEnd());
kalEvent.setSubject(event.getSubject());
transfer(event, kalEvent);
kalEventToUpdate.add(kalEvent);
}
}
}
if (kalEventToAdd.size() > 0) {
calendarManager.addEventTo(calendar.getKalendar(), kalEventToAdd);
}
if (kalEventToUpdate.size() > 0) {
calendarManager.updateEventsFrom(calendar.getKalendar(), kalEventToUpdate);
}
return Response.ok().build();
}
Aggregations