/** Default constructor, sets up the listener name and the list of events to subscribe to. */ public PatientPushHistoryRemover() { super("patient-push-history-remover", new PatientDeletingEvent()); }
@Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; if (doc == null || "PatientTemplate".equals(doc.getDocumentReference().getName())) { return; } XWikiDocument odoc; try { odoc = (XWikiDocument) this.dab.getDocument(doc.getDocumentReference()); } catch (Exception e) { return; } BaseObject patientRecordObj = odoc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null) { return; } Patient patient = this.repo.load(odoc); User user = this.userManager.getCurrentUser(); CancelableEvent patientEvent = new PatientDeletingEvent(patient, user); this.observationManager.notify(patientEvent, odoc); if (patientEvent.isCanceled()) { // FIXME DocumentDeletingEvent is not cancelable yet! // ((CancelableEvent) event).cancel(); } } }
@Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; if (doc == null || "PatientTemplate".equals(doc.getDocumentReference().getName())) { return; } XWikiDocument odoc; try { odoc = (XWikiDocument) this.dab.getDocument(doc.getDocumentReference()); } catch (Exception e) { return; } BaseObject patientRecordObj = odoc.getXObject(Patient.CLASS_REFERENCE); if (patientRecordObj == null) { return; } Patient patient = this.repo.load(odoc); User user = this.userManager.getCurrentUser(); CancelableEvent patientEvent = new PatientDeletingEvent(patient, user); this.observationManager.notify(patientEvent, odoc); if (patientEvent.isCanceled()) { // FIXME DocumentDeletingEvent is not cancelable yet! // ((CancelableEvent) event).cancel(); } } }