On 18 May 2007, at 16:40, Olivier Grisel wrote:
Vincent Dutat a écrit :
Hi,
I created a 2 document types with folderish facet and some other
schemas
(let's call them doctypeA and doctypeB). I would like that a
document of
doctypeB is automatically created in all documents of doctypeA
when they
are created. I thought that a core event listener was a good way to
achieve this. This core event listener receives an event
'documentCreated' on a document of type doctypeA and create a
document
of type doctypeB as a child of it. But I get exception saying that
document of typr doctypeA does not exist, strange. My listener's
class
is AddMrLeadFoldersListener. Created document's title is 'lead 2'.
Here
is the exception :
This might be because you are trying to create children in a new
transaction
that is concurrent to the one that creates the folder. To reuse the
same
CoreSession you can try to do something along the lines:
public void notifyEvent(CoreEvent event) {
String eventId = event.getEventId();
Object ob = event.getSource();
if (!(ob instanceof Document)) {
return;
}
Document doc = (Document) ob;
Session session = doc.getSession();
String sid = session.getUserSessionId();
Olivier means
String managedSessionId = session.getUserSessionId();
here.
CoreSession session = CoreInstance.getInstance().getSession(
managedSessionId);
// do the creation of your children here
// do not close the session as it will be probably be used
// by other core event listener afterward
}
Note that all this is due to the fact that we still have two notions
of sessions, the core session and the "higher level" session. We plan
to refactor this in the near future (a few weeks) to make things a
bit more rational.
Florent
--
Florent Guillaume, Director of R&D, Nuxeo
Open Source Enterprise Content Management (ECM)
http://www.nuxeo.com http://www.nuxeo.org +33 1 40 33 79 87
_______________________________________________
ECM mailing list
[email protected]
http://lists.nuxeo.com/mailman/listinfo/ecm