Hi all.
I need to write a Java package in order to manipulate Alfresco repository objects in custom ways. I am just creating a custom Java package and I want to have a reference to alfresco services (nodeService, …) inside my Java classes, so I am going to direct inject Alfresco beans into my classes. Because I need to manage all the task in a transactional way, I need a reference to TransactionService into my classes. I was thinking about direct injecting a TransactionService bean into my classes, but it failed.
My questions are the following:
1) how to direct inject TransactionService into my classes (if possible)?
2) Instead of TransactionService is it possible to direct inject the ServiceRegistry bean?
I followed the FirstFoundationClient example, but it creates a new ApplicationContext, on the contrary I want to use the ApplicationContext already created during the Alfresco boot.
I tried the write a Java bean and direct inject the TransactionComponent and the AuthenticationComponentImpl beans. My bean has an init() method as the following:
public void init ()
{
try {
transactionService.getUserTransaction().begin();
} catch (NotSupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.authenticationService.authenticate("admin", "admin".toCharArray());
}
It works fine but I would like to know if this is the correct way to go on or not.
Many thanks to all.
Sergio