Search in sources :

Example 1 with PollItemId

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);
    }
}
Also used : ParserException(net.fortuna.ical4j.data.ParserException) CalendarParserImpl(net.fortuna.ical4j.data.CalendarParserImpl) HashMap(java.util.HashMap) UnfoldingReader(net.fortuna.ical4j.data.UnfoldingReader) Calendar(net.fortuna.ical4j.model.Calendar) PollItemId(net.fortuna.ical4j.model.property.PollItemId) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) StringReader(java.io.StringReader) CalendarComponent(net.fortuna.ical4j.model.component.CalendarComponent) StartEndComponent(org.bedework.calfacade.base.StartEndComponent) Component(net.fortuna.ical4j.model.Component)

Example 2 with PollItemId

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);
    }
}
Also used : ComponentList(net.fortuna.ical4j.model.ComponentList) BwEvent(org.bedework.calfacade.BwEvent) BwString(org.bedework.calfacade.BwString) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) PollItemId(net.fortuna.ical4j.model.property.PollItemId) TreeSet(java.util.TreeSet) Iterator(java.util.Iterator) Component(net.fortuna.ical4j.model.Component) BwFreeBusyComponent(org.bedework.calfacade.BwFreeBusyComponent) DateListProperty(net.fortuna.ical4j.model.property.DateListProperty) XProperty(net.fortuna.ical4j.model.property.XProperty) Property(net.fortuna.ical4j.model.Property) DateProperty(net.fortuna.ical4j.model.property.DateProperty)

Aggregations

Component (net.fortuna.ical4j.model.Component)2 PollItemId (net.fortuna.ical4j.model.property.PollItemId)2 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)2 StringReader (java.io.StringReader)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 TreeSet (java.util.TreeSet)1 CalendarParserImpl (net.fortuna.ical4j.data.CalendarParserImpl)1 ParserException (net.fortuna.ical4j.data.ParserException)1 UnfoldingReader (net.fortuna.ical4j.data.UnfoldingReader)1 Calendar (net.fortuna.ical4j.model.Calendar)1 ComponentList (net.fortuna.ical4j.model.ComponentList)1 Property (net.fortuna.ical4j.model.Property)1 CalendarComponent (net.fortuna.ical4j.model.component.CalendarComponent)1 DateListProperty (net.fortuna.ical4j.model.property.DateListProperty)1 DateProperty (net.fortuna.ical4j.model.property.DateProperty)1 XProperty (net.fortuna.ical4j.model.property.XProperty)1 BwEvent (org.bedework.calfacade.BwEvent)1 BwFreeBusyComponent (org.bedework.calfacade.BwFreeBusyComponent)1 BwString (org.bedework.calfacade.BwString)1