cancel
Showing results for 
Search instead for 
Did you mean: 

How to check Lock and/or ReadOnly Status of MegaObject before invoking setProp() Method?

Solved
Occasional Contributor

How to check Lock and/or ReadOnly Status of MegaObject before invoking setProp() Method?

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 AttributeNameSmiley SurprisedbjectName 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.

 

setProp.GIF

 

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

4 Replies
MEGA

Re: How to check Lock and/or ReadOnly Status of MegaObject before invoking setProp() Method?

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

Jerome
Occasional Contributor

Re: How to check Lock and/or ReadOnly Status of MegaObject before invoking setProp() Method?

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

Contributor

Re: How to check Lock and/or ReadOnly Status of MegaObject before invoking setProp() Method?

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;
}

 

Custo Guru
Occasional Contributor

Re: How to check Lock and/or ReadOnly Status of MegaObject before invoking setProp() Method?

Hi Jelghazi,

 

Thank you very much for this! It's working....

 

 

Cheers,

ACE