Best way to deal with document locking in xPages? -


what best way deal document locking in xpages? use standard soft locking , seems work in notes client.

in xpages considered using "allow document locking" feature worried people close browser without using close or save button lock never cleared.

is there way clear locks when user has closed session? seeing no such event.

or there easier way have document locking?

i realize can clear locks using agent when run it? think sometime night lock should no longer active.

here code i'm using:

/* document locking */ /*      use global object "documentlocking" with:     .lock(doc) -> locks document     .unlock(doc) -> unlocks document     .islocked(doc) -> returns true/false     .lockedby(doc) -> returns name of lock holder     .lockeddt(doc) -> returns datetime stamp of lock  */  function yndocumentlocking() {      /*          lock entry in application scope          key = "$ynlock_"+unid          containing array         (0) = username of lock holder         (1) = timestamp of lock       */      var lockmaxage = 60 * 120; // in seconds, default 120 min      this.getunid = function(v) {         if (!v) return null;         if (typeof v == "notesxspdocument") return v.getdocument().getuniversalid();         if (typeof v == "string") return v;         return v.getuniversalid();     }      /* puts lock application scope */     this.lock = function(doc:notesdocument) {         var = new array(1);         a[0] = @username();         a[1] = @now();         applicationscope.put("$ynlock_"+this.getunid(doc), a);           // print("set lock "+"$ynlock_"+doc.getuniversalid()+" / "+a[0]+" / "+a[1]);     }         /* removes lock application scope */     this.unlock = function(doc:notesdocument) {         applicationscope.put("$ynlock_"+this.getunid(doc), null);         //print("removed lock "+"$ynlock_"+doc.getuniversalid());     }      this.islocked = function(doc:notesdocument) {         try {             //print("islocked "+"$ynlock_"+doc.getuniversalid());                     // check how old lock             var v = applicationscope.get("$ynlock_"+this.getunid(doc));             if (!v) {                 //print("no lock found -> return false");                 return false;                }              // if lock holder current user, treat not locked             if (v[0] == @username()) {                 //print("lock holder = user -> not locked");                 return false;             }               var dlock:notesdatetime = session.createdatetime(v[1]);             var dnow:notesdatetime = session.createdatetime(@now());             // diff in seconds             //print("time diff="+dnow.timedifference(dlock)+" dlock="+v[1]+" now="+@now());             // if diff > x seconds remove lock, not locked             if (dnow.timedifference(dlock) > lockmaxage) {                 // print("lock older maxage "+lockmaxage+" -> returning false");                 return false;             }             //print("return true");             return true;         // todo: check how old lock         } catch (e) {             print("yndocumentlocking.islocked: "+e);         }      }      this.lockedby = function(doc:notesdocument) {         try {         var v = applicationscope.get("$ynlock_"+this.getunid(doc));         if (!v) return "";         //print("islockedby "+"$ynlock_"+doc.getuniversalid()+" = "+v[0]);         return v[0];          } catch (e) {             print("yndocumentlocking.islockedby: "+e);         }     }      this.lockeddt = function(doc:notesdocument) {         try {         var v = applicationscope.get("$ynlock_"+this.getunid(doc));         if (!v) return "";         return v[1];          } catch (e) {             print("yndocumentlocking.islockedby: "+e);         }     }  }  var documentlocking = new yndocumentlocking(); 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -