Search in sources :

Example 1 with RRule

use of net.fortuna.ical4j.model.property.RRule in project openremote by openremote.

the class AssetStorageService method calendarEventActiveOn.

protected static boolean calendarEventActiveOn(CalendarEvent calendarEvent, Date when) {
    if (calendarEvent.getRecurrence() == null) {
        return (!when.before(calendarEvent.getStart()) && !when.after(calendarEvent.getEnd()));
    }
    RecurrenceRule recurrenceRule = calendarEvent.getRecurrence();
    Recur recurrence;
    if (recurrenceRule.getCount() != null) {
        recurrence = new Recur(recurrenceRule.getFrequency().name(), recurrenceRule.getCount());
    } else if (recurrenceRule.getUntil() != null) {
        recurrence = new Recur(recurrenceRule.getFrequency().name(), new net.fortuna.ical4j.model.Date(recurrenceRule.getUntil()));
    } else {
        recurrence = new Recur(recurrenceRule.getFrequency().name(), null);
    }
    if (recurrenceRule.getInterval() != null) {
        recurrence.setInterval(recurrenceRule.getInterval());
    }
    RRule rRule = new RRule(recurrence);
    VEvent vEvent = new VEvent(new DateTime(calendarEvent.getStart()), new DateTime(calendarEvent.getEnd()), "");
    vEvent.getProperties().add(rRule);
    Period period = new Period(new DateTime(when), new Dur(0, 0, 1, 0));
    PeriodRule periodRule = new PeriodRule(period);
    return periodRule.evaluate(vEvent);
}
Also used : RecurrenceRule(org.openremote.model.calendar.RecurrenceRule) VEvent(net.fortuna.ical4j.model.component.VEvent) Dur(net.fortuna.ical4j.model.Dur) RRule(net.fortuna.ical4j.model.property.RRule) PeriodRule(net.fortuna.ical4j.filter.PeriodRule) Period(net.fortuna.ical4j.model.Period) DateTime(net.fortuna.ical4j.model.DateTime) Recur(net.fortuna.ical4j.model.Recur)

Example 2 with RRule

use of net.fortuna.ical4j.model.property.RRule in project bw-calendar-engine by Bedework.

the class RecurUtil method getLatestRecurrenceDate.

/**
 * Return the absolute latest end date for this event. Note that
 * exclusions may mean the actual latest date is earlier.
 *
 * @param evprops
 * @param vstart
 * @param enddt
 * @param d
 * @param maxRangeEnd
 * @return date
 * @throws CalFacadeException
 */
private static Date getLatestRecurrenceDate(final PropertyList evprops, final DtStart vstart, final DtEnd enddt, final Duration d, final Date maxRangeEnd) throws CalFacadeException {
    boolean debug = getLog().isDebugEnabled();
    try {
        Date start = vstart.getDate();
        Date until = null;
        /* Get the duration of the event to get us past the end
       */
        Dur dur;
        if (d != null) {
            dur = d.getDuration();
        } else {
            Date evend;
            if (enddt == null) {
                evend = start;
            } else {
                evend = enddt.getDate();
            }
            dur = new Dur(start, evend);
        }
        /* Make a new duration incremented a little to avoid any boundary
          conditions */
        if (dur.getWeeks() != 0) {
            dur = new Dur(dur.getWeeks() + 1);
        } else {
            dur = new Dur(dur.getDays() + 1, dur.getHours(), dur.getMinutes(), dur.getSeconds());
        }
        PropertyList rrules = evprops.getProperties(Property.RRULE);
        PropertyList rdts = evprops.getProperties(Property.RDATE);
        if ((rrules == null) && (rdts == null)) {
            // Not a recurring event
            return null;
        }
        if (rrules != null) {
            Iterator rit = rrules.iterator();
            while (rit.hasNext()) {
                RRule r = (RRule) rit.next();
                Date nextUntil = getLastDate(r.getRecur(), start, maxRangeEnd);
                if (nextUntil == null) {
                    /* We have a rule without an end date so it's infinite.
             */
                    return null;
                }
                if (debug) {
                    debugMsg("Last date for recur=" + nextUntil);
                }
                if ((until == null) || (nextUntil.after(until))) {
                    until = nextUntil;
                }
            }
            /* We have some rules - none have an end date so it's infinite.
         */
            if (until == null) {
                // infinite
                return null;
            }
        }
        if (rdts != null) {
            // Get the latest date from each
            // XXX are these sorted?
            Iterator rit = rdts.iterator();
            while (rit.hasNext()) {
                RDate r = (RDate) rit.next();
                if (Value.PERIOD.equals(r.getParameter(Parameter.VALUE))) {
                    PeriodList pl = r.getPeriods();
                    Iterator it = pl.iterator();
                    while (it.hasNext()) {
                        Period p = (Period) it.next();
                        // Not sure if a single date gives a null end
                        Date nextUntil = p.getEnd();
                        if (nextUntil == null) {
                            nextUntil = p.getStart();
                        }
                        if ((until == null) || (nextUntil.after(until))) {
                            until = nextUntil;
                        }
                    }
                } else {
                    // date or datetime
                    DateList startDates = r.getDates();
                    for (int j = 0; j < startDates.size(); j++) {
                        Date startDate = (Date) startDates.get(j);
                        Date endDate = new Date(dur.getTime(startDate));
                        if ((until == null) || (endDate.after(until))) {
                            until = endDate;
                        }
                    }
                }
            }
        }
        if (debug) {
            debugMsg("Last date before fix=" + until);
        }
        /* Now add the duration of the event to get us past the end
       */
        if (until instanceof DateTime) {
            until = new DateTime(dur.getTime(until));
            ((DateTime) until).setUtc(true);
        } else {
            until = new Date(dur.getTime(until));
        }
        if (debug) {
            debugMsg("Last date after fix=" + until);
        }
        return until;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : Dur(net.fortuna.ical4j.model.Dur) RDate(net.fortuna.ical4j.model.property.RDate) RRule(net.fortuna.ical4j.model.property.RRule) PeriodList(net.fortuna.ical4j.model.PeriodList) Period(net.fortuna.ical4j.model.Period) RDate(net.fortuna.ical4j.model.property.RDate) Date(net.fortuna.ical4j.model.Date) DateTime(net.fortuna.ical4j.model.DateTime) BwDateTime(org.bedework.calfacade.BwDateTime) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) PropertyList(net.fortuna.ical4j.model.PropertyList) Iterator(java.util.Iterator) DateList(net.fortuna.ical4j.model.DateList)

Example 3 with RRule

use of net.fortuna.ical4j.model.property.RRule in project bw-calendar-engine by Bedework.

the class ToXEvent method doRecurring.

/**
 * Build recurring properties from event.
 *
 * @param pattern
 * @param compCl - component class for pattern matching
 * @param val
 * @param pl
 * @throws CalFacadeException
 */
public static void doRecurring(final BaseComponentType pattern, final Class compCl, final BwEvent val, final List<JAXBElement<? extends BasePropertyType>> pl) throws CalFacadeException {
    try {
        if (emit(pattern, compCl, RrulePropType.class) && val.hasRrules()) {
            for (String s : val.getRrules()) {
                RRule rule = new RRule();
                rule.setValue(s);
                Recur r = rule.getRecur();
                RecurType rt = new RecurType();
                rt.setFreq(FreqRecurType.fromValue(r.getFrequency()));
                if (r.getCount() > 0) {
                    rt.setCount(BigInteger.valueOf(r.getCount()));
                }
                Date until = r.getUntil();
                if (until != null) {
                    UntilRecurType u = new UntilRecurType();
                    /*
            if (until instanceof DateTime) {
              u.setDateTime(until.toString());
            } else {
              u.setDate(until.toString());
            }
            */
                    XcalUtil.initUntilRecur(u, until.toString());
                }
                if (r.getInterval() > 0) {
                    rt.setInterval(String.valueOf(r.getInterval()));
                }
                listFromNumberList(rt.getBysecond(), r.getSecondList());
                listFromNumberList(rt.getByminute(), r.getMinuteList());
                listFromNumberList(rt.getByhour(), r.getHourList());
                if (r.getDayList() != null) {
                    List<String> l = rt.getByday();
                    for (WeekDay wd : r.getDayList()) {
                        l.add(wd.getDay().name());
                    }
                }
                listFromNumberList(rt.getByyearday(), r.getYearDayList());
                intlistFromNumberList(rt.getBymonthday(), r.getMonthDayList());
                listFromNumberList(rt.getByweekno(), r.getWeekNoList());
                intlistFromNumberList(rt.getBymonth(), r.getMonthList());
                bigintlistFromNumberList(rt.getBysetpos(), r.getSetPosList());
                RrulePropType rrp = new RrulePropType();
                rrp.setRecur(rt);
                pl.add(of.createRrule(rrp));
            }
        }
    /*
      if (emit(pattern, compCl, ExrulePropType.class) &&
          val.hasExrules()) {
        for(String s: val.getExrules()) {
          ExRule rule = new ExRule();
          rule.setValue(s);

          pl.add(rule);
        }
      }

      if (emit(pattern, compCl, RdatePropType.class) {
        makeDlp(false, val.getRdates(), pl);
      }

      if (emit(pattern, compCl, ExdatePropType.class) {
        makeDlp(true, val.getExdates(), pl);
      }
      */
    // } catch (CalFacadeException cfe) {
    // throw cfe;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : UntilRecurType(ietf.params.xml.ns.icalendar_2.UntilRecurType) WeekDay(net.fortuna.ical4j.model.WeekDay) RRule(net.fortuna.ical4j.model.property.RRule) FreqRecurType(ietf.params.xml.ns.icalendar_2.FreqRecurType) RecurType(ietf.params.xml.ns.icalendar_2.RecurType) UntilRecurType(ietf.params.xml.ns.icalendar_2.UntilRecurType) BwString(org.bedework.calfacade.BwString) RrulePropType(ietf.params.xml.ns.icalendar_2.RrulePropType) Date(net.fortuna.ical4j.model.Date) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) Recur(net.fortuna.ical4j.model.Recur)

Example 4 with RRule

use of net.fortuna.ical4j.model.property.RRule in project bw-calendar-engine by Bedework.

the class VEventUtil method doRecurring.

/**
 * Build recurring properties from event.
 *
 * @param val
 * @param pl
 * @throws CalFacadeException
 */
public static void doRecurring(final BwEvent val, final PropertyList pl) throws CalFacadeException {
    try {
        if (val.hasRrules()) {
            for (String s : val.getRrules()) {
                RRule rule = new RRule();
                rule.setValue(s);
                pl.add(rule);
            }
        }
        if (val.hasExrules()) {
            for (String s : val.getExrules()) {
                ExRule rule = new ExRule();
                rule.setValue(s);
                pl.add(rule);
            }
        }
        makeDlp(val, false, val.getRdates(), pl);
        makeDlp(val, true, val.getExdates(), pl);
    } catch (CalFacadeException cfe) {
        throw cfe;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : RRule(net.fortuna.ical4j.model.property.RRule) BwString(org.bedework.calfacade.BwString) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) ExRule(net.fortuna.ical4j.model.property.ExRule)

Example 5 with RRule

use of net.fortuna.ical4j.model.property.RRule in project opencast by opencast.

the class IndexServiceImplTest method generatePeriods.

private List<Period> generatePeriods(TimeZone tz, Calendar start, Calendar end, String days, Long duration) throws ParseException {
    Calendar utcDate = Calendar.getInstance(utc);
    utcDate.setTime(start.getTime());
    RRule rRule = new RRule(generateRule(days, utcDate.get(Calendar.HOUR_OF_DAY), utcDate.get(Calendar.MINUTE)));
    IndexServiceImpl indexServiceImpl = new IndexServiceImpl();
    return calculatePeriods(rRule, start.getTime(), end.getTime(), duration, tz);
}
Also used : RRule(net.fortuna.ical4j.model.property.RRule) Calendar(java.util.Calendar)

Aggregations

RRule (net.fortuna.ical4j.model.property.RRule)23 ParseException (java.text.ParseException)14 Date (java.util.Date)11 Recur (net.fortuna.ical4j.model.Recur)9 DateTime (net.fortuna.ical4j.model.DateTime)8 PropertyList (net.fortuna.ical4j.model.PropertyList)7 ExDate (net.fortuna.ical4j.model.property.ExDate)6 VEvent (net.fortuna.ical4j.model.component.VEvent)5 MediaPackage (org.opencastproject.mediapackage.MediaPackage)5 TimeZone (java.util.TimeZone)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 Period (net.fortuna.ical4j.model.Period)4 RecurrenceId (net.fortuna.ical4j.model.property.RecurrenceId)4 Kalendar (org.olat.commons.calendar.model.Kalendar)4 KalendarEvent (org.olat.commons.calendar.model.KalendarEvent)4 IOException (java.io.IOException)3 Calendar (java.util.Calendar)3 Path (javax.ws.rs.Path)3 Date (net.fortuna.ical4j.model.Date)3 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)3