Search in sources :

Example 1 with BwDateTime

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

the class EntityFieldRule method dateTimeFld.

protected BwDateTime dateTimeFld(final DateTimeValues dtv) throws Exception {
    try {
        String tzid = dtv.tzid;
        if (tzid != null) {
            /* If this is a system timezone it's fine - otherwise try to convert to a
         * system timezone.
         */
            TimeZone tz = Timezones.getTz(tzid);
            if (tz == null) {
                globals.unmatchedTzids.add(tzid);
                tzid = null;
            } else if (!tzid.equals(tz.getID())) {
                globals.convertedTzids++;
                tzid = tz.getID();
            }
        }
        BwDateTime dtim = BwDateTime.makeBwDateTime(dtv.dateType, dtv.dtval, tzid);
        if (!dtv.date.equals(dtim.getDate())) {
            warn("At event " + (globals.counts[globals.events] + 1) + ": UTC mismatch - file=" + dtv.date + " calculated=" + dtim);
        }
        return dtim;
    } catch (Throwable t) {
        if (t instanceof Exception) {
            throw (Exception) t;
        }
        throw new Exception(t);
    }
}
Also used : TimeZone(net.fortuna.ical4j.model.TimeZone) BwDateTime(org.bedework.calfacade.BwDateTime) BwString(org.bedework.calfacade.BwString)

Example 2 with BwDateTime

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

the class BwObjectFilter method match.

/* ====================================================================
   *                   matching methods
   * ==================================================================== */
@Override
public boolean match(final Object o, final String userHref) throws WebdavException {
    ObjectFilter of = getEntity();
    Object ent = of.getEntity();
    boolean not = of.getNot();
    String val = null;
    Integer ival = null;
    if (ent instanceof BwCalendar) {
        val = ((BwCalendar) ent).getPath();
    } else if (ent instanceof String) {
        val = (String) ent;
    } else if (ent instanceof Integer) {
        ival = (Integer) ent;
    } else {
        throw new WebdavException("Unmatchable filter");
    }
    BwEvent ev = null;
    if (o instanceof BwEvent) {
        ev = (BwEvent) o;
    }
    if (of instanceof EntityTypeFilter) {
        if (ev == null) {
            return false;
        }
        if (not) {
            return ev.getEntityType() != ival;
        }
        return ev.getEntityType() == ival;
    }
    PropertyInfoIndex pii = of.getPropertyIndex();
    BwIcalPropertyInfoEntry pi = BwIcalPropertyInfo.getPinfo(pii);
    if (pi.getParam()) {
        pii = of.getParentPropertyIndex();
    }
    switch(pii) {
        case CLASS:
            if (ev.getClassification() == null) {
                return false;
            }
            return stringMatch(ev.getClassification(), val);
        case CREATED:
            return stringMatch(ev.getCreated(), val);
        case DESCRIPTION:
            for (BwLongString ls : ev.getDescriptions()) {
                if (stringMatch(ls.getValue(), val)) {
                    return true;
                }
            }
            return false;
        case DTSTAMP:
            return stringMatch(ev.getDtstamp(), val);
        case DTEND:
        /* Event only */
        case DUE:
            /* Todo only */
            return matchDateTime(pi, ev.getDtend(), val);
        case DTSTART:
            return matchDateTime(pi, ev.getDtstart(), val);
        case DURATION:
            return stringMatch(ev.getDuration(), val);
        case GEO:
            if (ev.getGeo() == null) {
                return false;
            }
            return stringMatch(ev.getGeo().toString(), val);
        case LAST_MODIFIED:
            return stringMatch(ev.getLastmod(), val);
        case LOCATION:
            if (ev.getLocation() == null) {
                return false;
            }
            return stringMatch(ev.getLocation().getAddress().getValue(), val);
        case ORGANIZER:
            if (ev.getOrganizer() == null) {
                return false;
            }
            return stringMatch(ev.getOrganizer().getOrganizerUri(), val);
        case PRIORITY:
            if (ev.getPriority() == null) {
                return false;
            }
            return stringMatch(String.valueOf(ev.getPriority()), val);
        case RECURRENCE_ID:
            if (ev.getRecurrenceId() == null) {
                return false;
            }
            return stringMatch(ev.getRecurrenceId(), val);
        case SEQUENCE:
            return stringMatch(String.valueOf(ev.getSequence()), val);
        case STATUS:
            if (ev.getStatus() == null) {
                return false;
            }
            return stringMatch(ev.getStatus(), val);
        case SUMMARY:
            for (BwString s : ev.getSummaries()) {
                if (stringMatch(s.getValue(), val)) {
                    return true;
                }
            }
            return false;
        case UID:
            return stringMatch(ev.getUid(), val);
        case URL:
            if (ev.getLink() == null) {
                return false;
            }
            return stringMatch(ev.getLink(), val);
        case TRANSP:
            try {
                if (ev.getPeruserTransparency(userHref) == null) {
                    return false;
                }
                return stringMatch(ev.getPeruserTransparency(userHref), val);
            } catch (Throwable t) {
                throw new WebdavException(t);
            }
        case COMPLETED:
            if (ev.getCompleted() == null) {
                return false;
            }
            return stringMatch(ev.getCompleted(), val);
        case PERCENT_COMPLETE:
            if (ev.getPercentComplete() == null) {
                return false;
            }
            return stringMatch(String.valueOf(ev.getPercentComplete()), val);
        case ATTACH:
            break;
        case ATTENDEE:
            break;
        case CATEGORIES:
            for (BwCategory cat : ev.getCategories()) {
                if (stringMatch(cat.getWordVal(), val)) {
                    return true;
                }
            }
            return false;
        case COMMENT:
            for (BwString s : ev.getComments()) {
                if (stringMatch(s.getValue(), val)) {
                    return true;
                }
            }
            return false;
        case CONTACT:
            for (BwContact c : ev.getContacts()) {
                if (stringMatch(c.getCn().getValue(), val)) {
                    return true;
                }
            }
            return false;
        case EXDATE:
            for (BwDateTime dt : ev.getExdates()) {
                if (stringMatch(dt.getDtval(), val)) {
                    return true;
                }
            }
            return false;
        case EXRULE:
            for (String s : ev.getExrules()) {
                if (stringMatch(s, val)) {
                    return true;
                }
            }
            return false;
        case REQUEST_STATUS:
            for (BwRequestStatus rs : ev.getRequestStatuses()) {
                if (stringMatch(rs.getCode(), val)) {
                    return true;
                }
            }
            return false;
        case RELATED_TO:
            if (ev.getRelatedTo() == null) {
                return false;
            }
            return stringMatch(ev.getRelatedTo().getValue(), val);
        case RESOURCES:
            for (BwString s : ev.getResources()) {
                if (stringMatch(s.getValue(), val)) {
                    return true;
                }
            }
            return false;
        case RDATE:
            for (BwDateTime dt : ev.getRdates()) {
                if (stringMatch(dt.getDtval(), val)) {
                    return true;
                }
            }
            return false;
        case RRULE:
            for (String s : ev.getRrules()) {
                if (stringMatch(s, val)) {
                    return true;
                }
            }
            return false;
        case FREEBUSY:
            break;
        case TZID:
            break;
        case TZNAME:
            break;
        case TZOFFSETFROM:
            break;
        case TZOFFSETTO:
            break;
        case TZURL:
            break;
        case ACTION:
            break;
        case REPEAT:
            break;
        case TRIGGER:
            break;
        case COLLECTION:
            return stringMatch(ev.getColPath(), val);
        case CREATOR:
            return stringMatch(ev.getCreatorHref(), val);
        case OWNER:
            return stringMatch(ev.getOwnerHref(), val);
        case ENTITY_TYPE:
            break;
    }
    return false;
}
Also used : BwDateTime(org.bedework.calfacade.BwDateTime) BwRequestStatus(org.bedework.calfacade.BwRequestStatus) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwCategory(org.bedework.calfacade.BwCategory) BwEvent(org.bedework.calfacade.BwEvent) ObjectFilter(org.bedework.caldav.util.filter.ObjectFilter) BwString(org.bedework.calfacade.BwString) BwLongString(org.bedework.calfacade.BwLongString) BwCalendar(org.bedework.calfacade.BwCalendar) BwString(org.bedework.calfacade.BwString) BwContact(org.bedework.calfacade.BwContact) EntityTypeFilter(org.bedework.caldav.util.filter.EntityTypeFilter) BwLongString(org.bedework.calfacade.BwLongString) PropertyInfoIndex(org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex) BwIcalPropertyInfoEntry(org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry)

Example 3 with BwDateTime

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

the class RecurUtil method fromRecurrencId.

/**
 * Generate a recurrence instance for the given master event
 * based on the recurrenceId and the date/time info in the master.
 *
 * @param master event
 * @param recurrenceId for the instance.
 * @return instance object filled in.
 * @throws CalFacadeException
 */
public static BwRecurrenceInstance fromRecurrencId(final BwEvent master, String recurrenceId) throws CalFacadeException {
    final String stzid = master.getDtstart().getTzid();
    final boolean dateOnly = master.getDtstart().getDateType();
    final BwDateTime rstart = BwDateTime.makeBwDateTime(dateOnly, recurrenceId, stzid);
    final BwDateTime rend = rstart.addDuration(BwDuration.makeDuration(master.getDuration()));
    final BwRecurrenceInstance ri = new BwRecurrenceInstance();
    ri.setDtstart(rstart);
    ri.setDtend(rend);
    ri.setRecurrenceId(ri.getDtstart().getDate());
    ri.setMaster(master);
    return ri;
}
Also used : BwRecurrenceInstance(org.bedework.calfacade.BwRecurrenceInstance) BwDateTime(org.bedework.calfacade.BwDateTime)

Example 4 with BwDateTime

use of org.bedework.calfacade.BwDateTime 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 5 with BwDateTime

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

the class Events method makeInstance.

private EventInfo makeInstance(final EventInfo ei, final String recurrenceId) throws CalFacadeException {
    final BwEvent ev = ei.getEvent();
    if (!ev.getRecurring()) {
        return ei;
    }
    if (!Util.isEmpty(ei.getOverrides())) {
        for (final EventInfo oei : ei.getOverrides()) {
            if (oei.getEvent().getRecurrenceId().equals(recurrenceId)) {
                oei.setRetrievedEvent(ei);
                oei.setCurrentAccess(ei.getCurrentAccess());
                return oei;
            }
        }
    }
    /* Not in the overrides - generate an instance */
    final BwDateTime rstart;
    final boolean dateOnly = ev.getDtstart().getDateType();
    if (dateOnly) {
        rstart = BwDateTime.makeBwDateTime(true, recurrenceId.substring(0, 8), null);
    } else {
        final String stzid = ev.getDtstart().getTzid();
        DateTime dt = null;
        try {
            dt = new DateTime(recurrenceId);
        } catch (final ParseException pe) {
            throw new CalFacadeException(pe);
        }
        final DtStart ds = ev.getDtstart().makeDtStart();
        dt.setTimeZone(ds.getTimeZone());
        rstart = BwDateTime.makeBwDateTime(dt);
    }
    final BwDateTime rend = rstart.addDuration(BwDuration.makeDuration(ev.getDuration()));
    final BwEventAnnotation ann = new BwEventAnnotation();
    ann.setDtstart(rstart);
    ann.setDtend(rend);
    ann.setRecurrenceId(recurrenceId);
    ann.setOwnerHref(ev.getOwnerHref());
    // Call it an override
    ann.setOverride(true);
    ann.setTombstoned(false);
    ann.setName(ev.getName());
    ann.setUid(ev.getUid());
    ann.setTarget(ev);
    ann.setMaster(ev);
    BwEvent proxy = new BwEventProxy(ann);
    EventInfo oei = new EventInfo(proxy);
    oei.setCurrentAccess(ei.getCurrentAccess());
    oei.setRetrievedEvent(ei);
    return oei;
}
Also used : DtStart(net.fortuna.ical4j.model.property.DtStart) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) EventInfo(org.bedework.calfacade.svc.EventInfo) BwDateTime(org.bedework.calfacade.BwDateTime) BwEventAnnotation(org.bedework.calfacade.BwEventAnnotation) BwEvent(org.bedework.calfacade.BwEvent) ParseException(java.text.ParseException) BwEventProxy(org.bedework.calfacade.BwEventProxy) DateTime(net.fortuna.ical4j.model.DateTime) BwDateTime(org.bedework.calfacade.BwDateTime) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

BwDateTime (org.bedework.calfacade.BwDateTime)45 BwEvent (org.bedework.calfacade.BwEvent)23 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)20 Period (net.fortuna.ical4j.model.Period)11 DateTime (net.fortuna.ical4j.model.DateTime)9 DtStart (net.fortuna.ical4j.model.property.DtStart)8 BwEventProxy (org.bedework.calfacade.BwEventProxy)8 BwRecurrenceInstance (org.bedework.calfacade.BwRecurrenceInstance)8 EventInfo (org.bedework.calfacade.svc.EventInfo)8 Date (net.fortuna.ical4j.model.Date)7 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)7 BwString (org.bedework.calfacade.BwString)7 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)7 Dur (net.fortuna.ical4j.model.Dur)6 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)6 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)6 RecurPeriods (org.bedework.icalendar.RecurUtil.RecurPeriods)6 TreeSet (java.util.TreeSet)5 ChangeTable (org.bedework.calfacade.util.ChangeTable)5 DateDatetimePropertyType (ietf.params.xml.ns.icalendar_2.DateDatetimePropertyType)4