Search in sources :

Example 11 with BwCategory

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

the class DocBuilder method indexCategories.

private void indexCategories(final Collection<BwCategory> cats) throws CalFacadeException {
    if (cats == null) {
        return;
    }
    try {
        startArray(getJname(PropertyInfoIndex.CATEGORIES));
        for (final BwCategory cat : cats) {
            startObject();
            cat.fixNames(basicSysprops, principal);
            makeField(PropertyInfoIndex.UID, cat.getUid());
            makeField(PropertyInfoIndex.HREF, cat.getHref());
            startArray(getJname(PropertyInfoIndex.VALUE));
            // Eventually may be more of these
            makeField((PropertyInfoIndex) null, cat.getWord());
            endArray();
            endObject();
        }
        endArray();
    } catch (final IndexException e) {
        throw new CalFacadeException(e);
    }
}
Also used : IndexException(org.bedework.util.indexing.IndexException) BwCategory(org.bedework.calfacade.BwCategory) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 12 with BwCategory

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

the class EntityBuilder method makeCat.

BwCategory makeCat() throws CalFacadeException {
    final BwCategory cat = new BwCategory();
    restoreSharedEntity(cat);
    cat.setName(getString(PropertyInfoIndex.NAME));
    cat.setUid(getString(PropertyInfoIndex.UID));
    cat.setWord((BwString) restoreBwString(PropertyInfoIndex.CATEGORIES, false));
    cat.setDescription((BwString) restoreBwString(PropertyInfoIndex.DESCRIPTION, false));
    return cat;
}
Also used : BwCategory(org.bedework.calfacade.BwCategory)

Example 13 with BwCategory

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

the class Filters method makeWhere.

/* Generate a where clause for a query which selects the events for the
   * given filter.
   *
   * @param f         Filter element.
   */
private void makeWhere(final FilterBase f) throws CalFacadeException {
    if ((f instanceof AndFilter) || (f instanceof OrFilter)) {
        boolean itsAnd = (f instanceof AndFilter);
        qseg.append('(');
        boolean first = true;
        for (FilterBase flt : f.getChildren()) {
            if (!first) {
                if (itsAnd) {
                    qseg.append(" and ");
                } else {
                    qseg.append(" or ");
                }
            }
            makeWhere(flt);
            first = false;
        }
        qseg.append(")");
    }
    if (f instanceof BwHrefFilter) {
        // Special case this
        qseg.append('(');
        qseg.append(masterName);
        qseg.append(".");
        qseg.append("colPath");
        qseg.append("=:");
        parTerm();
        qseg.append(" and ");
        qseg.append(masterName);
        qseg.append(".");
        qseg.append("name");
        qseg.append("=:");
        parTerm();
        qseg.append(')');
        queryLimited = true;
    } else if (f instanceof PropertyFilter) {
        PropertyFilter pf = (PropertyFilter) f;
        BwIcalPropertyInfoEntry pi = BwIcalPropertyInfo.getPinfo(pf.getPropertyIndex());
        if (pi == null) {
            throw new CalFacadeException("org.bedework.filters.unknownproperty", String.valueOf(pf.getPropertyIndex()));
        }
        String fieldName = pi.getDbFieldName();
        boolean multi = pi.getMultiValued();
        boolean param = pi.getParam();
        if (param) {
            BwIcalPropertyInfoEntry parentPi = BwIcalPropertyInfo.getPinfo(pf.getParentPropertyIndex());
            fieldName = parentPi.getDbFieldName() + "." + fieldName;
        }
        if (multi) {
            if (f instanceof PresenceFilter) {
                PresenceFilter prf = (PresenceFilter) f;
                // qseg.append("(size(");
                qseg.append("((select count(*) from ");
                qseg.append(masterName);
                qseg.append(".");
                qseg.append(fieldName);
                if (pi.getPresenceField() != null) {
                    qseg.append(".");
                    qseg.append(pi.getPresenceField());
                }
                qseg.append(")");
                if (prf.getTestPresent()) {
                    qseg.append(">0)");
                } else {
                    qseg.append("=0)");
                }
            } else if (pf instanceof TimeRangeFilter) {
                String fld = "joined_" + pi.getDbFieldName();
                String subfld = "unknown";
                if (pi.getPindex() == PropertyInfoIndex.VALARM) {
                    subfld = "triggerTime";
                }
                doTimeRange((TimeRangeFilter) pf, false, fld, subfld);
            } else if (pf instanceof BwCategoryFilter) {
                BwCategory cat = ((BwCategoryFilter) pf).getEntity();
                if (cat.unsaved()) {
                    ((BwCategoryFilter) pf).setEntity(cb.getCategory(cat.getUid()));
                }
                qseg.append("(:");
                parTerm();
                if (f.getNot()) {
                    qseg.append(" not");
                }
                qseg.append(" in elements(");
                qseg.append(masterName);
                qseg.append(".");
                qseg.append(fieldName);
                qseg.append("))");
            } else if (pf instanceof BwObjectFilter) {
                // String fld = "joined_" + pi.getField();
                String subfld = "value";
                // if (pi.getPindex() == PropertyInfoIndex.CATEGORIES) {
                // subfld = "word.value";
                // }
                doObject(((BwObjectFilter) pf).getEntity(), masterName, fieldName, subfld, true);
            } else {
                qseg.append("(:");
                parTerm();
                if (f.getNot()) {
                    qseg.append(" not");
                }
                qseg.append(" in elements(");
                qseg.append(masterName);
                qseg.append(".");
                qseg.append(fieldName);
                qseg.append("))");
            }
        // not multi follow
        } else if (f instanceof PresenceFilter) {
            PresenceFilter prf = (PresenceFilter) f;
            qseg.append('(');
            qseg.append(masterName);
            qseg.append(".");
            qseg.append(fieldName);
            if (prf.getTestPresent()) {
                qseg.append(" is not null");
            } else {
                qseg.append(" is null");
            }
            qseg.append(")");
        } else if (pf instanceof EntityTimeRangeFilter) {
            doEntityTimeRange((EntityTimeRangeFilter) pf);
        } else if (pf instanceof TimeRangeFilter) {
            doTimeRange((TimeRangeFilter) pf, (pi.getFieldType().getName().equals(BwDateTime.class.getName())), masterName, fieldName);
        } else if (pf instanceof BwObjectFilter) {
            doObject(((BwObjectFilter) pf).getEntity(), masterName, fieldName, null, false);
        } else {
            /* We assume we can't handle this one as a query.
         */
            throw new CalFacadeException("org.bedework.filters.unknownfilter", String.valueOf(f));
        }
    }
}
Also used : PresenceFilter(org.bedework.caldav.util.filter.PresenceFilter) BwDateTime(org.bedework.calfacade.BwDateTime) BwHrefFilter(org.bedework.calfacade.filter.BwHrefFilter) EntityTimeRangeFilter(org.bedework.caldav.util.filter.EntityTimeRangeFilter) TimeRangeFilter(org.bedework.caldav.util.filter.TimeRangeFilter) BwCategory(org.bedework.calfacade.BwCategory) BwCategoryFilter(org.bedework.calfacade.filter.BwCategoryFilter) OrFilter(org.bedework.caldav.util.filter.OrFilter) EntityTimeRangeFilter(org.bedework.caldav.util.filter.EntityTimeRangeFilter) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) AndFilter(org.bedework.caldav.util.filter.AndFilter) BwIcalPropertyInfoEntry(org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry) PropertyFilter(org.bedework.caldav.util.filter.PropertyFilter) FilterBase(org.bedework.caldav.util.filter.FilterBase) BwObjectFilter(org.bedework.calfacade.filter.BwObjectFilter)

Example 14 with BwCategory

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

the class Dumper method dumpCategories.

protected void dumpCategories(final boolean publick) throws CalFacadeException {
    try {
        makeDir(Defs.categoriesDirName, false);
        final Collection<BwCategory> cats;
        if (publick) {
            cats = getSvc().getCategoriesHandler().getPublic();
        } else {
            cats = getSvc().getCategoriesHandler().get();
        }
        for (final BwCategory cat : cats) {
            incCount(DumpGlobals.categories);
            final File catFile = makeFile(cat.getWordVal() + ".xml");
            cat.dump(catFile);
        }
    } finally {
        popPath();
    }
}
Also used : BwCategory(org.bedework.calfacade.BwCategory) File(java.io.File)

Example 15 with BwCategory

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

the class BwStringRule method end.

@Override
public void end(final String ns, final String name) throws Exception {
    if (name.equals("bwstring")) {
        // 3.5 onwards we wrapped with a tag. Do nothing
        return;
    }
    BwString entity = (BwString) pop();
    if (top() instanceof BwRequestStatus) {
        BwRequestStatus rs = (BwRequestStatus) top();
        rs.setDescription(entity);
        return;
    }
    if (top() instanceof BwCategory) {
        BwCategory cat = (BwCategory) top();
        if (name.equals("keyword")) {
            cat.setWord(entity);
        } else if (name.equals("desc")) {
            cat.setDescription(entity);
        } else {
            unknownTag(name);
        }
        return;
    }
    if (top() instanceof BwContact) {
        BwContact ent = (BwContact) top();
        if (name.equals("value")) {
            ent.setCn(entity);
        } else {
            unknownTag(name);
        }
        return;
    }
    if (top() instanceof BwLocation) {
        BwLocation loc = (BwLocation) top();
        if (name.equals("addr")) {
            loc.setAddress(entity);
        } else if (name.equals("subaddr")) {
            loc.setSubaddress(entity);
        } else {
            unknownTag(name);
        }
        return;
    }
    if (top() instanceof BwFilterDef) {
        BwFilterDef f = (BwFilterDef) top();
        if (name.equals("display-name")) {
            f.addDisplayName(entity);
        } else if (name.equals("subaddr")) {
            f.addDescription(new BwLongString(entity.getLang(), entity.getValue()));
        } else {
            unknownTag(name);
        }
        return;
    }
    if (top() instanceof BwAlarm) {
        BwAlarm a = (BwAlarm) top();
        if (name.equals("description")) {
            a.addDescription(entity);
            if (entity.getLang() != null) {
                a.addXproperty(new BwXproperty(entity.getLang(), null, entity.getValue()));
            } else {
                a.addDescription(entity);
            }
            return;
        }
        if (name.equals("summary")) {
            a.addSummary(entity);
        } else {
            unknownTag(name);
        }
        return;
    }
    EventInfo ei = (EventInfo) top();
    BwEvent e = ei.getEvent();
    if (e instanceof BwEventProxy) {
        e = ((BwEventProxy) e).getRef();
    }
    if (name.equals("comment")) {
        e.addComment(entity);
    } else if (name.equals("description")) {
        e.addDescription(new BwLongString(entity.getLang(), entity.getValue()));
    } else if (name.equals("resource")) {
        e.addResource(entity);
    } else if (name.equals("summary")) {
        e.addSummary(entity);
    } else {
        unknownTag(name);
    }
}
Also used : BwLongString(org.bedework.calfacade.BwLongString) BwLocation(org.bedework.calfacade.BwLocation) BwRequestStatus(org.bedework.calfacade.BwRequestStatus) EventInfo(org.bedework.calfacade.svc.EventInfo) BwXproperty(org.bedework.calfacade.BwXproperty) BwCategory(org.bedework.calfacade.BwCategory) BwFilterDef(org.bedework.calfacade.BwFilterDef) BwEvent(org.bedework.calfacade.BwEvent) BwString(org.bedework.calfacade.BwString) BwContact(org.bedework.calfacade.BwContact) BwEventProxy(org.bedework.calfacade.BwEventProxy) BwAlarm(org.bedework.calfacade.BwAlarm)

Aggregations

BwCategory (org.bedework.calfacade.BwCategory)42 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)13 BwContact (org.bedework.calfacade.BwContact)11 BwString (org.bedework.calfacade.BwString)11 BwCalendar (org.bedework.calfacade.BwCalendar)10 BwEvent (org.bedework.calfacade.BwEvent)10 BwLocation (org.bedework.calfacade.BwLocation)8 BwXproperty (org.bedework.calfacade.BwXproperty)7 ArrayList (java.util.ArrayList)6 EventInfo (org.bedework.calfacade.svc.EventInfo)6 BwDateTime (org.bedework.calfacade.BwDateTime)5 TreeSet (java.util.TreeSet)4 BwAttendee (org.bedework.calfacade.BwAttendee)4 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)4 PropertyInfoIndex (org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex)4 Period (net.fortuna.ical4j.model.Period)3 BwEventProxy (org.bedework.calfacade.BwEventProxy)3 BwIcalPropertyInfoEntry (org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry)3 FilterBase (org.bedework.caldav.util.filter.FilterBase)2 ObjectFilter (org.bedework.caldav.util.filter.ObjectFilter)2