for (final TeamEvent teamEventObject : teamEvents) {
if (teamEventObject instanceof TeamEventDO == false) {
log.warn("Oups, shouldn't occur, please contact the developer: teamEvent isn't of type TeamEventDO: " + teamEventObject);
continue;
}
final TeamEventDO teamEvent = (TeamEventDO)teamEventObject;
final String uid = TeamCalConfig.get().createEventUid(teamEvent.getId());
String summary;
if (teamCalIds.length > 1) {
summary = teamEvent.getSubject() + " (" + teamEvent.getCalendar().getTitle() + ")";
} else {
summary = teamEvent.getSubject();
}
final VEvent vEvent = ICal4JUtils.createVEvent(teamEvent.getStartDate(), teamEvent.getEndDate(), uid, summary,
teamEvent.isAllDay());
if (StringUtils.isNotBlank(teamEvent.getLocation()) == true) {
vEvent.getProperties().add(new Location(teamEvent.getLocation()));
}
vEvent.getProperties().add(new Name(teamEvent.getCalendar().getTitle()));
if (StringUtils.isNotBlank(teamEvent.getNote()) == true) {
vEvent.getProperties().add(new Description(teamEvent.getNote()));
}
// add alarm if necessary
if (exportReminders == true && teamEvent.getReminderDuration() != null && teamEvent.getReminderActionType() != null) {
final VAlarm alarm = new VAlarm();
Dur dur = null;
// (-1) * needed to set alert before
if (ReminderDurationUnit.MINUTES.equals(teamEvent.getReminderDurationUnit())) {
dur = new Dur(0, 0, (-1) * teamEvent.getReminderDuration(), 0);
} else if (ReminderDurationUnit.HOURS.equals(teamEvent.getReminderDurationUnit())) {
dur = new Dur(0, (-1) * teamEvent.getReminderDuration(), 0, 0);
} else if (ReminderDurationUnit.DAYS.equals(teamEvent.getReminderDurationUnit())) {
dur = new Dur((-1) * teamEvent.getReminderDuration(), 0, 0, 0);
}
if (dur != null) {
alarm.getProperties().add(new Trigger(dur));
alarm.getProperties().add(new Action(teamEvent.getReminderActionType().getType()));
vEvent.getAlarms().add(alarm);
}
}
if (teamEvent.hasRecurrence() == true) {
final Recur recur = teamEvent.getRecurrenceObject();
if (recur.getUntil() != null) {
recur.setUntil(ICal4JUtils.getICal4jDateTime(CalendarUtils.getEndOfDay(recur.getUntil(), timeZone), timeZone));
}
final RRule rrule = new RRule(recur);
vEvent.getProperties().add(rrule);
if (teamEvent.getRecurrenceExDate() != null) {
final List<net.fortuna.ical4j.model.Date> exDates = ICal4JUtils.parseISODateStringsAsICal4jDates(
teamEvent.getRecurrenceExDate(), timeZone);
if (CollectionUtils.isEmpty(exDates) == false) {
for (final net.fortuna.ical4j.model.Date date : exDates) {
final DateList dateList;
if (teamEvent.isAllDay() == true) {
dateList = new DateList(Value.DATE);
} else {
dateList = new DateList();
}
dateList.add(date);