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;
}
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);
}
}
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);
}
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;
}
Aggregations