use of org.olat.commons.calendar.model.KalendarEventLink in project openolat by klemens.
the class ICalFileCalendarManager method getVEvent.
private VEvent getVEvent(KalendarEvent kEvent) {
VEvent vEvent = new VEvent();
if (!kEvent.isAllDayEvent()) {
// regular VEvent
DateTime dtBegin = new DateTime(kEvent.getBegin());
if (tz != null) {
dtBegin.setTimeZone(tz);
}
Date kEventEnd = kEvent.getEnd();
if (kEventEnd == null) {
vEvent = new VEvent(dtBegin, kEvent.getSubject());
} else {
DateTime dtEnd = new DateTime(kEventEnd);
if (tz != null) {
dtEnd.setTimeZone(tz);
}
vEvent = new VEvent(dtBegin, dtEnd, kEvent.getSubject());
}
} else {
// AllDay VEvent
net.fortuna.ical4j.model.Date dtBegin = CalendarUtils.createDate(kEvent.getBegin());
// adjust end date: ICal end dates for all day events are on the next day
Date adjustedEndDate = new Date(kEvent.getEnd().getTime() + (1000 * 60 * 60 * 24));
net.fortuna.ical4j.model.Date dtEnd = CalendarUtils.createDate(adjustedEndDate);
vEvent = new VEvent(dtBegin, dtEnd, kEvent.getSubject());
}
if (kEvent.getCreated() > 0) {
Created created = new Created(new DateTime(kEvent.getCreated()));
vEvent.getProperties().add(created);
}
if ((kEvent.getCreatedBy() != null) && !kEvent.getCreatedBy().trim().isEmpty()) {
Contact contact = new Contact();
contact.setValue(kEvent.getCreatedBy());
vEvent.getProperties().add(contact);
}
if (kEvent.getLastModified() > 0) {
LastModified lastMod = new LastModified(new DateTime(kEvent.getLastModified()));
vEvent.getProperties().add(lastMod);
}
// Uid
PropertyList vEventProperties = vEvent.getProperties();
vEventProperties.add(new Uid(kEvent.getID()));
// clazz
switch(kEvent.getClassification()) {
case KalendarEvent.CLASS_PRIVATE:
vEventProperties.add(ICAL_CLASS_PRIVATE);
break;
case KalendarEvent.CLASS_PUBLIC:
vEventProperties.add(ICAL_CLASS_PUBLIC);
break;
case KalendarEvent.CLASS_X_FREEBUSY:
vEventProperties.add(ICAL_CLASS_X_FREEBUSY);
break;
default:
vEventProperties.add(ICAL_CLASS_PRIVATE);
break;
}
// location
if (kEvent.getLocation() != null) {
vEventProperties.add(new Location(kEvent.getLocation()));
}
if (kEvent.getDescription() != null) {
vEventProperties.add(new Description(kEvent.getDescription()));
}
// event links
Url urlOnce = null;
List<KalendarEventLink> kalendarEventLinks = kEvent.getKalendarEventLinks();
if ((kalendarEventLinks != null) && !kalendarEventLinks.isEmpty()) {
for (Iterator<KalendarEventLink> iter = kalendarEventLinks.iterator(); iter.hasNext(); ) {
KalendarEventLink link = iter.next();
StringBuilder linkEncoded = new StringBuilder(200);
linkEncoded.append(link.getProvider());
linkEncoded.append("§");
linkEncoded.append(link.getId());
linkEncoded.append("§");
linkEncoded.append(link.getDisplayName());
linkEncoded.append("§");
linkEncoded.append(link.getURI());
linkEncoded.append("§");
linkEncoded.append(link.getIconCssClass());
XProperty linkProperty = new XProperty(ICAL_X_OLAT_LINK, linkEncoded.toString());
vEventProperties.add(linkProperty);
if (urlOnce == null) {
try {
Url url = new Url();
url.setValue(link.getURI());
urlOnce = url;
} catch (URISyntaxException e) {
log.error("Invalid URL:" + link.getURI());
}
}
}
}
if (urlOnce != null) {
vEventProperties.add(urlOnce);
}
if (kEvent.getComment() != null) {
vEventProperties.add(new XProperty(ICAL_X_OLAT_COMMENT, kEvent.getComment()));
}
if (kEvent.getNumParticipants() != null) {
vEventProperties.add(new XProperty(ICAL_X_OLAT_NUMPARTICIPANTS, Integer.toString(kEvent.getNumParticipants())));
}
if (kEvent.getParticipants() != null) {
StringBuilder strBuf = new StringBuilder();
String[] participants = kEvent.getParticipants();
for (String participant : participants) {
strBuf.append(participant);
strBuf.append("§");
}
vEventProperties.add(new XProperty(ICAL_X_OLAT_PARTICIPANTS, strBuf.toString()));
}
if (kEvent.getSourceNodeId() != null) {
vEventProperties.add(new XProperty(ICAL_X_OLAT_SOURCENODEID, kEvent.getSourceNodeId()));
}
if (kEvent.getManagedFlags() != null) {
String val = CalendarManagedFlag.toString(kEvent.getManagedFlags());
vEventProperties.add(new XProperty(ICAL_X_OLAT_MANAGED, val));
}
if (StringHelper.containsNonWhitespace(kEvent.getExternalId())) {
vEventProperties.add(new XProperty(ICAL_X_OLAT_EXTERNAL_ID, kEvent.getExternalId()));
}
if (StringHelper.containsNonWhitespace(kEvent.getExternalSource())) {
vEventProperties.add(new XProperty(ICAL_X_OLAT_EXTERNAL_SOURCE, kEvent.getExternalSource()));
}
String recurenceId = kEvent.getRecurrenceID();
if (StringHelper.containsNonWhitespace(recurenceId)) {
try {
RecurrenceId recurId = new RecurrenceId(tz);
// VALUE=DATE recurrence id need to be specially saved
if (recurenceId.length() < 9) {
recurId = new RecurrenceId(tz);
recurId.setDate(CalendarUtils.createDate(new net.fortuna.ical4j.model.Date(recurenceId)));
} else {
recurId = new RecurrenceId(recurenceId, tz);
}
vEventProperties.add(recurId);
} catch (ParseException e) {
log.error("cannot create recurrence ID: " + recurenceId, e);
}
}
// recurrence
String recurrence = kEvent.getRecurrenceRule();
if (recurrence != null && !recurrence.equals("")) {
try {
Recur recur = new Recur(recurrence);
RRule rrule = new RRule(recur);
vEventProperties.add(rrule);
} catch (ParseException e) {
log.error("cannot create recurrence rule: " + recurrence.toString(), e);
}
}
// recurrence exclusions
String recurrenceExc = kEvent.getRecurrenceExc();
if (recurrenceExc != null && !recurrenceExc.equals("")) {
ExDate exdate = new ExDate();
try {
exdate.setValue(recurrenceExc);
vEventProperties.add(exdate);
} catch (ParseException e) {
log.error("", e);
}
}
return vEvent;
}
use of org.olat.commons.calendar.model.KalendarEventLink 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();
}
}
use of org.olat.commons.calendar.model.KalendarEventLink 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);
}
use of org.olat.commons.calendar.model.KalendarEventLink in project openolat by klemens.
the class ExternalLinksController method createLinkWrapper.
private LinkWrapper createLinkWrapper() {
String id = UUID.randomUUID().toString().replaceAll("-", "");
KalendarEventLink newLink = new KalendarEventLink(EXTERNAL_LINKS_PROVIDER, id, "", "", "");
LinkWrapper newLinkWrapper = new LinkWrapper(newLink);
return newLinkWrapper;
}
use of org.olat.commons.calendar.model.KalendarEventLink in project openolat by klemens.
the class ExternalLinksController method formOK.
@Override
protected void formOK(UserRequest ureq) {
List<KalendarEventLink> links = kalendarEvent.getKalendarEventLinks();
List<LinkWrapper> filledWrappers = new ArrayList<LinkWrapper>();
for (LinkWrapper linkWrapper : externalLinks) {
if (!linkWrapper.isEmpty()) {
filledWrappers.add(linkWrapper);
}
}
// add and update links
Set<String> usedUuids = new HashSet<String>();
for (LinkWrapper linkWrapper : filledWrappers) {
boolean found = false;
usedUuids.add(linkWrapper.getId());
for (KalendarEventLink link : links) {
if (link.getId().equals(linkWrapper.getId())) {
link.setURI(linkWrapper.getUrl().getValue());
link.setDisplayName(linkWrapper.getName().getValue());
link.setIconCssClass("o_icon o_icon_link_extern");
found = true;
}
}
if (!found) {
KalendarEventLink newLink = linkWrapper.getLink();
newLink.setURI(linkWrapper.getUrl().getValue());
newLink.setDisplayName(linkWrapper.getName().getValue());
newLink.setIconCssClass("o_icon o_icon_link_extern");
links.add(newLink);
}
}
// remove deleted links
for (Iterator<KalendarEventLink> it = links.iterator(); it.hasNext(); ) {
KalendarEventLink link = it.next();
if (EXTERNAL_LINKS_PROVIDER.equals(link.getId()) && !usedUuids.contains(link.getId())) {
it.remove();
}
}
fireEvent(ureq, Event.DONE_EVENT);
}
Aggregations