Hello folks,
I'm currently trying to access Permissions from a page in a Job-Plugin which is, as far as I found out not possible the direct way. As I tried this:
page.getContentPermissionSet(contPerm);
It said, it is'nt possible due to LazyInitialisation :(
So I read, that its possible to do this with a TransactionCallback/Tempalte - so I tried the example Codes on the page but this does need casts and stuff and is not working exactly that way how its suggested.
I try to use it this way:
DefaultTransactionDefinition definition = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED); TransactionTemplate transactionTemplate = new TransactionTemplate((PlatformTransactionManager) ContainerManager.getComponent("transactionManager"), definition);
With this imports:
import org.springframework.transaction.support.TransactionTemplate; import org.springframework.transaction.support.DefaultTransactionDefinition; import org.springframework.transaction.PlatformTransactionManager;
It gives me the Error:
[INFO] [talledLocalContainer] # ERROR # java.lang.ClassCastException: org.springframework.orm.hibernate.HibernateTransactionManager cannot be cast to org.springframework.transaction.PlatformTransactionManager
And if I use it this way:
TransactionTemplate transactionTemplate = (TransactionTemplate) ContainerManager.getComponent("transactionManager");
with this imports
import com.atlassian.sal.api.transaction.TransactionTemplate;
Im getting this Error.
[INFO] [talledLocalContainer] # ERROR # java.lang.ClassCastException: org.springframework.orm.hibernate.HibernateTransactionManager cannot be cast to com.atlassian.sal.api.transaction.TransactionTemplate
I dont see where I go wrong. I looked through some other code and looked here at answers and tried to do it like others but it didnt seem to work either :(
Community moderators have prevented the ability to post new answers.
Alternatively, you can use the SAL TransactionTemplate wrapper - see https://answers.atlassian.com/questions/16810/managing-a-session-manually
This problem of trying to access the Spring TransactionTemplate in a Confluence plugin exists because Confluence and the Plugin Framework use different versions of Spring.
I actually read that post before but I think I made some mistakes so this did'nt worked for me :(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok,
since I needed the TransactionTemplate and there was no way to get it with the help of the Container Manager, I used the way of using a Static accessor (Link).
I just inserted the TransactionTemplate into it and accessed it from my PluginJob Class like this:
TransactionTemplate transactionTemplate = StaticAccessor.getTransactionTemplate();
and made my transaction like the way it is suggested:
Object result = transactionTemplate.execute(new TransactionCallback() { @Override public Object doInTransaction() { // ... execute transactional code ... ContentPermissionSet cps = pageManager.getPage(pageId).getContentPermissionSet(ContentPermission.VIEW_PERMISSION); for(ContentPermission cp: cps){ if(cp.isUserPermission()){ contentPermissionManager.removeContentPermission(cp); } } return null; } });
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Leroy: What does your StaticAccessor class look like?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.