Search in sources :

Example 1 with PropertyInfoIndex

use of org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex 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 2 with PropertyInfoIndex

use of org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex in project bw-calendar-engine by Bedework.

the class RetrieveList method getRetrieveList.

public static List<BwIcalPropertyInfoEntry> getRetrieveList(final List<String> retrieveList) throws CalFacadeException {
    if (retrieveList == null) {
        return null;
    }
    // Convert property names to field names
    final List<BwIcalPropertyInfoEntry> retrieveListFields = new ArrayList<>(retrieveList.size() + BwIcalPropertyInfo.requiredPindexes.size());
    for (final String pname : retrieveList) {
        final PropertyInfoIndex pi;
        /* Special case etag for the moment */
        if (pname.equals(etagName)) {
            pi = PropertyInfoIndex.ETAG;
        } else {
            pi = PropertyInfoIndex.fromName(pname);
            if (pi == null) {
                continue;
            // throw new CalFacadeException(CalFacadeException.unknownProperty,
            // pname);
            }
        }
        final BwIcalPropertyInfoEntry ipie = BwIcalPropertyInfo.getPinfo(pi);
        if ((ipie == null) || (ipie.getMultiValued())) {
            // warn("Bad property " + pname);
            return null;
        }
        retrieveListFields.add(ipie);
    }
    for (final PropertyInfoIndex pi : BwIcalPropertyInfo.requiredPindexes) {
        retrieveListFields.add(BwIcalPropertyInfo.getPinfo(pi));
    }
    return retrieveListFields;
}
Also used : BwIcalPropertyInfoEntry(org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry) PropertyInfoIndex(org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex) ArrayList(java.util.ArrayList)

Example 3 with PropertyInfoIndex

use of org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex in project bw-calendar-engine by Bedework.

the class SimpleFilterParser method getProperty.

private List<PropertyInfo> getProperty(final int curtkn) throws ParseFailed {
    int tkn = curtkn;
    final List<PropertyInfo> pis = new ArrayList<>();
    for (; ; ) {
        if (tkn != StreamTokenizer.TT_WORD) {
            throw parseResult.fail("Expected Property Name: " + String.valueOf(tkn) + " source: " + source);
        }
        final String pname = tokenizer.sval;
        final String pnameUc = pname.toUpperCase();
        if ((pis.size() == 0) && pnameUc.equals("CATUID")) {
            // These are stored all over the place.
            pis.add(new PropertyInfo(PropertyInfoIndex.CATEGORIES, null, null));
            pis.add(new PropertyInfo(PropertyInfoIndex.UID, null, null));
            return pis;
        }
        final PropertyInfoIndex pi = PropertyInfoIndex.fromName(pname);
        if (pi == null) {
            throw parseResult.fail("unknown Property: " + pname + ": expr was " + currentExpr + " source: " + source);
        }
        // Check for indexed property
        Integer intIndex = null;
        String strIndex = null;
        tkn = nextToken("getProperty(index)");
        if (tkn == '[') {
            if (pis.size() > 0) {
                throw parseResult.fail("Unimplemented - indexing of nested fields: found" + String.valueOf(tkn) + " source: " + source);
            }
            // Expect an index or a quoted string
            tkn = nextToken("getProperty(index-1)");
            if (tkn == SfpTokenizer.TT_NUMBER) {
                intIndex = (int) tokenizer.nval;
            } else if ((tkn != '"') && (tkn != '\'')) {
                throw parseResult.fail("Expected number or quoted string: found" + String.valueOf(tkn) + " source: " + source);
            } else {
                strIndex = tokenizer.sval;
            }
            tkn = nextToken("end-getProperty(index)");
            if (tkn != ']') {
                throw parseResult.fail("Expected ']': found" + String.valueOf(tkn) + " source: " + source);
            }
            tkn = nextToken("getProperty");
        }
        pis.add(new PropertyInfo(pi, intIndex, strIndex));
        if (tkn != '.') {
            tokenizer.pushBack();
            return pis;
        }
        tkn = nextToken("getProperty: pname");
    }
}
Also used : PropertyInfoIndex(org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex) ArrayList(java.util.ArrayList) ToString(org.bedework.util.misc.ToString) BwIcalPropertyInfo(org.bedework.calfacade.ical.BwIcalPropertyInfo)

Example 4 with PropertyInfoIndex

use of org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex in project bw-calendar-engine by Bedework.

the class IcalTranslator method xmlProperty.

private void xmlProperty(final XmlEmit xml, final Property val) throws CalFacadeException {
    try {
        QName tag = openTag(xml, val.getName());
        ParameterList pl = val.getParameters();
        if (pl.size() > 0) {
            xml.openTag(XcalTags.parameters);
            Iterator pli = pl.iterator();
            while (pli.hasNext()) {
                xmlParameter(xml, (Parameter) pli.next());
            }
            xml.closeTag(XcalTags.parameters);
        }
        PropertyInfoIndex pii = PropertyInfoIndex.fromName(val.getName());
        QName ptype = XcalTags.textVal;
        if (pii != null) {
            DataType dtype = pii.getPtype();
            if (dtype != null) {
                ptype = dtype.getXcalType();
            }
        }
        if (ptype == null) {
            // Special processing I haven't done
            warn("Unimplemented value type for " + val.getName());
            ptype = XcalTags.textVal;
        }
        if (ptype.equals(XcalTags.recurVal)) {
            // Emit individual parts of recur rule
            xml.openTag(ptype);
            Recur r;
            if (val instanceof ExRule) {
                r = ((ExRule) val).getRecur();
            } else {
                r = ((RRule) val).getRecur();
            }
            xml.property(XcalTags.freq, r.getFrequency());
            xmlProp(xml, XcalTags.wkst, r.getWeekStartDay().name());
            if (r.getUntil() != null) {
                xmlProp(xml, XcalTags.until, r.getUntil().toString());
            }
            xmlProp(xml, XcalTags.count, String.valueOf(r.getCount()));
            xmlProp(xml, XcalTags.interval, String.valueOf(r.getInterval()));
            xmlProp(xml, XcalTags.bymonth, r.getMonthList());
            xmlProp(xml, XcalTags.byweekno, r.getWeekNoList());
            xmlProp(xml, XcalTags.byyearday, r.getYearDayList());
            xmlProp(xml, XcalTags.bymonthday, r.getMonthDayList());
            xmlProp(xml, XcalTags.byday, r.getDayList());
            xmlProp(xml, XcalTags.byhour, r.getHourList());
            xmlProp(xml, XcalTags.byminute, r.getMinuteList());
            xmlProp(xml, XcalTags.bysecond, r.getSecondList());
            xmlProp(xml, XcalTags.bysetpos, r.getSetPosList());
            xml.closeTag(ptype);
        } else {
            xml.property(ptype, val.getValue());
        }
        xml.closeTag(tag);
    } catch (CalFacadeException cfe) {
        throw cfe;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : PropertyInfoIndex(org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex) QName(javax.xml.namespace.QName) Iterator(java.util.Iterator) ParameterList(net.fortuna.ical4j.model.ParameterList) DataType(org.bedework.util.calendar.PropertyIndex.DataType) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) Recur(net.fortuna.ical4j.model.Recur) ExRule(net.fortuna.ical4j.model.property.ExRule)

Example 5 with PropertyInfoIndex

use of org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex in project bw-calendar-engine by Bedework.

the class BwFreeBusyUtil method toFreeBusy.

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

Aggregations

PropertyInfoIndex (org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex)19 ArrayList (java.util.ArrayList)6 BwEvent (org.bedework.calfacade.BwEvent)5 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)5 BwIcalPropertyInfoEntry (org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry)5 ChangeTable (org.bedework.calfacade.util.ChangeTable)5 BwCategory (org.bedework.calfacade.BwCategory)4 Iterator (java.util.Iterator)3 BwAttendee (org.bedework.calfacade.BwAttendee)3 BwCalendar (org.bedework.calfacade.BwCalendar)3 BwDateTime (org.bedework.calfacade.BwDateTime)3 TreeSet (java.util.TreeSet)2 Date (net.fortuna.ical4j.model.Date)2 Parameter (net.fortuna.ical4j.model.Parameter)2 Attach (net.fortuna.ical4j.model.property.Attach)2 DateListProperty (net.fortuna.ical4j.model.property.DateListProperty)2 DateProperty (net.fortuna.ical4j.model.property.DateProperty)2 EntityTypeFilter (org.bedework.caldav.util.filter.EntityTypeFilter)2 ObjectFilter (org.bedework.caldav.util.filter.ObjectFilter)2 BwContact (org.bedework.calfacade.BwContact)2