@Test public void onEventWithExistingOwnerDoesNothing() throws Exception { BaseObject ownerObject = mock(BaseObject.class); when(this.doc.getXObject(Owner.CLASS_REFERENCE)).thenReturn(ownerObject); this.mocker.getComponentUnderTest().onEvent(new PatientCreatingEvent(), this.doc, null); verify(this.doc, Mockito.never()).newXObject(Owner.CLASS_REFERENCE, this.context); verifyZeroInteractions(ownerObject); }
@Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; XWikiContext context = (XWikiContext) this.execution.getContext().getProperty("xwikicontext"); try { if (doc.getXObject(Owner.CLASS_REFERENCE) != null) { return; } BaseObject ownerObject = doc.newXObject(Owner.CLASS_REFERENCE, context); if (doc.getCreatorReference() != null) { ownerObject.setStringValue(OWNER, doc.getCreatorReference().toString()); } else { ownerObject.setStringValue(OWNER, ""); } } catch (XWikiException ex) { this.logger.error("Failed to set the initial owner for entity [{}]: {}", doc.getDocumentReference(), ex.getMessage(), ex); } }
OwnerUpdateEventListener extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; XWikiContext context = (XWikiContext) this.execution.getContext().getProperty("xwikicontext"); try { if (doc.getXObject(Owner.CLASS_REFERENCE) != null) { return; } BaseObject ownerObject = doc.newXObject(Owner.CLASS_REFERENCE, context); if (doc.getCreatorReference() != null) { ownerObject.setStringValue(OWNER, doc.getCreatorReference().toString()); } else { ownerObject.setStringValue(OWNER, ""); } } catch (XWikiException ex) { this.logger.error("Failed to set the initial owner for entity [{}]: {}", doc.getDocumentReference(), ex.getMessage(), ex); } } }
OwnerUpdateEventListener extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; XWikiContext context = (XWikiContext) this.execution.getContext().getProperty("xwikicontext"); try { if (doc.getXObject(Owner.CLASS_REFERENCE) != null) { return; } BaseObject ownerObject = doc.newXObject(Owner.CLASS_REFERENCE, context); if (doc.getCreatorReference() != null) { ownerObject.setStringValue(OWNER, doc.getCreatorReference().toString()); } else { ownerObject.setStringValue(OWNER, ""); } } catch (XWikiException ex) { this.logger.error("Failed to set the initial owner for entity [{}]: {}", doc.getDocumentReference(), ex.getMessage(), ex); } } OwnerUpdateEventListener(); }
OwnerUpdateEventListener extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; XWikiContext context = (XWikiContext) this.execution.getContext().getProperty("xwikicontext"); try { if (doc.getXObject(Owner.CLASS_REFERENCE) != null) { return; } BaseObject ownerObject = doc.newXObject(Owner.CLASS_REFERENCE, context); if (doc.getCreatorReference() != null) { ownerObject.setStringValue(OWNER, doc.getCreatorReference().toString()); } else { ownerObject.setStringValue(OWNER, ""); } } catch (XWikiException ex) { this.logger.error("Failed to set the initial owner for entity [{}]: {}", doc.getDocumentReference(), ex.getMessage(), ex); } } OwnerUpdateEventListener(); @Override void onEvent(Event event, Object source, Object data); }
OwnerUpdateEventListener extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { XWikiDocument doc = (XWikiDocument) source; XWikiContext context = (XWikiContext) this.execution.getContext().getProperty("xwikicontext"); try { if (doc.getXObject(Owner.CLASS_REFERENCE) != null) { return; } BaseObject ownerObject = doc.newXObject(Owner.CLASS_REFERENCE, context); if (doc.getCreatorReference() != null) { ownerObject.setStringValue(OWNER, doc.getCreatorReference().toString()); } else { ownerObject.setStringValue(OWNER, ""); } } catch (XWikiException ex) { this.logger.error("Failed to set the initial owner for entity [{}]: {}", doc.getDocumentReference(), ex.getMessage(), ex); } } OwnerUpdateEventListener(); @Override void onEvent(Event event, Object source, Object data);  }