Search in sources :

Example 1 with RelatedTo

use of net.fortuna.ical4j.model.property.RelatedTo 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 2 with RelatedTo

use of net.fortuna.ical4j.model.property.RelatedTo in project opencast by opencast.

the class CalendarGenerator method addEvent.

/**
 * Adds an SchedulerEvent as a new entry to this iCalendar
 *
 * @param mp
 *          {@link MediaPackage} of event
 * @param agentId
 *          the agent identifier
 * @param start
 *          the start date
 * @param end
 *          the end date
 * @param captureAgentMetadata
 *          properties for capture agent metadata
 *
 * @return true if the event could be added.
 */
public boolean addEvent(MediaPackage mp, DublinCoreCatalog catalog, String agentId, Date start, Date end, Date lastModified, String captureAgentMetadata) {
    String eventId = mp.getIdentifier().compact();
    logger.debug("Creating iCaleandar VEvent from scheduled event '{}'", eventId);
    DateTime startDate = new DateTime(start);
    DateTime endDate = new DateTime(end);
    Date marginEndDate = new org.joda.time.DateTime(endDate.getTime()).plusHours(1).toDate();
    if (marginEndDate.before(new Date())) {
        logger.debug("Event has already passed more than an hour, skipping!");
        return false;
    }
    startDate.setUtc(true);
    endDate.setUtc(true);
    String seriesID = null;
    VEvent event = new VEvent(startDate, endDate, catalog.getFirst(DublinCore.PROPERTY_TITLE));
    try {
        ParameterList pl = new ParameterList();
        if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_CREATOR))) {
            pl.add(new Cn(catalog.getFirst(DublinCore.PROPERTY_CREATOR)));
        }
        event.getProperties().add(new Uid(eventId));
        DateTime lastModifiedDate = new DateTime(lastModified);
        lastModifiedDate.setUtc(true);
        event.getProperties().add(new LastModified(lastModifiedDate));
        // TODO Organizer should be URI (email-address?) created fake address
        if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_CREATOR))) {
            URI organizer = new URI("mailto", catalog.getFirst(DublinCore.PROPERTY_CREATOR) + "@opencast.tld", null);
            event.getProperties().add(new Organizer(pl, organizer));
        }
        if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_DESCRIPTION))) {
            event.getProperties().add(new Description(catalog.getFirst(DublinCore.PROPERTY_DESCRIPTION)));
        }
        event.getProperties().add(new Location(agentId));
        if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_IS_PART_OF))) {
            seriesID = catalog.getFirst(DublinCore.PROPERTY_IS_PART_OF);
            event.getProperties().add(new RelatedTo(seriesID));
        }
        ParameterList dcParameters = new ParameterList();
        dcParameters.add(new FmtType("application/xml"));
        dcParameters.add(Value.BINARY);
        dcParameters.add(Encoding.BASE64);
        dcParameters.add(new XParameter("X-APPLE-FILENAME", "episode.xml"));
        Attach metadataAttachment = new Attach(dcParameters, catalog.toXmlString().getBytes("UTF-8"));
        event.getProperties().add(metadataAttachment);
        String seriesDC = getSeriesDublinCoreAsString(seriesID);
        if (seriesDC != null) {
            logger.debug("Attaching series {} information to event {}", seriesID, eventId);
            ParameterList sDcParameters = new ParameterList();
            sDcParameters.add(new FmtType("application/xml"));
            sDcParameters.add(Value.BINARY);
            sDcParameters.add(Encoding.BASE64);
            sDcParameters.add(new XParameter("X-APPLE-FILENAME", "series.xml"));
            Attach seriesAttachment = new Attach(sDcParameters, seriesDC.getBytes("UTF-8"));
            event.getProperties().add(seriesAttachment);
        } else {
            logger.debug("No series provided for event {}.", eventId);
        }
        ParameterList caParameters = new ParameterList();
        caParameters.add(new FmtType("application/text"));
        caParameters.add(Value.BINARY);
        caParameters.add(Encoding.BASE64);
        caParameters.add(new XParameter("X-APPLE-FILENAME", "org.opencastproject.capture.agent.properties"));
        Attach agentsAttachment = new Attach(caParameters, captureAgentMetadata.getBytes("UTF-8"));
        event.getProperties().add(agentsAttachment);
    } catch (Exception e) {
        logger.error("Unable to add event '{}' to recording calendar: {}", eventId, ExceptionUtils.getStackTrace(e));
        return false;
    }
    cal.getComponents().add(event);
    logger.debug("new VEvent = {} ", event.toString());
    return true;
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) Description(net.fortuna.ical4j.model.property.Description) Organizer(net.fortuna.ical4j.model.property.Organizer) Attach(net.fortuna.ical4j.model.property.Attach) Cn(net.fortuna.ical4j.model.parameter.Cn) URI(java.net.URI) DateTime(net.fortuna.ical4j.model.DateTime) Date(java.util.Date) SeriesException(org.opencastproject.series.api.SeriesException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) LastModified(net.fortuna.ical4j.model.property.LastModified) Uid(net.fortuna.ical4j.model.property.Uid) FmtType(net.fortuna.ical4j.model.parameter.FmtType) ParameterList(net.fortuna.ical4j.model.ParameterList) RelatedTo(net.fortuna.ical4j.model.property.RelatedTo) XParameter(net.fortuna.ical4j.model.parameter.XParameter) Location(net.fortuna.ical4j.model.property.Location)

Example 3 with RelatedTo

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

the class BwEventUtil method toEvent.

/**
 * We are going to try to construct a BwEvent object from a VEvent. This
 * may represent a new event or an update to a pre-existing event. In any
 * case, the VEvent probably has insufficient information to completely
 * reconstitute the event object so we'll get the uid first and retrieve
 * the event if it exists.
 *
 * <p>To put it another way we're doing a diff then update.
 *
 * <p>If it doesn't exist, we'll first fill in the appropriate fields,
 * (non-public, creator, created etc) then for both cases update the
 * remaining fields from the VEvent.
 *
 * <p>Recurring events present some challenges. If there is no recurrence
 * id the vevent represents the master entity which defines the recurrence
 * rules. If a recurrence id is present then the vevent represents a
 * recurrence instance override and we should not attempt to retrieve the
 * actual object but the referenced instance.
 *
 * <p>Also, note that we sorted the components first so we get the master
 * before any instances.
 *
 * <p>If DTSTART, RRULE, EXRULE have changed (also RDATE, EXDATE?) then any
 * existing overrides are unusable. We should delete all overrides and replace
 * with new ones.
 *
 * <p>For an update we have to keep track of which fields were present in
 * the vevent and set all absent fields to null in the BwEvent.
 *
 * @param cb          IcalCallback object
 * @param cal         Needed so we can retrieve the event.
 * @param ical        Icalendar we are converting. We check its events for
 *                    overrides.
 * @param val         VEvent object
 * @param diff        True if we should assume we are updating existing events.
 * @param mergeAttendees True if we should only update our own attendee.
 * @return EventInfo  object representing new entry or updated entry
 * @throws CalFacadeException
 */
public static EventInfo toEvent(final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean diff, final boolean mergeAttendees) throws CalFacadeException {
    if (val == null) {
        return null;
    }
    String currentPrincipal = null;
    final BwPrincipal principal = cb.getPrincipal();
    if (principal != null) {
        currentPrincipal = principal.getPrincipalRef();
    }
    final boolean debug = getLog().isDebugEnabled();
    @SuppressWarnings("unchecked") final Holder<Boolean> hasXparams = new Holder<Boolean>(Boolean.FALSE);
    final int methodType = ical.getMethodType();
    String attUri = null;
    if (mergeAttendees) {
        // We'll need this later.
        attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef());
    }
    final String colPath;
    if (cal == null) {
        colPath = null;
    } else {
        colPath = cal.getPath();
    }
    try {
        final PropertyList pl = val.getProperties();
        boolean vpoll = false;
        if (pl == null) {
            // Empty component
            return null;
        }
        final int entityType;
        if (val instanceof VEvent) {
            entityType = IcalDefs.entityTypeEvent;
        } else if (val instanceof VToDo) {
            entityType = IcalDefs.entityTypeTodo;
        } else if (val instanceof VJournal) {
            entityType = IcalDefs.entityTypeJournal;
        } else if (val instanceof VFreeBusy) {
            entityType = IcalDefs.entityTypeFreeAndBusy;
        } else if (val instanceof VAvailability) {
            entityType = IcalDefs.entityTypeVavailability;
        } else if (val instanceof Available) {
            entityType = IcalDefs.entityTypeAvailable;
        } else if (val instanceof VPoll) {
            entityType = IcalDefs.entityTypeVpoll;
            vpoll = true;
        } else {
            throw new CalFacadeException("org.bedework.invalid.component.type", val.getName());
        }
        Property prop;
        // Get the guid from the component
        String guid = null;
        prop = pl.getProperty(Property.UID);
        if (prop != null) {
            testXparams(prop, hasXparams);
            guid = prop.getValue();
        }
        if (guid == null) {
            /* XXX A guid is required - but are there devices out there without a
         *       guid - and if so how do we handle it?
         */
            throw new CalFacadeException(CalFacadeException.noGuid);
        }
        /* See if we have a recurrence id */
        BwDateTime ridObj = null;
        String rid = null;
        prop = pl.getProperty(Property.RECURRENCE_ID);
        if (prop != null) {
            testXparams(prop, hasXparams);
            ridObj = BwDateTime.makeBwDateTime((DateProperty) prop);
            if (ridObj.getRange() != null) {
                /* XXX What do I do with it? */
                warn("TRANS-TO_EVENT: Got a recurrence id range");
            }
            rid = ridObj.getDate();
        }
        EventInfo masterEI = null;
        EventInfo evinfo = null;
        BwEvent ev = null;
        /* If we have a recurrence id see if we already have the master (we should
       * get a master + all its overrides).
       *
       * If so find the override and use the annnotation or if no override,
       * make one.
       *
       * If no override retrieve the event, add it to our table and then locate the
       * annotation.
       *
       * If there is no annotation, create one.
       *
       * It's possible we have been sent 'detached' instances of a recurring
       * event. This may happen if we are invited to one or more instances of a
       * meeting. In this case we try to retrieve the master and if it doesn't
       * exist we manufacture one. We consider such an instance an update to
       * that instance only and leave the others alone.
       */
        /* We need this in a couple of places */
        final DtStart dtStart = (DtStart) pl.getProperty(Property.DTSTART);
        /* If this is a recurrence instance see if we can find the master
       */
        if (rid != null) {
            // See if we have a new master event. If so create a proxy to this event.
            masterEI = findMaster(guid, ical.getComponents());
            if (masterEI != null) {
                evinfo = masterEI.findOverride(rid);
            }
        }
        if (diff && (evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) {
            if (debug) {
                debugMsg("TRANS-TO_EVENT: try to fetch event with guid=" + guid);
            }
            final Collection<EventInfo> eis = cb.getEvent(colPath, guid);
            if (Util.isEmpty(eis)) {
            // do nothing
            } else if (eis.size() > 1) {
                // DORECUR - wrong again
                throw new CalFacadeException("More than one event returned for guid.");
            } else {
                evinfo = eis.iterator().next();
            }
            if (debug) {
                if (evinfo != null) {
                    debugMsg("TRANS-TO_EVENT: fetched event with guid");
                } else {
                    debugMsg("TRANS-TO_EVENT: did not find event with guid");
                }
            }
            if (evinfo != null) {
                if (rid != null) {
                    // We just retrieved it's master
                    masterEI = evinfo;
                    masterEI.setInstanceOnly(true);
                    evinfo = masterEI.findOverride(rid);
                    ical.addComponent(masterEI);
                } else if (methodType == ScheduleMethods.methodTypeCancel) {
                    // This should never have an rid for cancel of entire event.
                    evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed());
                } else {
                    // Presumably sent an update for the entire event. No longer suppressed master
                    evinfo.getEvent().setSuppressed(false);
                }
            } else if (rid != null) {
                /* Manufacture a master for the instance */
                masterEI = makeNewEvent(cb, entityType, guid, colPath);
                final BwEvent e = masterEI.getEvent();
                // XXX This seems bogus
                final DtStart mdtStart;
                final String bogusDate = "19980118";
                final String bogusTime = "T230000";
                final Parameter par = dtStart.getParameter("VALUE");
                final boolean isDateType = (par != null) && (par.equals(Value.DATE));
                if (isDateType) {
                    mdtStart = new DtStart(new Date(bogusDate));
                } else if (dtStart.isUtc()) {
                    mdtStart = new DtStart(bogusDate + bogusTime + "Z");
                } else if (dtStart.getTimeZone() == null) {
                    mdtStart = new DtStart(bogusDate + bogusTime);
                } else {
                    mdtStart = new DtStart(bogusDate + bogusTime + "Z", dtStart.getTimeZone());
                }
                setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null);
                e.setRecurring(true);
                // e.addRdate(ridObj);
                e.setSuppressed(true);
                ical.addComponent(masterEI);
                evinfo = masterEI.findOverride(rid);
                masterEI.setInstanceOnly(rid != null);
            }
        }
        if (evinfo == null) {
            evinfo = makeNewEvent(cb, entityType, guid, colPath);
        } else if (evinfo.getEvent().getEntityType() != entityType) {
            throw new CalFacadeException("org.bedework.mismatched.entity.type", val.toString());
        }
        final ChangeTable chg = evinfo.getChangeset(cb.getPrincipal().getPrincipalRef());
        if (rid != null) {
            final String evrid = evinfo.getEvent().getRecurrenceId();
            if ((evrid == null) || (!evrid.equals(rid))) {
                warn("Mismatched rid ev=" + evrid + " expected " + rid);
                // XXX spurious???
                chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid);
            }
            if (masterEI.getEvent().getSuppressed()) {
                masterEI.getEvent().addRdate(ridObj);
            }
        }
        ev = evinfo.getEvent();
        ev.setScheduleMethod(methodType);
        DtEnd dtEnd = null;
        if (entityType == IcalDefs.entityTypeTodo) {
            final Due due = (Due) pl.getProperty(Property.DUE);
            if (due != null) {
                dtEnd = new DtEnd(due.getParameters(), due.getValue());
            }
        } else {
            dtEnd = (DtEnd) pl.getProperty(Property.DTEND);
        }
        final Duration duration = (Duration) pl.getProperty(Property.DURATION);
        setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration);
        for (final Object aPl : pl) {
            prop = (Property) aPl;
            testXparams(prop, hasXparams);
            // debugMsg("ical prop " + prop.getClass().getName());
            String pval = prop.getValue();
            if ((pval != null) && (pval.length() == 0)) {
                pval = null;
            }
            final PropertyInfoIndex pi;
            if (prop instanceof XProperty) {
                pi = PropertyInfoIndex.XPROP;
            } else {
                pi = PropertyInfoIndex.fromName(prop.getName());
            }
            if (pi == null) {
                debugMsg("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval);
                continue;
            }
            chg.present(pi);
            switch(pi) {
                case ACCEPT_RESPONSE:
                    /* ------------------- Accept Response -------------------- */
                    String sval = ((AcceptResponse) prop).getValue();
                    if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) {
                        ev.setPollAcceptResponse(sval);
                    }
                    break;
                case ATTACH:
                    /* ------------------- Attachment -------------------- */
                    chg.addValue(pi, getAttachment((Attach) prop));
                    break;
                case ATTENDEE:
                    if (methodType == ScheduleMethods.methodTypePublish) {
                        if (cb.getStrictness() == IcalCallback.conformanceStrict) {
                            throw new CalFacadeException(CalFacadeException.attendeesInPublish);
                        }
                        if (cb.getStrictness() == IcalCallback.conformanceWarn) {
                        // warn("Had attendees for PUBLISH");
                        }
                    }
                    Attendee attPr = (Attendee) prop;
                    if (evinfo.getNewEvent() || !mergeAttendees) {
                        chg.addValue(pi, getAttendee(cb, attPr));
                    } else {
                        final String pUri = cb.getCaladdr(attPr.getValue());
                        if (pUri.equals(attUri)) {
                            /* Only update for our own attendee
               * We're doing a PUT and this must be the attendee updating their
               * partstat. We don't allow them to change other attendees
               * whatever the PUT content says.
               */
                            chg.addValue(pi, getAttendee(cb, attPr));
                        } else {
                            // Use the value we currently have
                            boolean found = false;
                            for (final BwAttendee att : ev.getAttendees()) {
                                if (pUri.equals(att.getAttendeeUri())) {
                                    chg.addValue(pi, att.clone());
                                    found = true;
                                    break;
                                }
                            }
                            if (!found) {
                                // An added attendee
                                final BwAttendee att = getAttendee(cb, attPr);
                                att.setPartstat(IcalDefs.partstatValNeedsAction);
                                chg.addValue(pi, att);
                            }
                        }
                    }
                    break;
                case BUSYTYPE:
                    int ibt = BwEvent.fromBusyTypeString(pval);
                    if (chg.changed(pi, ev.getBusyType(), ibt)) {
                        ev.setBusyType(ibt);
                    }
                    break;
                case CATEGORIES:
                    /* ------------------- Categories -------------------- */
                    Categories cats = (Categories) prop;
                    TextList cl = cats.getCategories();
                    String lang = getLang(cats);
                    if (cl != null) {
                        /* Got some categories */
                        Iterator cit = cl.iterator();
                        while (cit.hasNext()) {
                            String wd = (String) cit.next();
                            if (wd == null) {
                                continue;
                            }
                            BwString key = new BwString(lang, wd);
                            BwCategory cat = cb.findCategory(key);
                            if (cat == null) {
                                cat = BwCategory.makeCategory();
                                cat.setWord(key);
                                cb.addCategory(cat);
                            }
                            chg.addValue(pi, cat);
                        }
                    }
                    break;
                case CLASS:
                    if (chg.changed(pi, ev.getClassification(), pval)) {
                        ev.setClassification(pval);
                    }
                    break;
                case COMMENT:
                    /* ------------------- Comment -------------------- */
                    chg.addValue(pi, new BwString(null, pval));
                    break;
                case COMPLETED:
                    if (chg.changed(pi, ev.getCompleted(), pval)) {
                        ev.setCompleted(pval);
                    }
                    break;
                case CONTACT:
                    /* ------------------- Contact -------------------- */
                    String altrep = getAltRepPar(prop);
                    lang = getLang(prop);
                    String uid = getUidPar(prop);
                    BwString nm = new BwString(lang, pval);
                    BwContact contact = null;
                    if (uid != null) {
                        contact = cb.getContact(uid);
                    }
                    if (contact == null) {
                        contact = cb.findContact(nm);
                    }
                    if (contact == null) {
                        contact = BwContact.makeContact();
                        contact.setCn(nm);
                        contact.setLink(altrep);
                        cb.addContact(contact);
                    } else {
                        contact.setCn(nm);
                        contact.setLink(altrep);
                    }
                    chg.addValue(pi, contact);
                    break;
                case CREATED:
                    if (chg.changed(pi, ev.getCreated(), pval)) {
                        ev.setCreated(pval);
                    }
                    break;
                case DESCRIPTION:
                    if (chg.changed(pi, ev.getDescription(), pval)) {
                        ev.setDescription(pval);
                    }
                    break;
                case DTEND:
                    break;
                case DTSTAMP:
                    /* ------------------- DtStamp -------------------- */
                    ev.setDtstamp(pval);
                    break;
                case DTSTART:
                    break;
                case DURATION:
                    break;
                case EXDATE:
                    /* ------------------- ExDate -------------------- */
                    chg.addValues(pi, makeDateTimes((DateListProperty) prop));
                    break;
                case EXRULE:
                    /* ------------------- ExRule -------------------- */
                    chg.addValue(pi, pval);
                    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);
                    }
                    ev.addFreeBusyPeriod(fbc);
                    break;
                case GEO:
                    /* ------------------- Geo -------------------- */
                    Geo g = (Geo) prop;
                    BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude());
                    if (chg.changed(pi, ev.getGeo(), geo)) {
                        ev.setGeo(geo);
                    }
                    break;
                case LAST_MODIFIED:
                    if (chg.changed(pi, ev.getLastmod(), pval)) {
                        ev.setLastmod(pval);
                    }
                    break;
                case LOCATION:
                    /* ------------------- Location -------------------- */
                    BwLocation loc = null;
                    // String uid = getUidPar(prop);
                    /* At the moment Mozilla lightning is broken and this leads to all
           * sorts of problems.
            if (uid != null) {
              loc = cb.getLocation(uid);
            }
           */
                    lang = getLang(prop);
                    BwString addr = null;
                    if (pval != null) {
                        if (loc == null) {
                            addr = new BwString(lang, pval);
                            loc = cb.findLocation(addr);
                        }
                        if (loc == null) {
                            loc = BwLocation.makeLocation();
                            loc.setAddress(addr);
                            cb.addLocation(loc);
                        }
                    }
                    BwLocation evloc = ev.getLocation();
                    if (chg.changed(pi, evloc, loc)) {
                        // CHGTBL - this only shows that it's a different location object
                        ev.setLocation(loc);
                    } else if ((loc != null) && (evloc != null)) {
                        // See if the value is changed
                        String evval = evloc.getAddress().getValue();
                        String inval = loc.getAddress().getValue();
                        if (!evval.equals(inval)) {
                            chg.changed(pi, evval, inval);
                            evloc.getAddress().setValue(inval);
                        }
                    }
                    break;
                case ORGANIZER:
                    /* ------------------- Organizer -------------------- */
                    final BwOrganizer org = getOrganizer(cb, (Organizer) prop);
                    final BwOrganizer evorg = ev.getOrganizer();
                    final BwOrganizer evorgCopy;
                    if (evorg == null) {
                        evorgCopy = null;
                    } else {
                        evorgCopy = (BwOrganizer) evorg.clone();
                    }
                    if (chg.changed(pi, evorgCopy, org)) {
                        if (evorg == null) {
                            ev.setOrganizer(org);
                        } else {
                            evorg.update(org);
                        }
                    }
                    break;
                case PERCENT_COMPLETE:
                    /* ------------------- PercentComplete -------------------- */
                    Integer ival = ((PercentComplete) prop).getPercentage();
                    if (chg.changed(pi, ev.getPercentComplete(), ival)) {
                        ev.setPercentComplete(ival);
                    }
                    break;
                case POLL_MODE:
                    /* ------------------- Poll mode -------------------- */
                    sval = ((PollMode) prop).getValue();
                    if (chg.changed(pi, ev.getPollMode(), sval)) {
                        ev.setPollMode(sval);
                    }
                    break;
                case POLL_PROPERTIES:
                    /* ------------------- Poll properties ---------------- */
                    sval = ((PollProperties) prop).getValue();
                    if (chg.changed(pi, ev.getPollProperties(), sval)) {
                        ev.setPollProperties(sval);
                    }
                    break;
                case POLL_WINNER:
                    /* ------------------- Poll winner -------------------- */
                    ival = ((PollWinner) prop).getPollwinner();
                    if (chg.changed(pi, ev.getPollWinner(), ival)) {
                        ev.setPollWinner(ival);
                    }
                    break;
                case PRIORITY:
                    /* ------------------- Priority -------------------- */
                    ival = ((Priority) prop).getLevel();
                    if (chg.changed(pi, ev.getPriority(), ival)) {
                        ev.setPriority(ival);
                    }
                    break;
                case RDATE:
                    /* ------------------- RDate -------------------- */
                    chg.addValues(pi, makeDateTimes((DateListProperty) prop));
                    break;
                case RECURRENCE_ID:
                    break;
                case RELATED_TO:
                    /* ------------------- RelatedTo -------------------- */
                    final RelatedTo irelto = (RelatedTo) prop;
                    final BwRelatedTo relto = new BwRelatedTo();
                    final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE");
                    if (parval != null) {
                        relto.setRelType(parval);
                    }
                    relto.setValue(irelto.getValue());
                    if (chg.changed(pi, ev.getRelatedTo(), relto)) {
                        ev.setRelatedTo(relto);
                    }
                    break;
                case REQUEST_STATUS:
                    /* ------------------- RequestStatus -------------------- */
                    final BwRequestStatus rs = BwRequestStatus.fromRequestStatus((RequestStatus) prop);
                    chg.addValue(pi, rs);
                    break;
                case RESOURCES:
                    /* ------------------- Resources -------------------- */
                    final TextList rl = ((Resources) prop).getResources();
                    if (rl != null) {
                        /* Got some resources */
                        lang = getLang(prop);
                        Iterator rit = rl.iterator();
                        while (rit.hasNext()) {
                            BwString rsrc = new BwString(lang, (String) rit.next());
                            chg.addValue(pi, rsrc);
                        }
                    }
                    break;
                case RRULE:
                    /* ------------------- RRule -------------------- */
                    chg.addValue(pi, pval);
                    break;
                case SEQUENCE:
                    /* ------------------- Sequence -------------------- */
                    int seq = ((Sequence) prop).getSequenceNo();
                    if (seq != ev.getSequence()) {
                        chg.changed(pi, ev.getSequence(), seq);
                        ev.setSequence(seq);
                    }
                    break;
                case STATUS:
                    if (chg.changed(pi, ev.getStatus(), pval)) {
                        ev.setStatus(pval);
                    }
                    break;
                case SUMMARY:
                    if (chg.changed(pi, ev.getSummary(), pval)) {
                        ev.setSummary(pval);
                    }
                    break;
                case TRANSP:
                    if (chg.changed(pi, ev.getPeruserTransparency(cb.getPrincipal().getPrincipalRef()), pval)) {
                        BwXproperty pu = ev.setPeruserTransparency(cb.getPrincipal().getPrincipalRef(), pval);
                        if (pu != null) {
                            chg.addValue(PropertyInfoIndex.XPROP, pu);
                        }
                    }
                    break;
                case UID:
                    break;
                case URL:
                    if (chg.changed(pi, ev.getLink(), pval)) {
                        ev.setLink(pval);
                    }
                    break;
                case XPROP:
                    /* ------------------------- x-property --------------------------- */
                    final String name = prop.getName();
                    if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) {
                        if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) {
                            ev.setCost(pval);
                        }
                        break;
                    }
                    if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) {
                        if (checkCategory(cb, chg, ev, null, pval)) {
                            break;
                        }
                    }
                    if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) {
                        if (checkLocation(cb, chg, ev, prop)) {
                            break;
                        }
                    }
                    if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) {
                        if (checkContact(cb, chg, ev, null, pval)) {
                            break;
                        }
                    }
                    /* See if this is an x-category that can be
               converted to a real category
              */
                    final XProperty xp = (XProperty) prop;
                    chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters().toString(), pval));
                    break;
                default:
                    if (debug) {
                        debugMsg("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval);
                    }
            }
        }
        if (val instanceof VAvailability) {
            processAvailable(cb, cal, ical, (VAvailability) val, evinfo);
        } else if (!(val instanceof Available)) {
            VAlarmUtil.processComponentAlarms(cb, val, ev, currentPrincipal, chg);
            if (val instanceof VPoll) {
                processVvoters((VPoll) val, evinfo, cb, chg, mergeAttendees);
                processCandidates((VPoll) val, evinfo, chg);
            }
        }
        /* Fix up timestamps. */
        if (ev.getCreated() == null) {
            if (ev.getLastmod() != null) {
                ev.setCreated(ev.getLastmod());
                chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated());
            } else {
                ev.updateDtstamp();
                chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated());
                chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod());
            }
        }
        if (ev.getLastmod() == null) {
            // created cannot be null now
            ev.setLastmod(ev.getCreated());
            chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod());
        }
        processTimezones(ev, ical, chg);
        /* Remove any recipients and originator
       */
        if (ev.getRecipients() != null) {
            ev.getRecipients().clear();
        }
        ev.setOriginator(null);
        if (hasXparams.value) {
            /* Save a text copy of the entire event as an x-property */
            Component valCopy = val.copy();
            /* Remove potentially large values */
            prop = valCopy.getProperty(Property.DESCRIPTION);
            if (prop != null) {
                prop.setValue(null);
            }
            prop = valCopy.getProperty(Property.ATTACH);
            // Don't store the entire attachment - we just need the parameters.
            if (prop != null) {
                Value v = (Value) prop.getParameter(Parameter.VALUE);
                if (v != null) {
                    prop.setValue(String.valueOf(prop.getValue().hashCode()));
                }
            }
            chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString()));
        }
        chg.processChanges(ev, true);
        ev.setRecurring(new Boolean(ev.isRecurringEntity()));
        if (debug) {
            debugMsg(chg.toString());
            debugMsg(ev.toString());
        }
        if (masterEI != null) {
            // Just return null as this event is on its override list
            return null;
        }
        return evinfo;
    } catch (CalFacadeException cfe) {
        if (debug) {
            cfe.printStackTrace();
        }
        throw cfe;
    } catch (Throwable t) {
        if (debug) {
            t.printStackTrace();
        }
        throw new CalFacadeException(t);
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) FreeBusy(net.fortuna.ical4j.model.property.FreeBusy) VFreeBusy(net.fortuna.ical4j.model.component.VFreeBusy) BwRelatedTo(org.bedework.calfacade.BwRelatedTo) BwRequestStatus(org.bedework.calfacade.BwRequestStatus) DateProperty(net.fortuna.ical4j.model.property.DateProperty) BwCategory(org.bedework.calfacade.BwCategory) BwString(org.bedework.calfacade.BwString) VAvailability(net.fortuna.ical4j.model.component.VAvailability) TextList(net.fortuna.ical4j.model.TextList) AcceptResponse(net.fortuna.ical4j.model.property.AcceptResponse) Available(net.fortuna.ical4j.model.component.Available) RelatedTo(net.fortuna.ical4j.model.property.RelatedTo) BwRelatedTo(org.bedework.calfacade.BwRelatedTo) VEvent(net.fortuna.ical4j.model.component.VEvent) BwFreeBusyComponent(org.bedework.calfacade.BwFreeBusyComponent) BwLocation(org.bedework.calfacade.BwLocation) Categories(net.fortuna.ical4j.model.property.Categories) 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) BwPrincipal(org.bedework.calfacade.BwPrincipal) PropertyInfoIndex(org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex) BwXproperty(org.bedework.calfacade.BwXproperty) Value(net.fortuna.ical4j.model.parameter.Value) Resources(net.fortuna.ical4j.model.property.Resources) BwAttendee(org.bedework.calfacade.BwAttendee) VToDo(net.fortuna.ical4j.model.component.VToDo) VJournal(net.fortuna.ical4j.model.component.VJournal) BwDateTime(org.bedework.calfacade.BwDateTime) DateListProperty(net.fortuna.ical4j.model.property.DateListProperty) BwGeo(org.bedework.calfacade.BwGeo) BwEvent(org.bedework.calfacade.BwEvent) VPoll(net.fortuna.ical4j.model.component.VPoll) Due(net.fortuna.ical4j.model.property.Due) 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) BwOrganizer(org.bedework.calfacade.BwOrganizer) XProperty(net.fortuna.ical4j.model.property.XProperty) VFreeBusy(net.fortuna.ical4j.model.component.VFreeBusy) Attach(net.fortuna.ical4j.model.property.Attach) Holder(javax.xml.ws.Holder) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) Date(net.fortuna.ical4j.model.Date) BwAttendee(org.bedework.calfacade.BwAttendee) Attendee(net.fortuna.ical4j.model.property.Attendee) PropertyList(net.fortuna.ical4j.model.PropertyList) DtStart(net.fortuna.ical4j.model.property.DtStart) ChangeTable(org.bedework.calfacade.util.ChangeTable) PercentComplete(net.fortuna.ical4j.model.property.PercentComplete) Parameter(net.fortuna.ical4j.model.Parameter) XParameter(net.fortuna.ical4j.model.parameter.XParameter) DtEnd(net.fortuna.ical4j.model.property.DtEnd)

Aggregations

VEvent (net.fortuna.ical4j.model.component.VEvent)3 URI (java.net.URI)2 Component (net.fortuna.ical4j.model.Component)2 DateTime (net.fortuna.ical4j.model.DateTime)2 ParameterList (net.fortuna.ical4j.model.ParameterList)2 Period (net.fortuna.ical4j.model.Period)2 PeriodList (net.fortuna.ical4j.model.PeriodList)2 Property (net.fortuna.ical4j.model.Property)2 PropertyList (net.fortuna.ical4j.model.PropertyList)2 TextList (net.fortuna.ical4j.model.TextList)2 Available (net.fortuna.ical4j.model.component.Available)2 VAvailability (net.fortuna.ical4j.model.component.VAvailability)2 VFreeBusy (net.fortuna.ical4j.model.component.VFreeBusy)2 VJournal (net.fortuna.ical4j.model.component.VJournal)2 VPoll (net.fortuna.ical4j.model.component.VPoll)2 VToDo (net.fortuna.ical4j.model.component.VToDo)2 Value (net.fortuna.ical4j.model.parameter.Value)2 XParameter (net.fortuna.ical4j.model.parameter.XParameter)2 AcceptResponse (net.fortuna.ical4j.model.property.AcceptResponse)2 Attach (net.fortuna.ical4j.model.property.Attach)2