use of net.fortuna.ical4j.model.property.RecurrenceId in project bw-calendar-engine by Bedework.
the class VEventUtil method toIcalComponent.
/**
* Make an Icalendar component from a BwEvent object. This may produce a
* VEvent, VTodo, VJournal or VPoll.
*
* @param ei the event
* @param isOverride - true if event object is an override
* @param tzreg - timezone registry
* @param currentPrincipal - href for current authenticated user
* @return Component
* @throws CalFacadeException
*/
public static Component toIcalComponent(final EventInfo ei, final boolean isOverride, final TimeZoneRegistry tzreg, final String currentPrincipal) throws CalFacadeException {
if ((ei == null) || (ei.getEvent() == null)) {
return null;
}
final BwEvent val = ei.getEvent();
boolean isInstance = false;
try {
Component xcomp = null;
Calendar cal = null;
final List<BwXproperty> xcompProps = val.getXproperties(BwXproperty.bedeworkIcal);
if (!Util.isEmpty(xcompProps)) {
final BwXproperty xcompProp = xcompProps.get(0);
final String xcompPropVal = xcompProp.getValue();
if (xcompPropVal != null) {
final StringBuilder sb = new StringBuilder();
final Icalendar ic = new Icalendar();
try {
sb.append("BEGIN:VCALENDAR\n");
sb.append(Version.VERSION_2_0.toString());
sb.append("\n");
sb.append(xcompPropVal);
if (!xcompPropVal.endsWith("\n")) {
sb.append("\n");
}
sb.append("END:VCALENDAR\n");
CalendarBuilder bldr = new CalendarBuilder(new CalendarParserImpl(), ic);
UnfoldingReader ufrdr = new UnfoldingReader(new StringReader(sb.toString()), true);
cal = bldr.build(ufrdr);
} catch (Throwable t) {
error(t);
error("Trying to parse:\n" + xcompPropVal);
}
}
}
Component comp;
PropertyList pl = new PropertyList();
boolean freeBusy = false;
boolean vavail = false;
boolean todo = false;
boolean vpoll = false;
int entityType = val.getEntityType();
if (entityType == IcalDefs.entityTypeEvent) {
comp = new VEvent(pl);
} else if (entityType == IcalDefs.entityTypeTodo) {
comp = new VToDo(pl);
todo = true;
} else if (entityType == IcalDefs.entityTypeJournal) {
comp = new VJournal(pl);
} else if (entityType == IcalDefs.entityTypeFreeAndBusy) {
comp = new VFreeBusy(pl);
freeBusy = true;
} else if (entityType == IcalDefs.entityTypeVavailability) {
comp = new VAvailability(pl);
vavail = true;
} else if (entityType == IcalDefs.entityTypeAvailable) {
comp = new Available(pl);
} else if (entityType == IcalDefs.entityTypeVpoll) {
comp = new VPoll(pl);
vpoll = true;
} else {
throw new CalFacadeException("org.bedework.invalid.entity.type", String.valueOf(entityType));
}
if (cal != null) {
xcomp = cal.getComponent(comp.getName());
}
Property prop;
/* ------------------- RecurrenceID --------------------
* Done early so we know if this is an instance.
*/
String strval = val.getRecurrenceId();
if ((strval != null) && (strval.length() > 0)) {
isInstance = true;
pl.add(new RecurrenceId(makeZonedDt(val, strval)));
}
/* ------------------- Alarms -------------------- */
VAlarmUtil.processEventAlarm(val, comp, currentPrincipal);
/* ------------------- Attachments -------------------- */
if (val.getNumAttachments() > 0) {
for (BwAttachment att : val.getAttachments()) {
pl.add(setAttachment(att));
}
}
/* ------------------- Attendees -------------------- */
if (!vpoll && (val.getNumAttendees() > 0)) {
for (BwAttendee att : val.getAttendees()) {
prop = setAttendee(att);
mergeXparams(prop, xcomp);
pl.add(prop);
}
}
if (val.getNumCategories() > 0) {
// LANG - filter on language - group language in one cat list?
for (BwCategory cat : val.getCategories()) {
prop = new Categories();
TextList cl = ((Categories) prop).getCategories();
cl.add(cat.getWord().getValue());
pl.add(langProp(prop, cat.getWord()));
}
}
/* ------------------- Class -------------------- */
final String pval = val.getClassification();
if (pval != null) {
pl.add(new Clazz(pval));
}
if (val.getNumComments() > 0) {
for (final BwString str : val.getComments()) {
pl.add(langProp(new Comment(str.getValue()), str));
}
}
if ((todo || vpoll) && (val.getCompleted() != null)) {
prop = new Completed(new DateTime(val.getCompleted()));
pl.add(prop);
}
if (val.getNumContacts() > 0) {
for (final BwContact c : val.getContacts()) {
// LANG
prop = new Contact(c.getCn().getValue());
final String l = c.getLink();
if (l != null) {
prop.getParameters().add(new AltRep(l));
}
pl.add(langProp(uidProp(prop, c.getUid()), c.getCn()));
}
}
if (val.getCost() != null) {
IcalUtil.addXproperty(pl, BwXproperty.bedeworkCost, null, val.getCost());
}
/* ------------------- Created -------------------- */
prop = new Created(val.getCreated());
// if (pars.includeDateTimeProperty) {
// prop.getParameters().add(Value.DATE_TIME);
// }
pl.add(prop);
if (val.getDeleted()) {
IcalUtil.addXproperty(pl, BwXproperty.bedeworkDeleted, null, String.valueOf(val.getDeleted()));
}
/* ------------------- Description -------------------- */
BwStringBase bwstr = val.findDescription(null);
if (bwstr != null) {
pl.add(langProp(new Description(bwstr.getValue()), bwstr));
}
if (val.getEndType() == StartEndComponent.endTypeDate) {
if (todo) {
Due due = val.getDtend().makeDue(tzreg);
if (freeBusy | val.getForceUTC()) {
due.setUtc(true);
}
pl.add(due);
} else {
DtEnd dtend = val.getDtend().makeDtEnd(tzreg);
if (freeBusy | val.getForceUTC()) {
dtend.setUtc(true);
}
pl.add(dtend);
}
} else if (val.getEndType() == StartEndComponent.endTypeDuration) {
addProperty(comp, new Duration(new Dur(val.getDuration())));
}
/* ------------------- DtStamp -------------------- */
prop = new DtStamp(new DateTime(val.getDtstamp()));
// if (pars.includeDateTimeProperty) {
// prop.getParameters().add(Value.DATE_TIME);
// }
pl.add(prop);
if (!val.getNoStart()) {
DtStart dtstart = val.getDtstart().makeDtStart(tzreg);
if (freeBusy | val.getForceUTC()) {
dtstart.setUtc(true);
}
pl.add(dtstart);
}
if (freeBusy) {
Collection<BwFreeBusyComponent> fbps = val.getFreeBusyPeriods();
if (fbps != null) {
for (BwFreeBusyComponent fbc : fbps) {
FreeBusy fb = new FreeBusy();
int type = fbc.getType();
if (type == BwFreeBusyComponent.typeBusy) {
addParameter(fb, FbType.BUSY);
} else if (type == BwFreeBusyComponent.typeFree) {
addParameter(fb, FbType.FREE);
} else if (type == BwFreeBusyComponent.typeBusyUnavailable) {
addParameter(fb, FbType.BUSY_UNAVAILABLE);
} else if (type == BwFreeBusyComponent.typeBusyTentative) {
addParameter(fb, FbType.BUSY_TENTATIVE);
} else {
throw new CalFacadeException("Bad free-busy type " + type);
}
PeriodList pdl = fb.getPeriods();
for (Period p : fbc.getPeriods()) {
// XXX inverse.ca plugin cannot handle durations.
Period np = new Period(p.getStart(), p.getEnd());
pdl.add(np);
}
pl.add(fb);
}
}
}
if (!vpoll) {
BwGeo bwgeo = val.getGeo();
if (bwgeo != null) {
Geo geo = new Geo(bwgeo.getLatitude(), bwgeo.getLongitude());
pl.add(geo);
}
}
/* ------------------- LastModified -------------------- */
prop = new LastModified(new DateTime(val.getLastmod()));
// if (pars.includeDateTimeProperty) {
// prop.getParameters().add(Value.DATE_TIME);
// }
pl.add(prop);
if (!vpoll) {
final BwLocation loc = val.getLocation();
if (loc != null) {
prop = new Location(loc.getCombinedValues());
pl.add(langProp(uidProp(prop, loc.getUid()), loc.getAddress()));
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationAddr, null, loc.getAddressField());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationRoom, null, loc.getRoomField());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationAccessible, null, String.valueOf(loc.getAccessible()));
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationSfield1, null, loc.getSubField1());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationSfield2, null, loc.getSubField2());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationGeo, null, loc.getGeouri());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationStreet, null, loc.getStreet());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationCity, null, loc.getCity());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationState, null, loc.getState());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationZip, null, loc.getZip());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationLink, null, loc.getLink());
}
}
/* ------------------- Organizer -------------------- */
BwOrganizer org = val.getOrganizer();
if (org != null) {
prop = setOrganizer(org);
mergeXparams(prop, xcomp);
pl.add(prop);
}
if (todo) {
Integer pc = val.getPercentComplete();
if (pc != null) {
pl.add(new PercentComplete(pc.intValue()));
}
}
/* ------------------- Priority -------------------- */
Integer prio = val.getPriority();
if (prio != null) {
pl.add(new Priority(prio.intValue()));
}
/* ------------------- RDate -below------------------- */
/* ------------------- RelatedTo -------------------- */
/* We encode related to (maybe) as triples - reltype, value-type, value */
String[] info = null;
BwRelatedTo relto = val.getRelatedTo();
if (relto != null) {
info = new String[3];
info[0] = relto.getRelType();
// default
info[1] = "";
info[2] = relto.getValue();
} else {
String relx = val.getXproperty(BwXproperty.bedeworkRelatedTo);
if (relx != null) {
info = Util.decodeArray(relx);
}
}
if (info != null) {
int i = 0;
while (i < info.length) {
RelatedTo irelto;
String reltype = info[i];
String valtype = info[i + 1];
String relval = info[i + 2];
ParameterList rtpl = null;
if (reltype.length() > 0) {
rtpl = new ParameterList();
rtpl.add(new RelType(reltype));
}
if (valtype.length() > 0) {
if (rtpl == null) {
rtpl = new ParameterList();
}
rtpl.add(new Value(valtype));
}
if (rtpl != null) {
irelto = new RelatedTo(rtpl, relval);
} else {
irelto = new RelatedTo(relval);
}
pl.add(irelto);
i += 3;
}
}
if (val.getNumResources() > 0) {
/* This event has a resource */
prop = new Resources();
TextList rl = ((Resources) prop).getResources();
for (BwString str : val.getResources()) {
// LANG
rl.add(str.getValue());
}
pl.add(prop);
}
if (val.getSequence() > 0) {
pl.add(new Sequence(val.getSequence()));
}
/* ------------------- Status -------------------- */
String status = val.getStatus();
if ((status != null) && !status.equals(BwEvent.statusMasterSuppressed)) {
pl.add(new Status(status));
}
/* ------------------- Summary -------------------- */
bwstr = val.findSummary(null);
if (bwstr != null) {
pl.add(langProp(new Summary(bwstr.getValue()), bwstr));
}
if (!todo && !vpoll) {
strval = val.getPeruserTransparency(currentPrincipal);
if ((strval != null) && (strval.length() > 0)) {
pl.add(new Transp(strval));
}
}
/* ------------------- Uid -------------------- */
pl.add(new Uid(val.getUid()));
/* ------------------- Url -------------------- */
strval = val.getLink();
if (strval != null) {
// Possibly drop this if we do it on input and check all data
strval = strval.trim();
}
if ((strval != null) && (strval.length() > 0)) {
URI uri = Util.validURI(strval);
if (uri != null) {
pl.add(new Url(uri));
}
}
if (val.getNumXproperties() > 0) {
try {
IcalUtil.xpropertiesToIcal(pl, val.getXproperties());
} catch (Throwable t) {
// XXX For the moment swallow these.
error(t);
}
}
if (!vpoll && !isInstance && !isOverride && val.testRecurring()) {
doRecurring(val, pl);
}
if (vavail) {
if (ei.getNumContainedItems() > 0) {
final VAvailability va = (VAvailability) comp;
for (final EventInfo aei : ei.getContainedItems()) {
va.getAvailable().add((Available) toIcalComponent(aei, false, tzreg, currentPrincipal));
}
}
/* ----------- Vavailability - busyType ----------------- */
String s = val.getBusyTypeString();
if (s != null) {
pl.add(new BusyType(s));
}
}
if (vpoll) {
final Integer ival = val.getPollWinner();
if (ival != null) {
pl.add(new PollWinner(ival));
}
strval = val.getPollAcceptResponse();
if ((strval != null) && (strval.length() > 0)) {
pl.add(new AcceptResponse(strval));
}
strval = val.getPollMode();
if ((strval != null) && (strval.length() > 0)) {
pl.add(new PollMode(strval));
}
strval = val.getPollProperties();
if ((strval != null) && (strval.length() > 0)) {
pl.add(new PollProperties(strval));
}
final Map<String, VVoter> vvoters = parseVpollVvoters(val);
for (final VVoter vv : vvoters.values()) {
((VPoll) comp).getVoters().add(vv);
}
final Map<Integer, Component> comps = parseVpollCandidates(val);
for (final Component candidate : comps.values()) {
((VPoll) comp).getCandidates().add(candidate);
}
}
return comp;
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
use of net.fortuna.ical4j.model.property.RecurrenceId in project OpenOLAT by OpenOLAT.
the class CalendarImportTest method testImportRecurringCal.
@Test
public void testImportRecurringCal() throws IOException, ParserException {
InputStream in = CalendarImportTest.class.getResourceAsStream("RecurringEvent.ics");
CalendarBuilder builder = new CalendarBuilder();
Calendar calendar = builder.build(in);
assertNotNull(calendar);
VEvent rootEvent = null;
VEvent exceptionEvent = null;
for (Iterator<?> iter = calendar.getComponents().iterator(); iter.hasNext(); ) {
Object comp = iter.next();
if (comp instanceof VEvent) {
VEvent vevent = (VEvent) comp;
if (vevent.getRecurrenceId() == null) {
rootEvent = vevent;
} else {
exceptionEvent = vevent;
}
}
}
assertNotNull(rootEvent);
assertNotNull(exceptionEvent);
java.util.Date startDate = CalendarUtils.getDate(2016, java.util.Calendar.OCTOBER, 10);
DateTime start = new DateTime(startDate);
java.util.Date endDate = CalendarUtils.getDate(2016, java.util.Calendar.NOVEMBER, 10);
DateTime end = new DateTime(endDate);
Period period = new Period(start, end);
PeriodList pList = rootEvent.calculateRecurrenceSet(period);
for (Object obj : pList) {
Period p = (Period) obj;
System.out.println("Period: " + p.getStart());
}
RecurrenceId recurrenceId = exceptionEvent.getRecurrenceId();
Date recurrenceDate = recurrenceId.getDate();
System.out.println("Recurrence: " + recurrenceDate);
exceptionEvent.getSequence();
}
use of net.fortuna.ical4j.model.property.RecurrenceId 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 net.fortuna.ical4j.model.property.RecurrenceId 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 net.fortuna.ical4j.model.property.RecurrenceId 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;
}
Aggregations