Exemplo n.º 1
0
 @Override
 public synchronized MailItem lock(
     OperationContext octxt, int itemId, MailItem.Type type, String accountId)
     throws ServiceException {
   Account acct = getLockAccount(accountId);
   boolean success = false;
   try {
     beginTransaction("lock", octxt);
     MailItem item = getItemById(itemId, type);
     if (acct == null && item instanceof Document) {
       // bit of a hack here; basically we need to be able to record lock owner as a remote acct
       // since it can be locked by a grantee that does not exist in ZD
       // rather than setting up a fake account we'll just manually set lock owner
       Document doc = (Document) item;
       if (doc.lockOwner != null && !doc.lockOwner.equalsIgnoreCase(accountId)) {
         throw MailServiceException.CANNOT_LOCK(doc.mId, doc.lockOwner);
       }
       doc.lockOwner = accountId;
       doc.lockTimestamp = System.currentTimeMillis();
       doc.markItemModified(Change.LOCK);
       doc.saveMetadata();
     } else {
       item.lock(acct);
     }
     success = true;
     return item;
   } finally {
     endTransaction(success);
   }
 }