Details
-
Bug
-
Resolution: Cannot Reproduce
-
Minor
-
None
-
5.2.1
-
None
-
Unknown
-
Description
to repeat:
Paste this into a page:
{{groovy}}
/* -*- Mode: java; tab-width: 4; indent-tabs-mode: nil; -*- */
import java.util.List;
import java.util.ArrayList;
import org.xwiki.observation.ObservationManager;
import org.xwiki.observation.EventListener;
import org.xwiki.bridge.event.DocumentUpdatedEvent;
import org.xwiki.bridge.event.DocumentCreatedEvent;
import org.xwiki.bridge.event.DocumentDeletedEvent;
import org.xwiki.observation.event.Event;
import com.xpn.xwiki.api.XWiki;
import com.xpn.xwiki.web.Utils;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.objects.BaseObject;
class TestListener implements EventListener
{
public String getName() {
return "TestListener";
}
public List<Event> getEvents() {
return (new ArrayList<Event>() {{
add(new DocumentUpdatedEvent());
add(new DocumentCreatedEvent());
add(new DocumentDeletedEvent());
}});
}
public void onEvent(Event event, Object source, Object data) {
XWikiDocument doc = (XWikiDocument) source;
if (doc.getAttachmentList().size() > 0) {
System.out.println("Received " + event.getClass() + " on " + doc.getFullName() + " which has attachments");
def xc = (XWikiContext) data;
def xwiki = new XWiki(xc.getWiki(), xc);
def docB = xwiki.getDocument(name);
if (docB.getAttachmentList().size() == 0) {
try {
throw new Exception();
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
} else {
System.out.println("Received " + event.getClass() + " on " + doc.getFullName() + " which has no attachments");
}
}
}
Utils.getComponent(ObservationManager.class).addListener(new TestListener());
{{/groovy}}
Then view it.
Then open a different page which has no attachments.
Then add an attachment and observe the log.
expected behaviour: Attachment is available at time of DocumentUpdatedEvent firing
actual behaviour: getAttachmentList() from a getDocument() of the same document yields nothing even though the document passed with the event contains the attachment.
Note: Objects other changes to the document have been persisted at this point.