@Test public void onDocumentTranslationUpdated() throws Exception { XWikiDocument translation = mock(XWikiDocument.class); DocumentReference translationReference = new DocumentReference("wiki", "Path", "Page", Locale.FRENCH); when(translation.getDocumentReferenceWithLocale()).thenReturn(translationReference); this.mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(), translation, null); verify(this.indexer).index(translationReference, false); verify(this.indexer, times(1)).index(any(EntityReference.class), any(Boolean.class)); }
@Override public void onEvent(Event event, Object source, Object data) { try { if (event instanceof DocumentUpdatedEvent) { XWikiDocument document = (XWikiDocument) source; if (Locale.ROOT.equals(document.getLocale())) { indexTranslations(document, (XWikiContext) data); } else { this.solrIndexer.get().index(document.getDocumentReferenceWithLocale(), false); } } else if (event instanceof DocumentCreatedEvent) { XWikiDocument document = (XWikiDocument) source; if (!Locale.ROOT.equals(document.getLocale())) { indexTranslations(document, (XWikiContext) data); } else { this.solrIndexer.get().index(document.getDocumentReferenceWithLocale(), false); } } else if (event instanceof DocumentDeletedEvent) { XWikiDocument document = ((XWikiDocument) source).getOriginalDocument(); this.solrIndexer.get().delete( new DocumentReference(document.getDocumentReference(), document.getRealLocale()), false); } else if (event instanceof AttachmentUpdatedEvent || event instanceof AttachmentAddedEvent) { XWikiDocument document = (XWikiDocument) source; String fileName = ((AbstractAttachmentEvent) event).getName(); XWikiAttachment attachment = document.getAttachment(fileName); this.solrIndexer.get().index(attachment.getReference(), false); } else if (event instanceof AttachmentDeletedEvent) { XWikiDocument document = ((XWikiDocument) source).getOriginalDocument(); String fileName = ((AbstractAttachmentEvent) event).getName(); XWikiAttachment attachment = document.getAttachment(fileName); this.solrIndexer.get().delete(attachment.getReference(), false); } else if (event instanceof XObjectUpdatedEvent || event instanceof XObjectAddedEvent) { EntityEvent entityEvent = (EntityEvent) event; this.solrIndexer.get().index(entityEvent.getReference(), false); } else if (event instanceof XObjectDeletedEvent) { EntityEvent entityEvent = (EntityEvent) event; this.solrIndexer.get().delete(entityEvent.getReference(), false); } else if (event instanceof XObjectPropertyUpdatedEvent || event instanceof XObjectPropertyAddedEvent) { EntityEvent entityEvent = (EntityEvent) event; this.solrIndexer.get().index(entityEvent.getReference(), false); } else if (event instanceof XObjectPropertyDeletedEvent) { EntityEvent entityEvent = (EntityEvent) event; this.solrIndexer.get().delete(entityEvent.getReference(), false); } else if (event instanceof WikiDeletedEvent) { String wikiName = (String) source; WikiReference wikiReference = new WikiReference(wikiName); this.solrIndexer.get().delete(wikiReference, false); } } catch (Exception e) { this.logger.error("Failed to handle event [{}] with source [{}]", event, source.toString(), e); } }
SolrIndexEventListener implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { try { if (event instanceof DocumentUpdatedEvent) { XWikiDocument document = (XWikiDocument) source; if (Locale.ROOT.equals(document.getLocale())) { indexTranslations(document, (XWikiContext) data); } else { this.solrIndexer.get().index(document.getDocumentReferenceWithLocale(), false); } } else if (event instanceof DocumentCreatedEvent) { XWikiDocument document = (XWikiDocument) source; if (!Locale.ROOT.equals(document.getLocale())) { indexTranslations(document, (XWikiContext) data); } else { this.solrIndexer.get().index(document.getDocumentReferenceWithLocale(), false); } } else if (event instanceof DocumentDeletedEvent) { XWikiDocument document = ((XWikiDocument) source).getOriginalDocument(); this.solrIndexer.get().delete( new DocumentReference(document.getDocumentReference(), document.getRealLocale()), false); } else if (event instanceof AttachmentUpdatedEvent || event instanceof AttachmentAddedEvent) { XWikiDocument document = (XWikiDocument) source; String fileName = ((AbstractAttachmentEvent) event).getName(); XWikiAttachment attachment = document.getAttachment(fileName); this.solrIndexer.get().index(attachment.getReference(), false); } else if (event instanceof AttachmentDeletedEvent) { XWikiDocument document = ((XWikiDocument) source).getOriginalDocument(); String fileName = ((AbstractAttachmentEvent) event).getName(); XWikiAttachment attachment = document.getAttachment(fileName); this.solrIndexer.get().delete(attachment.getReference(), false); } else if (event instanceof XObjectUpdatedEvent || event instanceof XObjectAddedEvent) { EntityEvent entityEvent = (EntityEvent) event; this.solrIndexer.get().index(entityEvent.getReference(), false); } else if (event instanceof XObjectDeletedEvent) { EntityEvent entityEvent = (EntityEvent) event; this.solrIndexer.get().delete(entityEvent.getReference(), false); } else if (event instanceof XObjectPropertyUpdatedEvent || event instanceof XObjectPropertyAddedEvent) { EntityEvent entityEvent = (EntityEvent) event; this.solrIndexer.get().index(entityEvent.getReference(), false); } else if (event instanceof XObjectPropertyDeletedEvent) { EntityEvent entityEvent = (EntityEvent) event; this.solrIndexer.get().delete(entityEvent.getReference(), false); } else if (event instanceof WikiDeletedEvent) { String wikiName = (String) source; WikiReference wikiReference = new WikiReference(wikiName); this.solrIndexer.get().delete(wikiReference, false); } } catch (Exception e) { this.logger.error("Failed to handle event [{}] with source [{}]", event, source.toString(), e); } } }
SolrIndexEventListener implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { try { if (event instanceof DocumentUpdatedEvent) { XWikiDocument document = (XWikiDocument) source; if (Locale.ROOT.equals(document.getLocale())) { indexTranslations(document, (XWikiContext) data); } else { this.solrIndexer.get().index(document.getDocumentReferenceWithLocale(), false); } } else if (event instanceof DocumentCreatedEvent) { XWikiDocument document = (XWikiDocument) source; if (!Locale.ROOT.equals(document.getLocale())) { indexTranslations(document, (XWikiContext) data); } else { this.solrIndexer.get().index(document.getDocumentReferenceWithLocale(), false); } } else if (event instanceof DocumentDeletedEvent) { XWikiDocument document = ((XWikiDocument) source).getOriginalDocument(); this.solrIndexer.get().delete( new DocumentReference(document.getDocumentReference(), document.getRealLocale()), false); } else if (event instanceof AttachmentUpdatedEvent || event instanceof AttachmentAddedEvent) { XWikiDocument document = (XWikiDocument) source; String fileName = ((AbstractAttachmentEvent) event).getName(); XWikiAttachment attachment = document.getAttachment(fileName); this.solrIndexer.get().index(attachment.getReference(), false); } else if (event instanceof AttachmentDeletedEvent) { XWikiDocument document = ((XWikiDocument) source).getOriginalDocument(); String fileName = ((AbstractAttachmentEvent) event).getName(); XWikiAttachment attachment = document.getAttachment(fileName); this.solrIndexer.get().delete(attachment.getReference(), false); } else if (event instanceof XObjectUpdatedEvent || event instanceof XObjectAddedEvent) { EntityEvent entityEvent = (EntityEvent) event; this.solrIndexer.get().index(entityEvent.getReference(), false); } else if (event instanceof XObjectDeletedEvent) { EntityEvent entityEvent = (EntityEvent) event; this.solrIndexer.get().delete(entityEvent.getReference(), false); } else if (event instanceof XObjectPropertyUpdatedEvent || event instanceof XObjectPropertyAddedEvent) { EntityEvent entityEvent = (EntityEvent) event; this.solrIndexer.get().index(entityEvent.getReference(), false); } else if (event instanceof XObjectPropertyDeletedEvent) { EntityEvent entityEvent = (EntityEvent) event; this.solrIndexer.get().delete(entityEvent.getReference(), false); } else if (event instanceof WikiDeletedEvent) { String wikiName = (String) source; WikiReference wikiReference = new WikiReference(wikiName); this.solrIndexer.get().delete(wikiReference, false); } } catch (Exception e) { this.logger.error("Failed to handle event [{}] with source [{}]", event, source.toString(), e); } }  }
SolrIndexEventListener implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { try { if (event instanceof DocumentUpdatedEvent) { XWikiDocument document = (XWikiDocument) source; if (Locale.ROOT.equals(document.getLocale())) { indexTranslations(document, (XWikiContext) data); } else { this.solrIndexer.get().index(document.getDocumentReferenceWithLocale(), false); } } else if (event instanceof DocumentCreatedEvent) { XWikiDocument document = (XWikiDocument) source; if (!Locale.ROOT.equals(document.getLocale())) { indexTranslations(document, (XWikiContext) data); } else { this.solrIndexer.get().index(document.getDocumentReferenceWithLocale(), false); } } else if (event instanceof DocumentDeletedEvent) { XWikiDocument document = ((XWikiDocument) source).getOriginalDocument(); this.solrIndexer.get().delete( new DocumentReference(document.getDocumentReference(), document.getRealLocale()), false); } else if (event instanceof AttachmentUpdatedEvent || event instanceof AttachmentAddedEvent) { XWikiDocument document = (XWikiDocument) source; String fileName = ((AbstractAttachmentEvent) event).getName(); XWikiAttachment attachment = document.getAttachment(fileName); this.solrIndexer.get().index(attachment.getReference(), false); } else if (event instanceof AttachmentDeletedEvent) { XWikiDocument document = ((XWikiDocument) source).getOriginalDocument(); String fileName = ((AbstractAttachmentEvent) event).getName(); XWikiAttachment attachment = document.getAttachment(fileName); this.solrIndexer.get().delete(attachment.getReference(), false); } else if (event instanceof XObjectUpdatedEvent || event instanceof XObjectAddedEvent) { EntityEvent entityEvent = (EntityEvent) event; this.solrIndexer.get().index(entityEvent.getReference(), false); } else if (event instanceof XObjectDeletedEvent) { EntityEvent entityEvent = (EntityEvent) event; this.solrIndexer.get().delete(entityEvent.getReference(), false); } else if (event instanceof XObjectPropertyUpdatedEvent || event instanceof XObjectPropertyAddedEvent) { EntityEvent entityEvent = (EntityEvent) event; this.solrIndexer.get().index(entityEvent.getReference(), false); } else if (event instanceof XObjectPropertyDeletedEvent) { EntityEvent entityEvent = (EntityEvent) event; this.solrIndexer.get().delete(entityEvent.getReference(), false); } else if (event instanceof WikiDeletedEvent) { String wikiName = (String) source; WikiReference wikiReference = new WikiReference(wikiName); this.solrIndexer.get().delete(wikiReference, false); } } catch (Exception e) { this.logger.error("Failed to handle event [{}] with source [{}]", event, source.toString(), e); } }  @Override List<Event> getEvents(); @Override String getName(); @Override void onEvent(Event event, Object source, Object data); }
SolrIndexEventListener implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { try { if (event instanceof DocumentUpdatedEvent) { XWikiDocument document = (XWikiDocument) source; if (Locale.ROOT.equals(document.getLocale())) { indexTranslations(document, (XWikiContext) data); } else { this.solrIndexer.get().index(document.getDocumentReferenceWithLocale(), false); } } else if (event instanceof DocumentCreatedEvent) { XWikiDocument document = (XWikiDocument) source; if (!Locale.ROOT.equals(document.getLocale())) { indexTranslations(document, (XWikiContext) data); } else { this.solrIndexer.get().index(document.getDocumentReferenceWithLocale(), false); } } else if (event instanceof DocumentDeletedEvent) { XWikiDocument document = ((XWikiDocument) source).getOriginalDocument(); this.solrIndexer.get().delete( new DocumentReference(document.getDocumentReference(), document.getRealLocale()), false); } else if (event instanceof AttachmentUpdatedEvent || event instanceof AttachmentAddedEvent) { XWikiDocument document = (XWikiDocument) source; String fileName = ((AbstractAttachmentEvent) event).getName(); XWikiAttachment attachment = document.getAttachment(fileName); this.solrIndexer.get().index(attachment.getReference(), false); } else if (event instanceof AttachmentDeletedEvent) { XWikiDocument document = ((XWikiDocument) source).getOriginalDocument(); String fileName = ((AbstractAttachmentEvent) event).getName(); XWikiAttachment attachment = document.getAttachment(fileName); this.solrIndexer.get().delete(attachment.getReference(), false); } else if (event instanceof XObjectUpdatedEvent || event instanceof XObjectAddedEvent) { EntityEvent entityEvent = (EntityEvent) event; this.solrIndexer.get().index(entityEvent.getReference(), false); } else if (event instanceof XObjectDeletedEvent) { EntityEvent entityEvent = (EntityEvent) event; this.solrIndexer.get().delete(entityEvent.getReference(), false); } else if (event instanceof XObjectPropertyUpdatedEvent || event instanceof XObjectPropertyAddedEvent) { EntityEvent entityEvent = (EntityEvent) event; this.solrIndexer.get().index(entityEvent.getReference(), false); } else if (event instanceof XObjectPropertyDeletedEvent) { EntityEvent entityEvent = (EntityEvent) event; this.solrIndexer.get().delete(entityEvent.getReference(), false); } else if (event instanceof WikiDeletedEvent) { String wikiName = (String) source; WikiReference wikiReference = new WikiReference(wikiName); this.solrIndexer.get().delete(wikiReference, false); } } catch (Exception e) { this.logger.error("Failed to handle event [{}] with source [{}]", event, source.toString(), e); } }  @Override List<Event> getEvents(); @Override String getName(); @Override void onEvent(Event event, Object source, Object data);  }