Search in sources :

Example 1 with WeekDay

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

the class RecurRuleComponents method fromEventXrules.

private static Collection<RecurRuleComponents> fromEventXrules(BwEvent ev, Collection<String> rules) throws CalFacadeException {
    Collection<RecurRuleComponents> rrcs = new ArrayList<RecurRuleComponents>();
    if (!ev.isRecurringEntity()) {
        return rrcs;
    }
    if (rules == null) {
        return rrcs;
    }
    try {
        for (String rule : rules) {
            RecurRuleComponents rrc = new RecurRuleComponents();
            Recur recur = new Recur(rule);
            rrc.setRule(rule);
            rrc.setFreq(Freq.valueOf(recur.getFrequency()));
            Date until = recur.getUntil();
            if (until != null) {
                rrc.setUntil(until);
            } else {
                rrc.setCount(recur.getCount());
            }
            rrc.setInterval(recur.getInterval());
            rrc.setBySecond(checkNumList(recur.getSecondList()));
            rrc.setByMinute(checkNumList(recur.getMinuteList()));
            rrc.setByHour(checkNumList(recur.getHourList()));
            /* Group by position */
            Collection wds = recur.getDayList();
            if (wds != null) {
                HashMap<Integer, Collection<String>> hm = new HashMap<Integer, Collection<String>>();
                for (Object o : wds) {
                    WeekDay wd = (WeekDay) o;
                    Collection<String> c = hm.get(wd.getOffset());
                    if (c == null) {
                        c = new ArrayList<>();
                        hm.put(wd.getOffset(), c);
                    }
                    c.add(wd.getDay().name());
                }
                final Collection<PosDays> pds = new ArrayList<>();
                final Set<Integer> poss = hm.keySet();
                for (final Integer pos : poss) {
                    pds.add(new PosDays(pos, hm.get(pos)));
                }
                rrc.setByDay(pds);
            }
            rrc.setByMonthDay(checkNumList(recur.getMonthDayList()));
            rrc.setByYearDay(checkNumList(recur.getYearDayList()));
            rrc.setByWeekNo(checkNumList(recur.getWeekNoList()));
            rrc.setByMonth(checkNumList(recur.getMonthList()));
            rrc.setBySetPos(checkNumList(recur.getSetPosList()));
            if (recur.getWeekStartDay() != null) {
                rrc.setWkst(recur.getWeekStartDay().name());
            }
            rrcs.add(rrc);
        }
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
    return rrcs;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Date(net.fortuna.ical4j.model.Date) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) WeekDay(net.fortuna.ical4j.model.WeekDay) Collection(java.util.Collection) Recur(net.fortuna.ical4j.model.Recur)

Example 2 with WeekDay

use of net.fortuna.ical4j.model.WeekDay 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 3 with WeekDay

use of net.fortuna.ical4j.model.WeekDay in project ofbiz-framework by apache.

the class ICalRecurConverter method visit.

@Override
public void visit(TemporalExpressions.DayInMonth expr) {
    Recur recur = new Recur(Recur.MONTHLY, 0);
    recur.getDayList().add(new WeekDay(dayOfWeekArray[expr.getDayOfWeek() - 1], expr.getOccurrence()));
    this.state.addRecur(recur);
}
Also used : WeekDay(net.fortuna.ical4j.model.WeekDay) Recur(net.fortuna.ical4j.model.Recur)

Example 4 with WeekDay

use of net.fortuna.ical4j.model.WeekDay in project ofbiz-framework by apache.

the class ICalRecurConverter method consolidateRecurs.

@SuppressWarnings("unchecked")
protected Recur consolidateRecurs(List<Recur> recurList) {
    // Try to consolidate a list of Recur instances into one instance
    Set<Integer> monthList = new HashSet<>();
    Set<Integer> monthDayList = new HashSet<>();
    Set<WeekDay> weekDayList = new HashSet<>();
    Set<Integer> hourList = new HashSet<>();
    Set<Integer> minuteList = new HashSet<>();
    String freq = null;
    int freqCount = 0;
    for (Recur recur : recurList) {
        monthList.addAll(recur.getMonthList());
        monthDayList.addAll(recur.getMonthDayList());
        weekDayList.addAll(recur.getDayList());
        hourList.addAll(recur.getHourList());
        minuteList.addAll(recur.getMinuteList());
        if (recur.getInterval() != 0) {
            freq = recur.getFrequency();
            freqCount = recur.getInterval();
        }
    }
    if (freq == null && monthList.size() > 0) {
        freq = Recur.MONTHLY;
    } else if (freq == null && (monthDayList.size() > 0 || weekDayList.size() > 0)) {
        freq = Recur.DAILY;
    } else if (freq == null && hourList.size() > 0) {
        freq = Recur.HOURLY;
    } else if (freq == null && minuteList.size() > 0) {
        freq = Recur.MINUTELY;
    }
    if (freq == null) {
        throw new IllegalStateException("Unable to convert intersection");
    }
    Recur newRecur = new Recur(freq, 0);
    if (freqCount != 0) {
        newRecur.setInterval(freqCount);
    }
    newRecur.getMonthList().addAll(monthList);
    newRecur.getMonthDayList().addAll(monthDayList);
    newRecur.getDayList().addAll(weekDayList);
    newRecur.getHourList().addAll(hourList);
    newRecur.getMinuteList().addAll(minuteList);
    return newRecur;
}
Also used : WeekDay(net.fortuna.ical4j.model.WeekDay) HashSet(java.util.HashSet) Recur(net.fortuna.ical4j.model.Recur)

Aggregations

Recur (net.fortuna.ical4j.model.Recur)4 WeekDay (net.fortuna.ical4j.model.WeekDay)4 Date (net.fortuna.ical4j.model.Date)2 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)2 FreqRecurType (ietf.params.xml.ns.icalendar_2.FreqRecurType)1 RecurType (ietf.params.xml.ns.icalendar_2.RecurType)1 RrulePropType (ietf.params.xml.ns.icalendar_2.RrulePropType)1 UntilRecurType (ietf.params.xml.ns.icalendar_2.UntilRecurType)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 RRule (net.fortuna.ical4j.model.property.RRule)1 BwString (org.bedework.calfacade.BwString)1