‎03-02-2016 07:46 AM
Hi,
I am trying to perform update on some objects' properties, using Java program:
MegaObject megaObj = //derived from MegaRoot collection
megaObj.setProp("~AttributeId[AttributeName]", "TEST VALUE");
for some locked objects, I usually throw class com.mega.modeling.api.MegaException
MEGA Error 0x80020009(Property Update Error) : Object ~MrUiM9B5iyM0{MetaClass}[Application] , Property AttributeName:ObjectName object cannot be accessed by User because it is already locked by Mega.
at com.mega.modeling.api.jni.MegaObjectJNI.SetProp(Native Method)
at com.mega.modeling.api.jni.MegaObjectProxy.setProp(Unknown Source)
The documentation states the program code might really fail if update is not possible.
I could catch the exception after invoking the method, then I would know that object is not updateable.... but I guess it's not the best way to do this.
How do I determine Lock and/or ReadOnly (or update is NOT possible) Status of MegaObject before invoking setProp() Method?
Thanks,
ACE
Solved! Go to Solution.
‎05-02-2016 09:27 AM
Hi Jelghazi,
Thank you very much for this! It's working....
Cheers,
ACE
‎04-02-2016 11:27 AM
Hello,
"Protection" is a Mega Operator, to manage it we use a MegaLock object that is found in the mj_api.jar.
here is an example of how to use it :
public String isMyObjectLocked() { String lockedMessage = ""; final MegaLock lock = new MegaLock((MegaCOMObject) yourObject.callFunction("protection")); if ((lock.status() == MegaLock.STATUS_LOCKED) || (lock.status() == MegaLock.STATUS_USER_NOT_UNLOCKED)) { lockedMessage = lock.updateMessage(); return lockedMessage; }
‎03-02-2016 02:30 PM
Thank you Jerome.
Does this MegaProtection object available only using VBScript, as referenced from the the mg_mapp.dll MEGA dll? Or is there any possible equivalent Java codes?
I could not find any MegaProtection Class from all the Java jar files/libraries contained in MEGA environment.
-ACE
‎03-02-2016 09:33 AM - edited ‎03-02-2016 09:46 AM
Hello ACE
With API script there is an object MegaProtection
Examples (VB script code)
oObj.Protection.Active
Returns -1 if object is protected
Returns 0 if object is not protected
oObj.Protection.Status
Returns a status that enabled to understand the cause
Status value is 20 for locks
So you can check protection before an update
Set oObject = GetObjectFromId("~nM3HFR7n05k3[Test]") If (oObject.Protection.Active) Then 'if object is locked display a warning Print "Object " & oObject.Name & " is protected and cannot be updated" Else 'otherwise, perform update oObject.SetProp "Name","Test2" End If
See API reference guide, section 'MegaProtection'
http://community.mega.com/mega/attachments/mega/HOPEXV1R2/10/59/API%20Annex.pdf