use of net.fortuna.ical4j.model.property.PollItemId in project bw-calendar-engine by Bedework.
the class IcalUtil method parseVpollCandidates.
/**
* @param poll the poll entity
* @return Parsed components.
* @throws Throwable
*/
public static Map<Integer, Component> parseVpollCandidates(final BwEvent poll) throws Throwable {
final StringBuilder sb = new StringBuilder();
sb.append("BEGIN:VCALENDAR\n");
sb.append("PRODID://Bedework.org//BedeWork V3.9//EN\n");
sb.append("VERSION:2.0\n");
if (!Util.isEmpty(poll.getPollItems())) {
for (final String s : poll.getPollItems()) {
sb.append(s);
}
}
sb.append("END:VCALENDAR\n");
try {
final StringReader sr = new StringReader(sb.toString());
final Icalendar ic = new Icalendar();
final CalendarBuilder bldr = new CalendarBuilder(new CalendarParserImpl(), ic);
final UnfoldingReader ufrdr = new UnfoldingReader(sr, true);
final Calendar ical = bldr.build(ufrdr);
final Map<Integer, Component> comps = new HashMap<>();
for (final Object o : ical.getComponents()) {
final Component comp = (Component) o;
final PollItemId pid = (PollItemId) comp.getProperty(Property.POLL_ITEM_ID);
if (pid == null) {
continue;
}
comps.put(pid.getPollitemid(), comp);
}
return comps;
} catch (final ParserException pe) {
throw new IcalMalformedException(pe.getMessage());
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
use of net.fortuna.ical4j.model.property.PollItemId in project bw-calendar-engine by Bedework.
the class BwEventUtil method processCandidates.
private static void processCandidates(final VPoll val, final EventInfo vpoll, final ChangeTable changes) throws CalFacadeException {
try {
final ComponentList cands = val.getCandidates();
if ((cands == null) || cands.isEmpty()) {
return;
}
final Iterator it = cands.iterator();
final Set<Integer> pids = new TreeSet<>();
final BwEvent event = vpoll.getEvent();
if (!Util.isEmpty(event.getPollItems())) {
event.clearPollItems();
}
while (it.hasNext()) {
final Component comp = (Component) it.next();
final String pollItem = comp.toString();
event.addPollItem(pollItem);
changes.addValue(PropertyInfoIndex.POLL_ITEM, pollItem);
final Property p = comp.getProperty(Property.POLL_ITEM_ID);
if (p == null) {
throw new CalFacadeException("XXX - no poll item id");
}
final int pid = ((PollItemId) p).getPollitemid();
if (pids.contains(pid)) {
throw new CalFacadeException("XXX - duplicate poll item id " + pid);
}
pids.add(pid);
// EventInfo cand = toEvent(cb, cal, ical, (Component)o, true,
// false);
// cand.getEvent().setOwnerHref(vpoll.getEvent().getOwnerHref());
// vpoll.addContainedItem(cand);
}
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
Aggregations