public void handleEvent(final Event event) { if (disabled) return; SolrClient solr = getSolrIndexClient(); PageEvent pageEvent = PageEvent.fromEvent(event); if (pageEvent == null) return; ResourceResolver resourceResolver = null; try { resourceResolver = resolverFactory.getAdministrativeResourceResolver(null); for (Iterator<PageModification> iter = pageEvent.getModifications(); iter.hasNext(); ) handlePageModification(iter.next(), solr, resourceResolver); } catch (Exception e) { LOG.error("Could not get ResourceResolver instance or handle page modification", e); return; } finally { if (resourceResolver != null && resourceResolver.isLive()) resourceResolver.close(); } }
@Override public void handleEvent(Event event) { if (pageIsNotIndexable(event)) { return; } PageEvent pageEvent = PageEvent.fromEvent(event); if (null == pageEvent) { return; } Iterator<PageModification> modifications = pageEvent.getModifications(); while (modifications.hasNext()) { PageModification modification = modifications.next(); String modificationPath = modification.getPath(); if (pageIsNotInObservedPath(modificationPath)) { return; } PageModification.ModificationType type = modification.getType(); if (type == PageModification.ModificationType.DELETED) { LOG.info("Page deleted {}", modificationPath); indexService.deleteTreeAndCommit(modification.getPath()); } else if (type == PageModification.ModificationType.CREATED) { LOG.info("Page created {}", modificationPath); addOrUpdatePage(modification); } else if (type == PageModification.ModificationType.MODIFIED) { LOG.info("Page modified {}", modificationPath); addOrUpdatePage(modification); } else if (type == PageModification.ModificationType.MOVED) { LOG.info("Page moved from '{}' to '{}'", modificationPath, modification.getDestination()); addOrUpdatePage(modification); indexService.deleteTreeAndCommit(modificationPath); } else { LOG.info("Unsupported page modification detected: '{}'", type); } } }