@Test public void doesntFireWhenNonPatientDocumentsAreBeingCreated() throws ComponentLookupException { XWikiDocument doc = mock(XWikiDocument.class); when(doc.getXObject(Patient.CLASS_REFERENCE)).thenReturn(null); when(doc.getDocumentReference()).thenReturn(new DocumentReference("instance", "data", "P0000001")); PatientRepository repo = this.mocker.getInstance(PatientRepository.class); UserManager um = this.mocker.getInstance(UserManager.class); ObservationManager om = this.mocker.getInstance(ObservationManager.class); this.mocker.getComponentUnderTest().onEvent(new DocumentCreatingEvent(), doc, null); Mockito.verifyNoMoreInteractions(repo, um, om); }
@Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; BaseObject patientRecordObj = doc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null || "PatientTemplate".equals(doc.getDocumentReference().getName())) { return; } Patient patient = this.repo.load(doc); User user = this.userManager.getCurrentUser(); CancelableEvent patientEvent = new PatientCreatingEvent(patient, user); this.observationManager.notify(patientEvent, doc); if (patientEvent.isCanceled()) { } patientEvent = new PatientChangingEvent(patient, user); this.observationManager.notify(patientEvent, doc); if (patientEvent.isCanceled()) { } }
PatientCreatingEventSource implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; BaseObject patientRecordObj = doc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null || "PatientTemplate".equals(doc.getDocumentReference().getName())) { return; } Patient patient = this.repo.load(doc); User user = this.userManager.getCurrentUser(); CancelableEvent patientEvent = new PatientCreatingEvent(patient, user); this.observationManager.notify(patientEvent, doc); if (patientEvent.isCanceled()) { } patientEvent = new PatientChangingEvent(patient, user); this.observationManager.notify(patientEvent, doc); if (patientEvent.isCanceled()) { } } }
PatientCreatingEventSource implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; BaseObject patientRecordObj = doc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null || "PatientTemplate".equals(doc.getDocumentReference().getName())) { return; } Patient patient = this.repo.load(doc); User user = this.userManager.getCurrentUser(); CancelableEvent patientEvent = new PatientCreatingEvent(patient, user); this.observationManager.notify(patientEvent, doc); if (patientEvent.isCanceled()) { } patientEvent = new PatientChangingEvent(patient, user); this.observationManager.notify(patientEvent, doc); if (patientEvent.isCanceled()) { } }  }
PatientCreatingEventSource implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; BaseObject patientRecordObj = doc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null || "PatientTemplate".equals(doc.getDocumentReference().getName())) { return; } Patient patient = this.repo.load(doc); User user = this.userManager.getCurrentUser(); CancelableEvent patientEvent = new PatientCreatingEvent(patient, user); this.observationManager.notify(patientEvent, doc); if (patientEvent.isCanceled()) { } patientEvent = new PatientChangingEvent(patient, user); this.observationManager.notify(patientEvent, doc); if (patientEvent.isCanceled()) { } }  @Override String getName(); @Override List<Event> getEvents(); @Override void onEvent(Event event, Object source, Object data); }
PatientCreatingEventSource implements EventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; BaseObject patientRecordObj = doc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null || "PatientTemplate".equals(doc.getDocumentReference().getName())) { return; } Patient patient = this.repo.load(doc); User user = this.userManager.getCurrentUser(); CancelableEvent patientEvent = new PatientCreatingEvent(patient, user); this.observationManager.notify(patientEvent, doc); if (patientEvent.isCanceled()) { } patientEvent = new PatientChangingEvent(patient, user); this.observationManager.notify(patientEvent, doc); if (patientEvent.isCanceled()) { } }  @Override String getName(); @Override List<Event> getEvents(); @Override void onEvent(Event event, Object source, Object data);  }