Search in sources :

Example 1 with BwOrganizer

use of org.bedework.calfacade.BwOrganizer in project bw-calendar-engine by Bedework.

the class ToXEvent method toComponent.

/**
 * Make a BaseComponentType component from a BwEvent object. This may produce a
 * VEvent, VTodo or VJournal.
 *
 * @param val
 * @param isOverride - true if event object is an override
 * @param pattern - if non-null limit returned components and values to those
 *                  supplied in the pattern.
 * @return JAXBElement<? extends BaseComponentType>
 * @throws CalFacadeException
 */
public static JAXBElement<? extends BaseComponentType> toComponent(final BwEvent val, final boolean isOverride, final boolean wrapXprops, final BaseComponentType pattern) throws CalFacadeException {
    if (val == null) {
        return null;
    }
    boolean isInstance = false;
    try {
        JAXBElement<? extends BaseComponentType> el;
        boolean freeBusy = false;
        boolean todo = false;
        int entityType = val.getEntityType();
        if (entityType == IcalDefs.entityTypeEvent) {
            el = of.createVevent(new VeventType());
        } else if (entityType == IcalDefs.entityTypeTodo) {
            el = of.createVtodo(new VtodoType());
            todo = true;
        } else if (entityType == IcalDefs.entityTypeJournal) {
            el = of.createVjournal(new VjournalType());
        } else if (entityType == IcalDefs.entityTypeFreeAndBusy) {
            el = of.createVfreebusy(new VfreebusyType());
            freeBusy = true;
        } else {
            throw new CalFacadeException("org.bedework.invalid.entity.type", String.valueOf(entityType));
        }
        BaseComponentType comp = el.getValue();
        Class masterClass = comp.getClass();
        comp.setProperties(new ArrayOfProperties());
        List<JAXBElement<? extends BasePropertyType>> pl = comp.getProperties().getBasePropertyOrTzid();
        if (emit(pattern, masterClass, RecurrenceIdPropType.class)) {
            String strval = val.getRecurrenceId();
            if ((strval != null) && (strval.length() > 0)) {
                isInstance = true;
                // DORECUR - we should be restoring to original form.
                /* Try using timezone from dtstart so we can more often be in same form
           * as original.
           */
                BwDateTime dts = val.getDtstart();
                RecurrenceIdPropType ri = new RecurrenceIdPropType();
                String tzid = null;
                if (dts.getDateType()) {
                    // RECUR - fix all day recurrences sometime
                    if (strval.length() > 8) {
                        // Try to fix up bad all day recurrence ids. - assume a local timezone
                        strval = strval.substring(0, 8);
                    }
                    ri.setDate(XcalUtil.fromDtval(strval));
                } else {
                    if (!val.getForceUTC()) {
                        if ((dts != null) && !dts.isUTC()) {
                            tzid = dts.getTzid();
                        }
                    }
                    XcalUtil.initDt(ri, strval, tzid);
                }
                pl.add(of.createRecurrenceId(ri));
            }
        }
        /* ------------------- Alarms -------------------- */
        processEventAlarm(val, comp, pattern, masterClass);
        /* ------------------- Attachments -------------------- */
        if (emit(pattern, masterClass, AttachPropType.class)) {
            if (val.getNumAttachments() > 0) {
                for (BwAttachment att : val.getAttachments()) {
                // pl.add(setAttachment(att));
                }
            }
        }
        /* ------------------- Attendees -------------------- */
        if (emit(pattern, masterClass, AttendeePropType.class)) {
            if (val.getNumAttendees() > 0) {
                for (BwAttendee att : val.getAttendees()) {
                    pl.add(of.createAttendee(makeAttendee(att)));
                }
            }
        }
        if (emit(pattern, masterClass, CategoriesPropType.class)) {
            if (val.getNumCategories() > 0) {
                // LANG - filter on language - group language in one cat list?
                for (BwCategory cat : val.getCategories()) {
                    CategoriesPropType c = new CategoriesPropType();
                    c.getText().add(cat.getWord().getValue());
                    pl.add(of.createCategories((CategoriesPropType) langProp(c, cat.getWord())));
                }
            }
        }
        if (emit(pattern, masterClass, ClassPropType.class)) {
            String pval = val.getClassification();
            if (pval != null) {
                ClassPropType c = new ClassPropType();
                c.setText(pval);
                pl.add(of.createClass(c));
            }
        }
        if (emit(pattern, masterClass, CommentPropType.class)) {
            if (val.getNumComments() > 0) {
                for (BwString str : val.getComments()) {
                    CommentPropType c = new CommentPropType();
                    c.setText(str.getValue());
                    pl.add(of.createComment((CommentPropType) langProp(c, str)));
                }
            }
        }
        if (emit(pattern, masterClass, CompletedPropType.class)) {
            if ((entityType == IcalDefs.entityTypeTodo) && (val.getCompleted() != null)) {
                CompletedPropType c = new CompletedPropType();
                c.setUtcDateTime(XcalUtil.getXMlUTCCal(val.getCompleted()));
                pl.add(of.createCompleted(c));
            }
        }
        if (emit(pattern, masterClass, ContactPropType.class)) {
            if (val.getNumContacts() > 0) {
                for (BwContact ctct : val.getContacts()) {
                    // LANG
                    ContactPropType c = new ContactPropType();
                    c.setText(ctct.getCn().getValue());
                    pl.add(of.createContact((ContactPropType) langProp(uidProp(altrepProp(c, ctct.getLink()), ctct.getUid()), ctct.getCn())));
                }
            }
        }
        if (emit(pattern, masterClass, CreatedPropType.class)) {
            CreatedPropType created = new CreatedPropType();
            created.setUtcDateTime(XcalUtil.getXMlUTCCal(val.getCreated()));
            pl.add(of.createCreated(created));
        }
        if (emit(pattern, masterClass, DescriptionPropType.class)) {
            BwStringBase bwstr = val.findDescription(null);
            if (bwstr != null) {
                DescriptionPropType desc = new DescriptionPropType();
                if (bwstr.getValue().contains("Â")) {
                    warn("Odd character  in description: " + bwstr.getValue());
                }
                desc.setText(bwstr.getValue());
                pl.add(of.createDescription((DescriptionPropType) langProp(desc, bwstr)));
            }
        }
        if ((todo && emit(pattern, masterClass, DuePropType.class)) || (!todo && emit(pattern, masterClass, DtendPropType.class))) {
            if (val.getEndType() == BwEvent.endTypeDate) {
                if (todo) {
                    DuePropType due = (DuePropType) makeDateDatetime(new DuePropType(), val.getDtend(), freeBusy | val.getForceUTC());
                    pl.add(of.createDue(due));
                } else {
                    DtendPropType dtend = (DtendPropType) makeDateDatetime(new DtendPropType(), val.getDtend(), freeBusy | val.getForceUTC());
                    pl.add(of.createDtend(dtend));
                }
            } else if (val.getEndType() == BwEvent.endTypeDuration) {
                DurationPropType dur = new DurationPropType();
                dur.setDuration(val.getDuration());
                pl.add(of.createDuration(dur));
            }
        }
        if (emit(pattern, masterClass, DtstampPropType.class)) {
            DtstampPropType dtstamp = new DtstampPropType();
            dtstamp.setUtcDateTime(XcalUtil.getXMlUTCCal(val.getDtstamp()));
            pl.add(of.createDtstamp(dtstamp));
        }
        if (emit(pattern, masterClass, DtstartPropType.class)) {
            if ((val.getNoStart() == null) || !val.getNoStart()) {
                DtstartPropType dtstart = (DtstartPropType) makeDateDatetime(new DtstartPropType(), val.getDtstart(), freeBusy | val.getForceUTC());
                pl.add(of.createDtstart(dtstart));
            }
        }
        if (emit(pattern, masterClass, FreebusyPropType.class)) {
            if (entityType == IcalDefs.entityTypeFreeAndBusy) {
                Collection<BwFreeBusyComponent> fbps = val.getFreeBusyPeriods();
                if (fbps != null) {
                    for (BwFreeBusyComponent fbc : fbps) {
                        FreebusyPropType fb = new FreebusyPropType();
                        /*
              int type = fbc.getType();
              FbtypeValueType fbtype;

              if (type == BwFreeBusyComponent.typeBusy) {
                fbtype = FbtypeValueType.BUSY;
              } else if (type == BwFreeBusyComponent.typeFree) {
                fbtype = FbtypeValueType.FREE;
              } else if (type == BwFreeBusyComponent.typeBusyUnavailable) {
                fbtype = FbtypeValueType.BUSY_UNAVAILABLE;
              } else if (type == BwFreeBusyComponent.typeBusyTentative) {
                fbtype = FbtypeValueType.BUSY_TENTATIVE;
              } else {
                fbtype = FbtypeValueType.BUSY;
  //              throw new CalFacadeException("Bad free-busy type " + type);
              }

              ArrayOfParameters pars = getAop(fb);

              FbtypeParamType f = new FbtypeParamType();
              f.setText(fbtype.name());
              */
                        ArrayOfParameters pars = getAop(fb);
                        FbtypeParamType f = new FbtypeParamType();
                        f.setText(BwFreeBusyComponent.fbtypes[fbc.getType()]);
                        JAXBElement<FbtypeParamType> param = of.createFbtype(f);
                        pars.getBaseParameter().add(param);
                        List<PeriodType> pdl = fb.getPeriod();
                        for (Period p : fbc.getPeriods()) {
                            PeriodType np = new PeriodType();
                            np.setStart(XcalUtil.getXMlUTCCal(p.getStart().toString()));
                            np.setEnd(XcalUtil.getXMlUTCCal(p.getEnd().toString()));
                            pdl.add(np);
                        }
                        pl.add(of.createFreebusy(fb));
                    }
                }
            }
        }
        if (emit(pattern, masterClass, GeoPropType.class)) {
            BwGeo geo = val.getGeo();
            if (geo != null) {
                GeoPropType g = new GeoPropType();
                g.setLatitude(geo.getLatitude().floatValue());
                g.setLatitude(geo.getLongitude().floatValue());
                pl.add(of.createGeo(g));
            }
        }
        if (emit(pattern, masterClass, LastModifiedPropType.class)) {
            LastModifiedPropType lm = new LastModifiedPropType();
            lm.setUtcDateTime(XcalUtil.getXMlUTCCal(val.getLastmod()));
            pl.add(of.createLastModified(lm));
        }
        if (emit(pattern, masterClass, LocationPropType.class)) {
            BwLocation loc = val.getLocation();
            if (loc != null) {
                LocationPropType l = new LocationPropType();
                l.setText(loc.getAddress().getValue());
                pl.add(of.createLocation((LocationPropType) langProp(uidProp(l, loc.getUid()), loc.getAddress())));
            }
        }
        if (emit(pattern, masterClass, OrganizerPropType.class)) {
            BwOrganizer org = val.getOrganizer();
            if (org != null) {
                pl.add(of.createOrganizer(makeOrganizer(org)));
            }
        }
        if (emit(pattern, masterClass, PercentCompletePropType.class)) {
            Integer pc = val.getPercentComplete();
            if (pc != null) {
                PercentCompletePropType p = new PercentCompletePropType();
                p.setInteger(BigInteger.valueOf(pc));
                pl.add(of.createPercentComplete(p));
            }
        }
        if (emit(pattern, masterClass, PriorityPropType.class)) {
            Integer prio = val.getPriority();
            if (prio != null) {
                PriorityPropType p = new PriorityPropType();
                p.setInteger(BigInteger.valueOf(prio));
                pl.add(of.createPriority(p));
            }
        }
        if (emit(pattern, masterClass, RelatedToPropType.class)) {
            BwRelatedTo relto = val.getRelatedTo();
            if (relto != null) {
                RelatedToPropType rt = new RelatedToPropType();
                rt.setUid(relto.getValue());
                if (relto.getRelType() != null) {
                    ArrayOfParameters pars = getAop(rt);
                    ReltypeParamType r = new ReltypeParamType();
                    r.setText(relto.getRelType());
                    JAXBElement<ReltypeParamType> param = of.createReltype(r);
                    pars.getBaseParameter().add(param);
                }
                pl.add(of.createRelatedTo(rt));
            }
        }
        if (emit(pattern, masterClass, ResourcesPropType.class)) {
            if (val.getNumResources() > 0) {
                /* This event has a resource */
                ResourcesPropType r = new ResourcesPropType();
                List<String> rl = r.getText();
                for (BwString str : val.getResources()) {
                    // LANG
                    rl.add(str.getValue());
                }
                pl.add(of.createResources(r));
            }
        }
        if (emit(pattern, masterClass, SequencePropType.class)) {
            if (val.getSequence() > 0) {
                SequencePropType s = new SequencePropType();
                s.setInteger(BigInteger.valueOf(val.getSequence()));
                pl.add(of.createSequence(s));
            }
        }
        if (emit(pattern, masterClass, StatusPropType.class)) {
            String status = val.getStatus();
            if ((status != null) && !status.equals(BwEvent.statusMasterSuppressed)) {
                StatusPropType s = new StatusPropType();
                s.setText(status);
                pl.add(of.createStatus(s));
            }
        }
        if (emit(pattern, masterClass, SummaryPropType.class)) {
            BwString bwstr = val.findSummary(null);
            if (bwstr != null) {
                SummaryPropType s = new SummaryPropType();
                s.setText(bwstr.getValue());
                s = (SummaryPropType) langProp(s, bwstr);
                pl.add(of.createSummary(s));
            }
        }
        if (emit(pattern, masterClass, TranspPropType.class)) {
            String strval = val.getTransparency();
            if ((strval != null) && (strval.length() > 0)) {
                TranspPropType t = new TranspPropType();
                t.setText(strval);
                pl.add(of.createTransp(t));
            }
        }
        if (emit(pattern, masterClass, UidPropType.class)) {
            UidPropType uid = new UidPropType();
            uid.setText(val.getUid());
            pl.add(of.createUid(uid));
        }
        if (emit(pattern, masterClass, UrlPropType.class)) {
            String strval = val.getLink();
            if (strval != null) {
                // Possibly drop this if we do it on input and check all data
                strval = strval.trim();
            }
            if ((strval != null) && (strval.length() > 0)) {
                UrlPropType u = new UrlPropType();
                u.setUri(strval);
                pl.add(of.createUrl(u));
            }
        }
        if (emit(pattern, masterClass, XBedeworkCostPropType.class)) {
            if (val.getCost() != null) {
                XBedeworkCostPropType c = new XBedeworkCostPropType();
                c.setText(val.getCost());
                pl.add(of.createXBedeworkCost(c));
            }
        }
        if (val.getNumXproperties() > 0) {
            try {
                xpropertiesToXcal(pl, val.getXproperties(), pattern, masterClass, wrapXprops);
            } catch (Throwable t) {
                // XXX For the moment swallow these.
                error(t);
            }
        }
        if (!isInstance && !isOverride && val.testRecurring()) {
            doRecurring(pattern, masterClass, val, pl);
        }
        return el;
    } catch (final CalFacadeException cfe) {
        throw cfe;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : PeriodType(ietf.params.xml.ns.icalendar_2.PeriodType) VfreebusyType(ietf.params.xml.ns.icalendar_2.VfreebusyType) RelatedToPropType(ietf.params.xml.ns.icalendar_2.RelatedToPropType) BwRelatedTo(org.bedework.calfacade.BwRelatedTo) TranspPropType(ietf.params.xml.ns.icalendar_2.TranspPropType) BwCategory(org.bedework.calfacade.BwCategory) BwString(org.bedework.calfacade.BwString) CreatedPropType(ietf.params.xml.ns.icalendar_2.CreatedPropType) DescriptionPropType(ietf.params.xml.ns.icalendar_2.DescriptionPropType) DurationPropType(ietf.params.xml.ns.icalendar_2.DurationPropType) UrlPropType(ietf.params.xml.ns.icalendar_2.UrlPropType) ArrayOfProperties(ietf.params.xml.ns.icalendar_2.ArrayOfProperties) BaseComponentType(ietf.params.xml.ns.icalendar_2.BaseComponentType) BasePropertyType(ietf.params.xml.ns.icalendar_2.BasePropertyType) LastModifiedPropType(ietf.params.xml.ns.icalendar_2.LastModifiedPropType) ResourcesPropType(ietf.params.xml.ns.icalendar_2.ResourcesPropType) CategoriesPropType(ietf.params.xml.ns.icalendar_2.CategoriesPropType) PriorityPropType(ietf.params.xml.ns.icalendar_2.PriorityPropType) BwAttachment(org.bedework.calfacade.BwAttachment) XBedeworkCostPropType(ietf.params.xml.ns.icalendar_2.XBedeworkCostPropType) PercentCompletePropType(ietf.params.xml.ns.icalendar_2.PercentCompletePropType) BwFreeBusyComponent(org.bedework.calfacade.BwFreeBusyComponent) SummaryPropType(ietf.params.xml.ns.icalendar_2.SummaryPropType) BwLocation(org.bedework.calfacade.BwLocation) RecurrenceIdPropType(ietf.params.xml.ns.icalendar_2.RecurrenceIdPropType) ArrayOfParameters(ietf.params.xml.ns.icalendar_2.ArrayOfParameters) Period(net.fortuna.ical4j.model.Period) VjournalType(ietf.params.xml.ns.icalendar_2.VjournalType) FreebusyPropType(ietf.params.xml.ns.icalendar_2.FreebusyPropType) JAXBElement(javax.xml.bind.JAXBElement) BwString(org.bedework.calfacade.BwString) BwContact(org.bedework.calfacade.BwContact) DtstartPropType(ietf.params.xml.ns.icalendar_2.DtstartPropType) VtodoType(ietf.params.xml.ns.icalendar_2.VtodoType) SequencePropType(ietf.params.xml.ns.icalendar_2.SequencePropType) LocationPropType(ietf.params.xml.ns.icalendar_2.LocationPropType) BwAttendee(org.bedework.calfacade.BwAttendee) GeoPropType(ietf.params.xml.ns.icalendar_2.GeoPropType) DuePropType(ietf.params.xml.ns.icalendar_2.DuePropType) BwDateTime(org.bedework.calfacade.BwDateTime) BwGeo(org.bedework.calfacade.BwGeo) StatusPropType(ietf.params.xml.ns.icalendar_2.StatusPropType) ContactPropType(ietf.params.xml.ns.icalendar_2.ContactPropType) DtstampPropType(ietf.params.xml.ns.icalendar_2.DtstampPropType) VeventType(ietf.params.xml.ns.icalendar_2.VeventType) ReltypeParamType(ietf.params.xml.ns.icalendar_2.ReltypeParamType) FbtypeParamType(ietf.params.xml.ns.icalendar_2.FbtypeParamType) BwOrganizer(org.bedework.calfacade.BwOrganizer) UidPropType(ietf.params.xml.ns.icalendar_2.UidPropType) CommentPropType(ietf.params.xml.ns.icalendar_2.CommentPropType) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BigInteger(java.math.BigInteger) CompletedPropType(ietf.params.xml.ns.icalendar_2.CompletedPropType) ClassPropType(ietf.params.xml.ns.icalendar_2.ClassPropType) BwStringBase(org.bedework.calfacade.base.BwStringBase) DtendPropType(ietf.params.xml.ns.icalendar_2.DtendPropType)

Example 2 with BwOrganizer

use of org.bedework.calfacade.BwOrganizer in project bw-calendar-engine by Bedework.

the class VEventUtil method toIcalComponent.

/**
 * Make an Icalendar component from a BwEvent object. This may produce a
 * VEvent, VTodo, VJournal or VPoll.
 *
 * @param ei the event
 * @param isOverride - true if event object is an override
 * @param tzreg - timezone registry
 * @param currentPrincipal - href for current authenticated user
 * @return Component
 * @throws CalFacadeException
 */
public static Component toIcalComponent(final EventInfo ei, final boolean isOverride, final TimeZoneRegistry tzreg, final String currentPrincipal) throws CalFacadeException {
    if ((ei == null) || (ei.getEvent() == null)) {
        return null;
    }
    final BwEvent val = ei.getEvent();
    boolean isInstance = false;
    try {
        Component xcomp = null;
        Calendar cal = null;
        final List<BwXproperty> xcompProps = val.getXproperties(BwXproperty.bedeworkIcal);
        if (!Util.isEmpty(xcompProps)) {
            final BwXproperty xcompProp = xcompProps.get(0);
            final String xcompPropVal = xcompProp.getValue();
            if (xcompPropVal != null) {
                final StringBuilder sb = new StringBuilder();
                final Icalendar ic = new Icalendar();
                try {
                    sb.append("BEGIN:VCALENDAR\n");
                    sb.append(Version.VERSION_2_0.toString());
                    sb.append("\n");
                    sb.append(xcompPropVal);
                    if (!xcompPropVal.endsWith("\n")) {
                        sb.append("\n");
                    }
                    sb.append("END:VCALENDAR\n");
                    CalendarBuilder bldr = new CalendarBuilder(new CalendarParserImpl(), ic);
                    UnfoldingReader ufrdr = new UnfoldingReader(new StringReader(sb.toString()), true);
                    cal = bldr.build(ufrdr);
                } catch (Throwable t) {
                    error(t);
                    error("Trying to parse:\n" + xcompPropVal);
                }
            }
        }
        Component comp;
        PropertyList pl = new PropertyList();
        boolean freeBusy = false;
        boolean vavail = false;
        boolean todo = false;
        boolean vpoll = false;
        int entityType = val.getEntityType();
        if (entityType == IcalDefs.entityTypeEvent) {
            comp = new VEvent(pl);
        } else if (entityType == IcalDefs.entityTypeTodo) {
            comp = new VToDo(pl);
            todo = true;
        } else if (entityType == IcalDefs.entityTypeJournal) {
            comp = new VJournal(pl);
        } else if (entityType == IcalDefs.entityTypeFreeAndBusy) {
            comp = new VFreeBusy(pl);
            freeBusy = true;
        } else if (entityType == IcalDefs.entityTypeVavailability) {
            comp = new VAvailability(pl);
            vavail = true;
        } else if (entityType == IcalDefs.entityTypeAvailable) {
            comp = new Available(pl);
        } else if (entityType == IcalDefs.entityTypeVpoll) {
            comp = new VPoll(pl);
            vpoll = true;
        } else {
            throw new CalFacadeException("org.bedework.invalid.entity.type", String.valueOf(entityType));
        }
        if (cal != null) {
            xcomp = cal.getComponent(comp.getName());
        }
        Property prop;
        /* ------------------- RecurrenceID --------------------
       * Done early so we know if this is an instance.
       */
        String strval = val.getRecurrenceId();
        if ((strval != null) && (strval.length() > 0)) {
            isInstance = true;
            pl.add(new RecurrenceId(makeZonedDt(val, strval)));
        }
        /* ------------------- Alarms -------------------- */
        VAlarmUtil.processEventAlarm(val, comp, currentPrincipal);
        /* ------------------- Attachments -------------------- */
        if (val.getNumAttachments() > 0) {
            for (BwAttachment att : val.getAttachments()) {
                pl.add(setAttachment(att));
            }
        }
        /* ------------------- Attendees -------------------- */
        if (!vpoll && (val.getNumAttendees() > 0)) {
            for (BwAttendee att : val.getAttendees()) {
                prop = setAttendee(att);
                mergeXparams(prop, xcomp);
                pl.add(prop);
            }
        }
        if (val.getNumCategories() > 0) {
            // LANG - filter on language - group language in one cat list?
            for (BwCategory cat : val.getCategories()) {
                prop = new Categories();
                TextList cl = ((Categories) prop).getCategories();
                cl.add(cat.getWord().getValue());
                pl.add(langProp(prop, cat.getWord()));
            }
        }
        /* ------------------- Class -------------------- */
        final String pval = val.getClassification();
        if (pval != null) {
            pl.add(new Clazz(pval));
        }
        if (val.getNumComments() > 0) {
            for (final BwString str : val.getComments()) {
                pl.add(langProp(new Comment(str.getValue()), str));
            }
        }
        if ((todo || vpoll) && (val.getCompleted() != null)) {
            prop = new Completed(new DateTime(val.getCompleted()));
            pl.add(prop);
        }
        if (val.getNumContacts() > 0) {
            for (final BwContact c : val.getContacts()) {
                // LANG
                prop = new Contact(c.getCn().getValue());
                final String l = c.getLink();
                if (l != null) {
                    prop.getParameters().add(new AltRep(l));
                }
                pl.add(langProp(uidProp(prop, c.getUid()), c.getCn()));
            }
        }
        if (val.getCost() != null) {
            IcalUtil.addXproperty(pl, BwXproperty.bedeworkCost, null, val.getCost());
        }
        /* ------------------- Created -------------------- */
        prop = new Created(val.getCreated());
        // if (pars.includeDateTimeProperty) {
        // prop.getParameters().add(Value.DATE_TIME);
        // }
        pl.add(prop);
        if (val.getDeleted()) {
            IcalUtil.addXproperty(pl, BwXproperty.bedeworkDeleted, null, String.valueOf(val.getDeleted()));
        }
        /* ------------------- Description -------------------- */
        BwStringBase bwstr = val.findDescription(null);
        if (bwstr != null) {
            pl.add(langProp(new Description(bwstr.getValue()), bwstr));
        }
        if (val.getEndType() == StartEndComponent.endTypeDate) {
            if (todo) {
                Due due = val.getDtend().makeDue(tzreg);
                if (freeBusy | val.getForceUTC()) {
                    due.setUtc(true);
                }
                pl.add(due);
            } else {
                DtEnd dtend = val.getDtend().makeDtEnd(tzreg);
                if (freeBusy | val.getForceUTC()) {
                    dtend.setUtc(true);
                }
                pl.add(dtend);
            }
        } else if (val.getEndType() == StartEndComponent.endTypeDuration) {
            addProperty(comp, new Duration(new Dur(val.getDuration())));
        }
        /* ------------------- DtStamp -------------------- */
        prop = new DtStamp(new DateTime(val.getDtstamp()));
        // if (pars.includeDateTimeProperty) {
        // prop.getParameters().add(Value.DATE_TIME);
        // }
        pl.add(prop);
        if (!val.getNoStart()) {
            DtStart dtstart = val.getDtstart().makeDtStart(tzreg);
            if (freeBusy | val.getForceUTC()) {
                dtstart.setUtc(true);
            }
            pl.add(dtstart);
        }
        if (freeBusy) {
            Collection<BwFreeBusyComponent> fbps = val.getFreeBusyPeriods();
            if (fbps != null) {
                for (BwFreeBusyComponent fbc : fbps) {
                    FreeBusy fb = new FreeBusy();
                    int type = fbc.getType();
                    if (type == BwFreeBusyComponent.typeBusy) {
                        addParameter(fb, FbType.BUSY);
                    } else if (type == BwFreeBusyComponent.typeFree) {
                        addParameter(fb, FbType.FREE);
                    } else if (type == BwFreeBusyComponent.typeBusyUnavailable) {
                        addParameter(fb, FbType.BUSY_UNAVAILABLE);
                    } else if (type == BwFreeBusyComponent.typeBusyTentative) {
                        addParameter(fb, FbType.BUSY_TENTATIVE);
                    } else {
                        throw new CalFacadeException("Bad free-busy type " + type);
                    }
                    PeriodList pdl = fb.getPeriods();
                    for (Period p : fbc.getPeriods()) {
                        // XXX inverse.ca plugin cannot handle durations.
                        Period np = new Period(p.getStart(), p.getEnd());
                        pdl.add(np);
                    }
                    pl.add(fb);
                }
            }
        }
        if (!vpoll) {
            BwGeo bwgeo = val.getGeo();
            if (bwgeo != null) {
                Geo geo = new Geo(bwgeo.getLatitude(), bwgeo.getLongitude());
                pl.add(geo);
            }
        }
        /* ------------------- LastModified -------------------- */
        prop = new LastModified(new DateTime(val.getLastmod()));
        // if (pars.includeDateTimeProperty) {
        // prop.getParameters().add(Value.DATE_TIME);
        // }
        pl.add(prop);
        if (!vpoll) {
            final BwLocation loc = val.getLocation();
            if (loc != null) {
                prop = new Location(loc.getCombinedValues());
                pl.add(langProp(uidProp(prop, loc.getUid()), loc.getAddress()));
                IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationAddr, null, loc.getAddressField());
                IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationRoom, null, loc.getRoomField());
                IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationAccessible, null, String.valueOf(loc.getAccessible()));
                IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationSfield1, null, loc.getSubField1());
                IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationSfield2, null, loc.getSubField2());
                IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationGeo, null, loc.getGeouri());
                IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationStreet, null, loc.getStreet());
                IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationCity, null, loc.getCity());
                IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationState, null, loc.getState());
                IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationZip, null, loc.getZip());
                IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationLink, null, loc.getLink());
            }
        }
        /* ------------------- Organizer -------------------- */
        BwOrganizer org = val.getOrganizer();
        if (org != null) {
            prop = setOrganizer(org);
            mergeXparams(prop, xcomp);
            pl.add(prop);
        }
        if (todo) {
            Integer pc = val.getPercentComplete();
            if (pc != null) {
                pl.add(new PercentComplete(pc.intValue()));
            }
        }
        /* ------------------- Priority -------------------- */
        Integer prio = val.getPriority();
        if (prio != null) {
            pl.add(new Priority(prio.intValue()));
        }
        /* ------------------- RDate -below------------------- */
        /* ------------------- RelatedTo -------------------- */
        /* We encode related to (maybe) as triples - reltype, value-type, value */
        String[] info = null;
        BwRelatedTo relto = val.getRelatedTo();
        if (relto != null) {
            info = new String[3];
            info[0] = relto.getRelType();
            // default
            info[1] = "";
            info[2] = relto.getValue();
        } else {
            String relx = val.getXproperty(BwXproperty.bedeworkRelatedTo);
            if (relx != null) {
                info = Util.decodeArray(relx);
            }
        }
        if (info != null) {
            int i = 0;
            while (i < info.length) {
                RelatedTo irelto;
                String reltype = info[i];
                String valtype = info[i + 1];
                String relval = info[i + 2];
                ParameterList rtpl = null;
                if (reltype.length() > 0) {
                    rtpl = new ParameterList();
                    rtpl.add(new RelType(reltype));
                }
                if (valtype.length() > 0) {
                    if (rtpl == null) {
                        rtpl = new ParameterList();
                    }
                    rtpl.add(new Value(valtype));
                }
                if (rtpl != null) {
                    irelto = new RelatedTo(rtpl, relval);
                } else {
                    irelto = new RelatedTo(relval);
                }
                pl.add(irelto);
                i += 3;
            }
        }
        if (val.getNumResources() > 0) {
            /* This event has a resource */
            prop = new Resources();
            TextList rl = ((Resources) prop).getResources();
            for (BwString str : val.getResources()) {
                // LANG
                rl.add(str.getValue());
            }
            pl.add(prop);
        }
        if (val.getSequence() > 0) {
            pl.add(new Sequence(val.getSequence()));
        }
        /* ------------------- Status -------------------- */
        String status = val.getStatus();
        if ((status != null) && !status.equals(BwEvent.statusMasterSuppressed)) {
            pl.add(new Status(status));
        }
        /* ------------------- Summary -------------------- */
        bwstr = val.findSummary(null);
        if (bwstr != null) {
            pl.add(langProp(new Summary(bwstr.getValue()), bwstr));
        }
        if (!todo && !vpoll) {
            strval = val.getPeruserTransparency(currentPrincipal);
            if ((strval != null) && (strval.length() > 0)) {
                pl.add(new Transp(strval));
            }
        }
        /* ------------------- Uid -------------------- */
        pl.add(new Uid(val.getUid()));
        /* ------------------- Url -------------------- */
        strval = val.getLink();
        if (strval != null) {
            // Possibly drop this if we do it on input and check all data
            strval = strval.trim();
        }
        if ((strval != null) && (strval.length() > 0)) {
            URI uri = Util.validURI(strval);
            if (uri != null) {
                pl.add(new Url(uri));
            }
        }
        if (val.getNumXproperties() > 0) {
            try {
                IcalUtil.xpropertiesToIcal(pl, val.getXproperties());
            } catch (Throwable t) {
                // XXX For the moment swallow these.
                error(t);
            }
        }
        if (!vpoll && !isInstance && !isOverride && val.testRecurring()) {
            doRecurring(val, pl);
        }
        if (vavail) {
            if (ei.getNumContainedItems() > 0) {
                final VAvailability va = (VAvailability) comp;
                for (final EventInfo aei : ei.getContainedItems()) {
                    va.getAvailable().add((Available) toIcalComponent(aei, false, tzreg, currentPrincipal));
                }
            }
            /* ----------- Vavailability - busyType ----------------- */
            String s = val.getBusyTypeString();
            if (s != null) {
                pl.add(new BusyType(s));
            }
        }
        if (vpoll) {
            final Integer ival = val.getPollWinner();
            if (ival != null) {
                pl.add(new PollWinner(ival));
            }
            strval = val.getPollAcceptResponse();
            if ((strval != null) && (strval.length() > 0)) {
                pl.add(new AcceptResponse(strval));
            }
            strval = val.getPollMode();
            if ((strval != null) && (strval.length() > 0)) {
                pl.add(new PollMode(strval));
            }
            strval = val.getPollProperties();
            if ((strval != null) && (strval.length() > 0)) {
                pl.add(new PollProperties(strval));
            }
            final Map<String, VVoter> vvoters = parseVpollVvoters(val);
            for (final VVoter vv : vvoters.values()) {
                ((VPoll) comp).getVoters().add(vv);
            }
            final Map<Integer, Component> comps = parseVpollCandidates(val);
            for (final Component candidate : comps.values()) {
                ((VPoll) comp).getCandidates().add(candidate);
            }
        }
        return comp;
    } catch (final CalFacadeException cfe) {
        throw cfe;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : FreeBusy(net.fortuna.ical4j.model.property.FreeBusy) VFreeBusy(net.fortuna.ical4j.model.component.VFreeBusy) BwRelatedTo(org.bedework.calfacade.BwRelatedTo) EventInfo(org.bedework.calfacade.svc.EventInfo) BwCategory(org.bedework.calfacade.BwCategory) BwString(org.bedework.calfacade.BwString) VAvailability(net.fortuna.ical4j.model.component.VAvailability) DateTime(net.fortuna.ical4j.model.DateTime) BwDateTime(org.bedework.calfacade.BwDateTime) TextList(net.fortuna.ical4j.model.TextList) LastModified(net.fortuna.ical4j.model.property.LastModified) DtStamp(net.fortuna.ical4j.model.property.DtStamp) AcceptResponse(net.fortuna.ical4j.model.property.AcceptResponse) Available(net.fortuna.ical4j.model.component.Available) BwAttachment(org.bedework.calfacade.BwAttachment) RelatedTo(net.fortuna.ical4j.model.property.RelatedTo) BwRelatedTo(org.bedework.calfacade.BwRelatedTo) VEvent(net.fortuna.ical4j.model.component.VEvent) Status(net.fortuna.ical4j.model.property.Status) BwFreeBusyComponent(org.bedework.calfacade.BwFreeBusyComponent) BwLocation(org.bedework.calfacade.BwLocation) VVoter(net.fortuna.ical4j.model.component.VVoter) Transp(net.fortuna.ical4j.model.property.Transp) Categories(net.fortuna.ical4j.model.property.Categories) Priority(net.fortuna.ical4j.model.property.Priority) BusyType(net.fortuna.ical4j.model.property.BusyType) PeriodList(net.fortuna.ical4j.model.PeriodList) Period(net.fortuna.ical4j.model.Period) Duration(net.fortuna.ical4j.model.property.Duration) BwString(org.bedework.calfacade.BwString) BwContact(org.bedework.calfacade.BwContact) Sequence(net.fortuna.ical4j.model.property.Sequence) Geo(net.fortuna.ical4j.model.property.Geo) BwGeo(org.bedework.calfacade.BwGeo) Uid(net.fortuna.ical4j.model.property.Uid) PollMode(net.fortuna.ical4j.model.property.PollMode) BwXproperty(org.bedework.calfacade.BwXproperty) Value(net.fortuna.ical4j.model.parameter.Value) ParameterList(net.fortuna.ical4j.model.ParameterList) RecurrenceId(net.fortuna.ical4j.model.property.RecurrenceId) Resources(net.fortuna.ical4j.model.property.Resources) BwAttendee(org.bedework.calfacade.BwAttendee) VToDo(net.fortuna.ical4j.model.component.VToDo) CalendarParserImpl(net.fortuna.ical4j.data.CalendarParserImpl) VJournal(net.fortuna.ical4j.model.component.VJournal) Description(net.fortuna.ical4j.model.property.Description) BwGeo(org.bedework.calfacade.BwGeo) AltRep(net.fortuna.ical4j.model.parameter.AltRep) BwEvent(org.bedework.calfacade.BwEvent) URI(java.net.URI) Url(net.fortuna.ical4j.model.property.Url) PollWinner(net.fortuna.ical4j.model.property.PollWinner) Created(net.fortuna.ical4j.model.property.Created) VPoll(net.fortuna.ical4j.model.component.VPoll) Due(net.fortuna.ical4j.model.property.Due) StringReader(java.io.StringReader) PollProperties(net.fortuna.ical4j.model.property.PollProperties) Clazz(net.fortuna.ical4j.model.property.Clazz) StartEndComponent(org.bedework.calfacade.base.StartEndComponent) Component(net.fortuna.ical4j.model.Component) BwFreeBusyComponent(org.bedework.calfacade.BwFreeBusyComponent) DateListProperty(net.fortuna.ical4j.model.property.DateListProperty) Property(net.fortuna.ical4j.model.Property) BwOrganizer(org.bedework.calfacade.BwOrganizer) Dur(net.fortuna.ical4j.model.Dur) Comment(net.fortuna.ical4j.model.property.Comment) RelType(net.fortuna.ical4j.model.parameter.RelType) VFreeBusy(net.fortuna.ical4j.model.component.VFreeBusy) Calendar(net.fortuna.ical4j.model.Calendar) UnfoldingReader(net.fortuna.ical4j.data.UnfoldingReader) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) Contact(net.fortuna.ical4j.model.property.Contact) BwContact(org.bedework.calfacade.BwContact) PropertyList(net.fortuna.ical4j.model.PropertyList) DtStart(net.fortuna.ical4j.model.property.DtStart) BwStringBase(org.bedework.calfacade.base.BwStringBase) PercentComplete(net.fortuna.ical4j.model.property.PercentComplete) Completed(net.fortuna.ical4j.model.property.Completed) Summary(net.fortuna.ical4j.model.property.Summary) DtEnd(net.fortuna.ical4j.model.property.DtEnd) BwLocation(org.bedework.calfacade.BwLocation) Location(net.fortuna.ical4j.model.property.Location)

Example 3 with BwOrganizer

use of org.bedework.calfacade.BwOrganizer in project bw-calendar-engine by Bedework.

the class Events method setScheduleState.

/* Flag this as an attendee scheduling object or an organizer scheduling object
   */
private void setScheduleState(final BwEvent ev, final boolean adding, final boolean schedulingInbox) throws CalFacadeException {
    ev.setOrganizerSchedulingObject(false);
    ev.setAttendeeSchedulingObject(false);
    if ((ev.getEntityType() != IcalDefs.entityTypeEvent) && (ev.getEntityType() != IcalDefs.entityTypeTodo) && (ev.getEntityType() != IcalDefs.entityTypeVpoll)) {
        // Not a possible scheduling entity
        return;
    }
    final BwOrganizer org = ev.getOrganizer();
    final Set<BwAttendee> atts = ev.getAttendees();
    if (Util.isEmpty(atts) || (org == null)) {
        return;
    }
    final String curPrincipal = getSvc().getPrincipal().getPrincipalRef();
    final Directories dirs = getSvc().getDirectories();
    AccessPrincipal evPrincipal = dirs.caladdrToPrincipal(org.getOrganizerUri());
    if ((evPrincipal != null) && (evPrincipal.getPrincipalRef().equals(curPrincipal))) {
        ev.setOrganizerSchedulingObject(true);
        /* If we are expanding groups do so here */
        final ChangeTable chg = ev.getChangeset(getPrincipalHref());
        final Set<BwAttendee> groups = new TreeSet<>();
        if (!schedulingInbox) {
            final ChangeTableEntry cte = chg.getEntry(PropertyInfoIndex.ATTENDEE);
            checkAttendees: for (final BwAttendee att : atts) {
                if (CuType.GROUP.getValue().equals(att.getCuType())) {
                    groups.add(att);
                }
                final AccessPrincipal attPrincipal = getSvc().getDirectories().caladdrToPrincipal(att.getAttendeeUri());
                if ((attPrincipal != null) && (attPrincipal.getPrincipalRef().equals(curPrincipal))) {
                    // It's us
                    continue;
                }
                if (att.getPartstat().equals(IcalDefs.partstatValNeedsAction)) {
                    continue;
                }
                if (adding) {
                    // Can't add an event with attendees set to accepted
                    att.setPartstat(IcalDefs.partstatValNeedsAction);
                    continue;
                }
                // Not adding event. Did we add attendee?
                if ((cte != null) && !Util.isEmpty(cte.getAddedValues())) {
                    for (final Object o : cte.getAddedValues()) {
                        final BwAttendee chgAtt = (BwAttendee) o;
                        if (chgAtt.getCn().equals(att.getCn())) {
                            att.setPartstat(IcalDefs.partstatValNeedsAction);
                            continue checkAttendees;
                        }
                    }
                }
            }
        }
        try {
            /* If this is a vpoll we need the vvoters as we are going to
           have to remove the group vvoter entry and clone it for the
           attendees we add.

           I think this will work for any poll mode - if not we may
           have to rethink this approach.
         */
            Map<String, VVoter> voters = null;
            final boolean vpoll;
            if (ev.getEntityType() == IcalDefs.entityTypeVpoll) {
                voters = IcalUtil.parseVpollVvoters(ev);
                // We'll add them all back
                ev.clearVvoters();
                vpoll = true;
            } else {
                vpoll = false;
            }
            for (final BwAttendee att : groups) {
                /* If the group is in one of our domains we can try to expand it.
           * We should leave it if it's an external id.
           */
                final Holder<Boolean> trunc = new Holder<>();
                final List<BwPrincipalInfo> groupPis = dirs.find(att.getAttendeeUri(), att.getCuType(), // expand
                true, trunc);
                if ((groupPis == null) || (groupPis.size() != 1)) {
                    continue;
                }
                final BwPrincipalInfo pi = groupPis.get(0);
                if (pi.getMembers() == null) {
                    continue;
                }
                VVoter groupVvoter = null;
                Voter groupVoter = null;
                PropertyList pl = null;
                if (vpoll) {
                    groupVvoter = voters.get(att.getAttendeeUri());
                    if (groupVvoter == null) {
                        if (debug) {
                            warn("No vvoter found for " + att.getAttendeeUri());
                        }
                        continue;
                    }
                    voters.remove(att.getAttendeeUri());
                    groupVoter = groupVvoter.getVoter();
                    pl = groupVvoter.getProperties();
                }
                // Remove the group
                ev.removeAttendee(att);
                chg.changed(PropertyInfoIndex.ATTENDEE, att, null);
                for (final BwPrincipalInfo mbrPi : pi.getMembers()) {
                    if (mbrPi.getCaladruri() == null) {
                        continue;
                    }
                    final BwAttendee mbrAtt = new BwAttendee();
                    mbrAtt.setType(att.getType());
                    mbrAtt.setAttendeeUri(mbrPi.getCaladruri());
                    mbrAtt.setCn(mbrPi.getEmail());
                    mbrAtt.setCuType(mbrPi.getKind());
                    mbrAtt.setMember(att.getAttendeeUri());
                    ev.addAttendee(mbrAtt);
                    chg.addValue(PropertyInfoIndex.ATTENDEE, mbrAtt);
                    if (vpoll) {
                        pl.remove(groupVoter);
                        groupVoter = IcalUtil.setVoter(mbrAtt);
                        pl.add(groupVoter);
                        ev.addVvoter(groupVvoter.toString());
                    }
                }
            }
            if (vpoll) {
                // Add back any remaining vvoters
                for (VVoter vv : voters.values()) {
                    ev.addVvoter(vv.toString());
                }
            }
        } catch (final CalFacadeException cfe) {
            throw cfe;
        } catch (final Throwable t) {
            throw new CalFacadeException(t);
        }
        if (ev instanceof BwEventProxy) {
            // Only add x-property to master
            return;
        }
        if (CalFacadeDefs.jasigSchedulingAssistant.equals(getPars().getClientId())) {
            ev.addXproperty(new BwXproperty(BwXproperty.bedeworkSchedAssist, null, "true"));
        }
        return;
    }
    for (final BwAttendee att : atts) {
        /* See if at least one attendee is us */
        evPrincipal = getSvc().getDirectories().caladdrToPrincipal(att.getAttendeeUri());
        if ((evPrincipal != null) && (evPrincipal.getPrincipalRef().equals(curPrincipal))) {
            ev.setAttendeeSchedulingObject(true);
            break;
        }
    }
}
Also used : VVoter(net.fortuna.ical4j.model.component.VVoter) Holder(javax.xml.ws.Holder) BwEventProxy(org.bedework.calfacade.BwEventProxy) AccessPrincipal(org.bedework.access.AccessPrincipal) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) Directories(org.bedework.calfacade.ifs.Directories) PropertyList(net.fortuna.ical4j.model.PropertyList) BwXproperty(org.bedework.calfacade.BwXproperty) ChangeTable(org.bedework.calfacade.util.ChangeTable) TreeSet(java.util.TreeSet) Voter(net.fortuna.ical4j.model.property.Voter) VVoter(net.fortuna.ical4j.model.component.VVoter) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) BwAttendee(org.bedework.calfacade.BwAttendee) BwPrincipalInfo(org.bedework.calfacade.BwPrincipalInfo) BwOrganizer(org.bedework.calfacade.BwOrganizer)

Example 4 with BwOrganizer

use of org.bedework.calfacade.BwOrganizer in project bw-calendar-engine by Bedework.

the class IcalUtil method setOrganizer.

/**
 * @param val
 * @return Organizer
 * @throws Throwable
 */
public static Organizer setOrganizer(final BwOrganizer val) throws Throwable {
    ParameterList pars = new ParameterList();
    String temp = val.getScheduleStatus();
    if (temp != null) {
        pars.add(new ScheduleStatus(temp));
    }
    temp = val.getCn();
    if (temp != null) {
        pars.add(new Cn(temp));
    }
    temp = val.getDir();
    if (temp != null) {
        pars.add(new Dir(temp));
    }
    temp = val.getLanguage();
    if (temp != null) {
        pars.add(new Language(temp));
    }
    temp = val.getSentBy();
    if (temp != null) {
        pars.add(new SentBy(temp));
    }
    Organizer prop = new Organizer(pars, val.getOrganizerUri());
    return prop;
}
Also used : Language(net.fortuna.ical4j.model.parameter.Language) BwOrganizer(org.bedework.calfacade.BwOrganizer) Organizer(net.fortuna.ical4j.model.property.Organizer) ParameterList(net.fortuna.ical4j.model.ParameterList) SentBy(net.fortuna.ical4j.model.parameter.SentBy) Cn(net.fortuna.ical4j.model.parameter.Cn) Dir(net.fortuna.ical4j.model.parameter.Dir) ScheduleStatus(net.fortuna.ical4j.model.parameter.ScheduleStatus)

Example 5 with BwOrganizer

use of org.bedework.calfacade.BwOrganizer in project bw-calendar-engine by Bedework.

the class BwFreeBusyUtil method toFreeBusy.

/**
 * @param cb
 * @param val
 * @return BwFreeBusy
 * @throws CalFacadeException
 */
public static EventInfo toFreeBusy(final IcalCallback cb, final VFreeBusy val) throws CalFacadeException {
    if (val == null) {
        return null;
    }
    boolean debug = getLog().isDebugEnabled();
    try {
        PropertyList pl = val.getProperties();
        if (pl == null) {
            // Empty VEvent
            return null;
        }
        BwEvent fb = new BwEventObj();
        EventInfo ei = new EventInfo(fb);
        ChangeTable chg = ei.getChangeset(cb.getPrincipal().getPrincipalRef());
        fb.setEntityType(IcalDefs.entityTypeFreeAndBusy);
        setDates(cb.getPrincipal().getPrincipalRef(), ei, (DtStart) pl.getProperty(Property.DTSTART), (DtEnd) pl.getProperty(Property.DTEND), (Duration) pl.getProperty(Property.DURATION));
        Iterator it = pl.iterator();
        while (it.hasNext()) {
            Property prop = (Property) it.next();
            String pval = prop.getValue();
            if ((pval != null) && (pval.length() == 0)) {
                pval = null;
            }
            PropertyInfoIndex pi = PropertyInfoIndex.fromName(prop.getName());
            if (pi == null) {
                debugMsg("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval);
                continue;
            }
            switch(pi) {
                case ATTENDEE:
                    /* ------------------- Attendee -------------------- */
                    BwAttendee att = getAttendee(cb, (Attendee) prop);
                    fb.addAttendee(att);
                    chg.addValue(pi, att);
                    break;
                case COMMENT:
                    /* ------------------- Comment -------------------- */
                    // LANG
                    fb.addComment(null, pval);
                    chg.addValue(pi, pval);
                case DTEND:
                    break;
                case DTSTAMP:
                    /* ------------------- DtStamp -------------------- */
                    chg.changed(pi, fb.getDtstamp(), pval);
                    fb.setDtstamp(pval);
                case DTSTART:
                    break;
                case FREEBUSY:
                    /* ------------------- freebusy -------------------- */
                    FreeBusy fbusy = (FreeBusy) prop;
                    PeriodList perpl = fbusy.getPeriods();
                    Parameter par = getParameter(fbusy, "FBTYPE");
                    int fbtype;
                    if (par == null) {
                        fbtype = BwFreeBusyComponent.typeBusy;
                    } else if (par.equals(FbType.BUSY)) {
                        fbtype = BwFreeBusyComponent.typeBusy;
                    } else if (par.equals(FbType.BUSY_TENTATIVE)) {
                        fbtype = BwFreeBusyComponent.typeBusyTentative;
                    } else if (par.equals(FbType.BUSY_UNAVAILABLE)) {
                        fbtype = BwFreeBusyComponent.typeBusyUnavailable;
                    } else if (par.equals(FbType.FREE)) {
                        fbtype = BwFreeBusyComponent.typeFree;
                    } else {
                        if (debug) {
                            debugMsg("Unsupported parameter " + par.getName());
                        }
                        throw new IcalMalformedException("parameter " + par.getName());
                    }
                    BwFreeBusyComponent fbc = new BwFreeBusyComponent();
                    fbc.setType(fbtype);
                    Iterator perit = perpl.iterator();
                    while (perit.hasNext()) {
                        Period per = (Period) perit.next();
                        fbc.addPeriod(per);
                    }
                    fb.addFreeBusyPeriod(fbc);
                    chg.addValue(pi, fbc);
                    break;
                case ORGANIZER:
                    /* ------------------- Organizer -------------------- */
                    BwOrganizer org = getOrganizer(cb, (Organizer) prop);
                    fb.setOrganizer(org);
                    chg.addValue(pi, org);
                    break;
                case UID:
                    /* ------------------- Uid -------------------- */
                    chg.changed(pi, fb.getUid(), pval);
                    fb.setUid(pval);
                    break;
                default:
                    if (debug) {
                        debugMsg("Unsupported property with class " + prop.getClass() + " and value " + pval);
                    }
            }
        }
        return ei;
    } catch (CalFacadeException cfe) {
        throw cfe;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : BwFreeBusyComponent(org.bedework.calfacade.BwFreeBusyComponent) EventInfo(org.bedework.calfacade.svc.EventInfo) VFreeBusy(net.fortuna.ical4j.model.component.VFreeBusy) FreeBusy(net.fortuna.ical4j.model.property.FreeBusy) PeriodList(net.fortuna.ical4j.model.PeriodList) Period(net.fortuna.ical4j.model.Period) BwEvent(org.bedework.calfacade.BwEvent) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) PropertyList(net.fortuna.ical4j.model.PropertyList) PropertyInfoIndex(org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex) ChangeTable(org.bedework.calfacade.util.ChangeTable) Iterator(java.util.Iterator) Parameter(net.fortuna.ical4j.model.Parameter) Property(net.fortuna.ical4j.model.Property) BwAttendee(org.bedework.calfacade.BwAttendee) BwEventObj(org.bedework.calfacade.BwEventObj) BwOrganizer(org.bedework.calfacade.BwOrganizer)

Aggregations

BwOrganizer (org.bedework.calfacade.BwOrganizer)18 BwAttendee (org.bedework.calfacade.BwAttendee)8 BwEvent (org.bedework.calfacade.BwEvent)8 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)8 EventInfo (org.bedework.calfacade.svc.EventInfo)8 Period (net.fortuna.ical4j.model.Period)5 PropertyList (net.fortuna.ical4j.model.PropertyList)5 VFreeBusy (net.fortuna.ical4j.model.component.VFreeBusy)5 BwFreeBusyComponent (org.bedework.calfacade.BwFreeBusyComponent)5 BwString (org.bedework.calfacade.BwString)5 PeriodList (net.fortuna.ical4j.model.PeriodList)4 Property (net.fortuna.ical4j.model.Property)4 FreeBusy (net.fortuna.ical4j.model.property.FreeBusy)4 ChangeTable (org.bedework.calfacade.util.ChangeTable)4 ParameterList (net.fortuna.ical4j.model.ParameterList)3 BwPrincipal (org.bedework.calfacade.BwPrincipal)3 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)3 VVoter (net.fortuna.ical4j.model.component.VVoter)2 BwAttachment (org.bedework.calfacade.BwAttachment)2 BwCategory (org.bedework.calfacade.BwCategory)2