use of net.fortuna.ical4j.model.Recur in project OpenOLAT by OpenOLAT.
the class CalendarUtils method getRecurrence.
public static String getRecurrence(String rule) {
if (rule != null) {
try {
Recur recur = new Recur(rule);
String frequency = recur.getFrequency();
WeekDayList wdl = recur.getDayList();
Integer interval = recur.getInterval();
if ((wdl != null && wdl.size() > 0)) {
// we only support one rule with daylist
return KalendarEvent.WORKDAILY;
} else if (interval != null && interval == 2) {
// we only support one rule with interval
return KalendarEvent.BIWEEKLY;
} else {
// native supportet rule
return frequency;
}
} catch (ParseException e) {
log.error("cannot restore recurrence rule", e);
}
}
return null;
}
use of net.fortuna.ical4j.model.Recur in project ofbiz-framework by apache.
the class ICalRecurConverter method visit.
@SuppressWarnings("unchecked")
@Override
public void visit(HourRange expr) {
NumberList hourList = new NumberList();
hourList.addAll(expr.getHourRangeAsSet());
Recur recur = new Recur(Recur.HOURLY, 0);
recur.getHourList().addAll(hourList);
this.state.addRecur(recur);
}
use of net.fortuna.ical4j.model.Recur in project ofbiz-framework by apache.
the class ICalRecurConverter method visit.
@SuppressWarnings("unchecked")
@Override
public void visit(TemporalExpressions.MonthRange expr) {
int startMonth = expr.getStartMonth();
int endMonth = expr.getEndMonth();
Calendar cal = Calendar.getInstance();
int maxMonth = cal.getActualMaximum(Calendar.MONTH);
NumberList monthList = new NumberList();
monthList.add(startMonth + 1);
while (startMonth != endMonth) {
startMonth++;
if (startMonth > maxMonth) {
startMonth = Calendar.JANUARY;
}
monthList.add(startMonth + 1);
}
Recur recur = new Recur(Recur.MONTHLY, 0);
recur.getMonthList().addAll(monthList);
this.state.addRecur(recur);
}
use of net.fortuna.ical4j.model.Recur in project openolat by klemens.
the class ICalFileCalendarManager method getRecurrenceEndDate.
/**
* @param rule
* @return date of recurrence end
*/
@Override
public Date getRecurrenceEndDate(String rule) {
if (rule != null) {
try {
TimeZone ltz = calendarModule.getDefaultTimeZone();
Recur recur = new Recur(rule);
Date dUntil = recur.getUntil();
DateTime dtUntil = dUntil == null ? null : new DateTime(dUntil.getTime());
if (dtUntil != null) {
if (ltz != null) {
dtUntil.setTimeZone(ltz);
}
return dtUntil;
}
} catch (ParseException e) {
log.error("cannot restore recurrence rule", e);
}
}
return null;
}
use of net.fortuna.ical4j.model.Recur in project openolat by klemens.
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();
}
Aggregations