Calling an operation from an event listener: how to inject dependencies ?
Hi,
I need to call the “ExportStructureToFS” operation from an event listener in order to trigger a scheduled export mys documents.
I found this explanation about how to call operations from java code, but I can't get the AutomationService and OperationContext injected as suggested in the example.
I use this declarations:
@Context
protected AutomationService service;
@Context
protected OperationContext context;
Both service and context end being set to null using this technique.
What's wrong ?
Thanks
Dependency injection via the @context annotation works calling one operation from another.
In that case using:
AutomationService automationService = Framework.getService(AutomationService.class);
To get the service implementation
And
automationService.run(new OperationContext(), "ExportStructureToFS", parameters);
Solved my problem
As I understood, those service and context are inside your custom operation "ExportStructureToFS".
Could you check if @Context is org.nuxeo.ecm.automation.core.annotations.Context?
If it is, can you communicate this operation and the contribution xml?
Thank you
I'm using this ready made operation https://github.com/nuxeo/nuxeo-fsexporter
I can get the descriptor with a get.
Dependency injection is used inside my event listener as follow:
import org.nuxeo.ecm.automation.AutomationService; import org.nuxeo.ecm.automation.OperationContext; import org.nuxeo.ecm.automation.core.annotations.Context;
public class FsExportListener implements EventListener {
}
Maybe I'm wrong ? Thanks btw
edit: I did not post the listener contrib, because the log file is recording debug but let me know if it's needed
I've just found this link
https://github.com/easysoa/EasySOA/wiki/Nuxeo-CoreSession-and-Transactions
So I will bet on using the event context and call the service with
Framework.getService(AutomationService.class)