Search in sources :

Example 1 with BwIndexer

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

the class PrincipalProcessor method process.

/* (non-Javadoc)
   * @see org.bedework.indexer.crawler.Processor#process(java.lang.String)
   */
@Override
public void process() throws CalFacadeException {
    try (BwSvc bw = getBw()) {
        final CalSvcI svc = bw.getSvci();
        indexCollection(svc, svc.getCalendarsHandler().getHomePath());
        if (principal.equals(svc.getUsersHandler().getPublicUser().getPrincipalRef())) {
            return;
        }
        final BwIndexer indexer = svc.getIndexer(principal, indexRootPath);
        status.stats.inc(IndexedType.categories, svc.getCategoriesHandler().reindex(indexer));
        status.stats.inc(IndexedType.contacts, svc.getContactsHandler().reindex(indexer));
        status.stats.inc(IndexedType.locations, svc.getLocationsHandler().reindex(indexer));
    }
}
Also used : CalSvcI(org.bedework.calsvci.CalSvcI) BwIndexer(org.bedework.calfacade.indexing.BwIndexer)

Example 2 with BwIndexer

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

the class ProcessRealias method realiasEvents.

private boolean realiasEvents() throws Throwable {
    boolean add = false;
    boolean remove = false;
    BwXproperty xp = null;
    /* Expect from (possibly quoted)
     *        to  (possibly quoted)
     */
    try {
        open();
        final String fromHref = getAliasPath();
        if (fromHref == null) {
            return false;
        }
        final String wd = word();
        if (wd == null) {
            return false;
        }
        if ("remove".equals(wd)) {
            remove = true;
        } else {
            if ("add".equals(wd)) {
                add = true;
            } else if ("replace".equals(wd)) {
                remove = true;
            } else {
                error("Expect add | remove | replace");
                return false;
            }
            final BwCalendar col = getCal();
            if (col == null) {
                return false;
            }
            /* At the moment an alias is represented by an x-property with 
           the form:
           X-BEDEWORK-ALIAS; \
             X-BEDEWORK-PARAM-DISPLAYNAME=Jobs;\
             X-BEDEWORK-PARAM-PATH=/public/aliases/Browse By Topic/Jobs;\
             X-BEDEWORK-PARAM-ALIASPATH=/public/cals/MainCal:\
             /user/agrp_calsuite-MainCampus/Browse By Topic/Jobs"
        
           That is - it appears the displayname comes from the top level
           the path is what it points to
           the aliaspath is the path of the final target 
           the value is the path of the alias itself.
         */
            final BwCalendar aliasTarget = getAliasTarget(col);
            xp = new BwXproperty();
            xp.setName("X-BEDEWORK-ALIAS");
            xp.setPars("X-BEDEWORK-PARAM-DISPLAYNAME=" + col.getName() + ";X-BEDEWORK-PARAM-PATH=" + col.getAliasUri().substring(BwCalendar.internalAliasUriPrefix.length()) + ";X-BEDEWORK-PARAM-ALIASPATH=" + aliasTarget.getPath());
            xp.setValue(col.getPath());
        }
        final FilterBase fltr = parseQuery("topical_area=\"\t" + fromHref + "\"");
        if (fltr == null) {
            return false;
        }
        close();
        /* Now we need to process the stuff in batches */
        open();
        final BwIndexer idx = getIndexer();
        final SearchResult sr = idx.search(null, false, fltr, null, null, null, null, batchSize, includeDeleted, RecurringRetrievalMode.entityOnly);
        if (sr.getFound() == 0) {
            warn("No events found");
            return false;
        }
        for (; ; ) {
            final List<SearchResultEntry> sres = idx.getSearchResult(sr, BwIndexer.Position.next, PrivilegeDefs.privAny);
            if (Util.isEmpty(sres)) {
                break;
            }
            int updated = 0;
            for (final SearchResultEntry sre : sres) {
                final Object o = sre.getEntity();
                if (!(o instanceof EventInfo)) {
                    warn("Unhandled entity " + o.getClass());
                    continue;
                }
                EventInfo ei = (EventInfo) o;
                /* Fetch the persistent version
           */
                final String colPath = ei.getEvent().getColPath();
                final String name = ei.getEvent().getName();
                ei = getEvents().get(colPath, name);
                if (ei == null) {
                    warn("Unable to retrieve persistent copy of " + colPath + " " + name);
                    continue;
                }
                updated += doRealias(ei, fromHref, xp, add, remove);
                if ((updated % 10) == 0) {
                    info("done " + updated);
                }
            }
            info("Total updated: " + updated);
        }
        return true;
    } finally {
        close();
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) BwXproperty(org.bedework.calfacade.BwXproperty) BwIndexer(org.bedework.calfacade.indexing.BwIndexer) SearchResult(org.bedework.calfacade.indexing.SearchResult) BwCalendar(org.bedework.calfacade.BwCalendar) FilterBase(org.bedework.caldav.util.filter.FilterBase) SearchResultEntry(org.bedework.calfacade.indexing.SearchResultEntry)

Example 3 with BwIndexer

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

the class EventPropertiesImpl method getIndexer.

/* ====================================================================
   *                   Protected methods
   * ==================================================================== */
protected BwIndexer getIndexer(final boolean getPublic, final String ownerHref) throws CalFacadeException {
    String href = checkHref(ownerHref);
    final boolean publick = getPublic || isGuest() || isPublicAdmin();
    if (publick) {
        if (publicIndexer == null) {
            publicIndexer = getSvc().getIndexer(true);
        }
        return publicIndexer;
    }
    BwIndexer idx = userIndexers.get(href);
    if (idx != null) {
        return idx;
    }
    idx = getSvc().getIndexer(href);
    userIndexers.put(href, idx);
    return idx;
}
Also used : BwIndexer(org.bedework.calfacade.indexing.BwIndexer) BwString(org.bedework.calfacade.BwString)

Example 4 with BwIndexer

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

the class EntityProcessor method process.

/* (non-Javadoc)
   * @see java.lang.Thread#run()
   */
@Override
public void process() throws CalFacadeException {
    try {
        try (BwSvc bw = getBw()) {
            final CalSvcI svci = bw.getSvci();
            final BwIndexer indexer = svci.getIndexer(principal, indexRootPath);
            for (final String name : entityNames) {
                try {
                    if (debug) {
                        debug("Indexing collection " + path + " entity " + name);
                    }
                    status.stats.inc(IndexedType.events);
                    final EventInfo ent = svci.getEventsHandler().get(path, name);
                    if (ent == null) {
                        status.stats.inc(IndexedType.unreachableEntities);
                        continue;
                    }
                    indexer.indexEntity(ent);
                } catch (final Throwable t) {
                    Logger.getLogger(this.getClass()).error(this, t);
                    errors++;
                    if (errors > maxErrors) {
                        error("Too many errors (" + errors + "): terminating");
                        break;
                    }
                }
            }
        }
    } catch (final Throwable t) {
        Logger.getLogger(this.getClass()).error(t);
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) CalSvcI(org.bedework.calsvci.CalSvcI) BwIndexer(org.bedework.calfacade.indexing.BwIndexer)

Example 5 with BwIndexer

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

the class ProcessorBase method indexCollection.

protected void indexCollection(final CalSvcI svci, final String path) throws CalFacadeException {
    if (skipThis(path)) {
        if (debug) {
            debug("Skipping " + path);
        }
        return;
    }
    if (debug) {
        debug("indexCollection(" + path + ")");
    }
    status.currentStatus = "indexCollection(" + path + ")";
    status.stats.inc(IndexedType.collections);
    try {
        BwCalendar col = null;
        try {
            col = svci.getCalendarsHandler().get(path);
        } catch (final CalFacadeAccessException cfe) {
            error("No access to " + path);
        }
        if ((col == null) || !hasAccess(col)) {
            if (debug) {
                debug("path " + path + " not found");
            }
            return;
        }
        final BwIndexer indexer = svci.getIndexer(principal, indexRootPath);
        indexer.indexEntity(col);
        // close();
        final BwCalendar.CollectionInfo ci = col.getCollectionInfo();
        if (!ci.childrenAllowed) {
            return;
        }
        Refs refs = null;
        for (; ; ) {
            refs = getChildCollections(path, refs);
            if (refs == null) {
                break;
            }
            for (final String cpath : refs.refs) {
                indexCollection(svci, cpath);
            }
        }
        if (!ci.onlyCalEntities || !ci.indexable) {
            return;
        }
        refs = null;
        for (; ; ) {
            refs = getChildEntities(path, refs);
            if (refs == null) {
                break;
            }
            final EntityProcessor ep = new EntityProcessor(status, name + ":Entity", adminAccount, principal, entityDelay, path, refs.refs, indexRootPath);
            final IndexerThread eit = getEntityThread(ep);
            eit.start();
        }
    } catch (final Throwable t) {
        error(t);
    }
}
Also used : BwIndexer(org.bedework.calfacade.indexing.BwIndexer) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException)

Aggregations

BwIndexer (org.bedework.calfacade.indexing.BwIndexer)6 CalSvcI (org.bedework.calsvci.CalSvcI)3 BwCalendar (org.bedework.calfacade.BwCalendar)2 EventInfo (org.bedework.calfacade.svc.EventInfo)2 FilterBase (org.bedework.caldav.util.filter.FilterBase)1 BwString (org.bedework.calfacade.BwString)1 BwXproperty (org.bedework.calfacade.BwXproperty)1 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)1 SearchResult (org.bedework.calfacade.indexing.SearchResult)1 SearchResultEntry (org.bedework.calfacade.indexing.SearchResultEntry)1