[opencms-dev] Change property in action class

Paul-Inge Flakstad flakstad at npolar.no
Fri Dec 18 10:03:34 CET 2009


Hi Enrico

I don't think a user - admin user or not - is allowed to change any resource that is locked by another user - therefore you cannot overwrite a property without first owning the lock on the resource.

Without going too deep into your problem, I think you can temporarily change the lock using the API. See org.opencms.file.CmsObject: The current lock can be accessed with getLock, and you can perform the "steal lock" operation by calling changeLock. Furthermore, there are the getLock and unlockResource methods.

In theory, this means you can read the current lock, steal the lock and do whatever while you own it, and then setting the lock back to its original state. However, re-creating the lock could be a problem, as you would have to switch user and become the user who originally owned the lock (or am I wrong?) before calling lockResource, as there is no method to lock a given resource to a given user.

Remember also that resources cannot be modified in the Online project, you'll need to set it to Offline (see org.opencms.file.CmsRequestContext#setCurrentProject(org.opencms.file.CmsProject)).

Hope this helps you.

Cheers,
Paul

________________________________
From: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Popall, Enrico
Sent: 16. desember 2009 17:09
To: opencms-dev at opencms.org
Subject: [opencms-dev] Change property in action class



Hi everybody

I'm trying to set a property of a resource inside of an action class that listens to I_CmsEventListener.EVENT_RESOURCE_MODIFIED.

The problem is that once I'm not logged in as "Admin" I can't change this property. The error message: Resource XYZ is not locked by current user "Admin". Again, that happens when I'm not logged in as Admin. The class works as expected if I login as Admin and modify the resource then. Another user which also has root admin rights but is not named "Admin" can't do it.

So my guess was that the system internally somehow switches the user prior to firing the event. cmsObject.getRequestContext().currentUser().getFullName() confirms this. The context also tells me that it is in the Online project (which kinda explains the Admin).

Any ideas how to get around this? Is there a way to change the lock of this resource temporary and then set it back to it's original state? Or overwrite a property since you are the admin in this situation anyway? Or is there another way to catch events in the Offline project?

The whole task is to put the categories (relations --> assign categories) in a property field that is indexable for the search. Maybe I'm on a wrong path here and I don't need/can't to do this via the action class. If someone has an idea, please let me know too.

Thanks and best regards

__________________________________
Enrico Popall
Software AG
Global Marketing
Uhlandstr.12, 64297 Darmstadt, Germany

Tel: +49 6151 922998
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20091218/947c5dc4/attachment.htm>


More information about the opencms-dev mailing list