org.nuxeo.ecm.core.api.Lock类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(250)

本文整理了Java中org.nuxeo.ecm.core.api.Lock类的一些代码示例,展示了Lock类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Lock类的具体详情如下:
包路径:org.nuxeo.ecm.core.api.Lock
类名称:Lock

Lock介绍

[英]Information about a lock set on a document.

The lock information holds the owner, which is a user id, and the lock creation time.
[中]有关文档上的锁集的信息。
锁信息保存所有者(即用户id)和锁创建时间。

代码示例

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-redis

protected String stringFromLock(Lock lock) {
  if (lock == null) {
    throw new NullPointerException("null lock");
  }
  return lock.getOwner() + ":" + lock.getCreated().getTimeInMillis();
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-storage-mem

@Override
public synchronized Lock setLock(String id, Lock lock) {
  State state = states.get(id);
  if (state == null) {
    // document not found
    throw new DocumentNotFoundException(id);
  }
  String owner = (String) state.get(KEY_LOCK_OWNER);
  if (owner != null) {
    // return old lock
    Calendar created = (Calendar) state.get(KEY_LOCK_CREATED);
    return new Lock(owner, created);
  }
  state.put(KEY_LOCK_OWNER, lock.getOwner());
  state.put(KEY_LOCK_CREATED, lock.getCreated());
  return null;
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-redis

@Override
public Lock removeLock(final String id, final String owner) {
  RedisExecutor redisExecutor = Framework.getService(RedisExecutor.class);
  List<String> keys = Collections.singletonList(redisNamespace + id);
  List<String> args = Collections.singletonList(owner == null ? "" : owner);
  String lockString = (String) redisExecutor.evalsha(scriptRemoveSha, keys, args);
  Lock lock = lockFromString(lockString);
  if (lock != null && owner != null && !owner.equals(lock.getOwner())) {
    lock = new Lock(lock, true); // failed removal
  }
  return lock;
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core

protected static String getDocumentLocker(DocumentModel doc) {
  Lock lock = doc.getLockInfo();
  return lock == null ? null : lock.getOwner();
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-storage-sql

return null;
if (oldLock != null && !LockManager.canLockBeRemoved(oldLock.getOwner(), owner)) {
  oldLock = new Lock(oldLock, true);
} else {
  if (oldLock == null) {
  if (oldLock != null && oldLock.getFailed()) {
    lockCache.put(id, new Lock(oldLock, false));
  } else {
    lockCache.put(id, NULL_LOCK);

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core

@Override
public Lock removeLock(DocumentRef docRef) throws LockException {
  Document doc = resolveReference(docRef);
  String owner;
  if (hasPermission(docRef, UNLOCK)) {
    // always unlock
    owner = null;
  } else {
    owner = getPrincipal().getName();
  }
  Lock lock = doc.removeLock(owner);
  if (lock == null) {
    // there was no lock, we're done
    return null;
  }
  if (lock.getFailed()) {
    // lock removal failed due to owner check
    throw new LockException("Document already locked by " + lock.getOwner() + ": " + docRef);
  }
  DocumentModel docModel = readModel(doc);
  Map<String, Serializable> options = new HashMap<>();
  options.put("lock", lock);
  notifyEvent(DocumentEventTypes.DOCUMENT_UNLOCKED, docModel, options, null, null, true, false);
  return lock;
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-redis

protected Lock lockFromString(String lockString) {
  if (lockString == null) {
    return null;
  }
  String[] split = lockString.split(":");
  if (split.length != 2 || !StringUtils.isNumeric(split[1])) {
    throw new IllegalArgumentException(
        "Invalid Redis lock : " + lockString + ", should be " + redisNamespace + "<id>");
  }
  Calendar created = Calendar.getInstance();
  created.setTimeInMillis(Long.parseLong(split[1]));
  return new Lock(split[0], created);
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-storage-sql

@Override
public Lock removeLock(final Serializable id, final String owner, final boolean force) {
  if (log.isDebugEnabled()) {
    log.debug("removeLock " + id + " owner=" + owner + " force=" + force);
  }
  Lock oldLock = force ? null : getLock(id);
  if (!force && owner != null) {
    if (oldLock == null) {
      // not locked, nothing to do
      return null;
    }
    if (!LockManager.canLockBeRemoved(oldLock.getOwner(), owner)) {
      // existing mismatched lock, flag failure
      return new Lock(oldLock, true);
    }
  }
  if (force || oldLock != null) {
    deleteRows(Model.LOCK_TABLE_NAME, Collections.singleton(id));
  }
  return oldLock;
}

代码示例来源:origin: toutatice-services.listeemargement/toutatice-listeemargement-ecm

private boolean isNotLockedOrIsLockOwner(DocumentModel document) throws ClientException {
  Lock lockInfo = document.getLockInfo();
  return (null != lockInfo) ? lockInfo.getOwner().equals(currentUser.getName()) : true;
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-storage

@Override
public void updateImport(CoreSession session, DocumentModel docModel, ExportedDocument xdoc) throws Exception {
  Element lockInfo = xdoc.getDocument().getRootElement().element("lockInfo");
  if (lockInfo != null) {
    String createdMS = lockInfo.element("created").getText();
    String owner = lockInfo.element("owner").getText();
    Calendar created = Calendar.getInstance();
    created.setTimeInMillis(Long.parseLong(createdMS));
    Lock lock = new Lock(owner, created);
    getLockManager(session).setLock(docModel.getId(), lock);
  }
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-storage-sql

@Override
public Lock setLock(final Serializable id, final Lock lock) {
  if (log.isDebugEnabled()) {
    log.debug("setLock " + id + " owner=" + lock.getOwner());
  }
  Lock oldLock = getLock(id);
  if (oldLock == null) {
    Row row = new Row(Model.LOCK_TABLE_NAME, id);
    row.put(Model.LOCK_OWNER_KEY, lock.getOwner());
    row.put(Model.LOCK_CREATED_KEY, lock.getCreated());
    insertSimpleRows(Model.LOCK_TABLE_NAME, Collections.singletonList(row));
  }
  return oldLock;
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-storage-mongodb

);
    Updates.set(KEY_LOCK_OWNER, lock.getOwner()), //
    Updates.set(KEY_LOCK_CREATED, converter.serializableToBson(lock.getCreated())) //
);
if (log.isTraceEnabled()) {
  Calendar oldCreated = (Calendar) converter.scalarToSerializable(old.get(KEY_LOCK_CREATED));
  if (oldOwner != null) {
    return new Lock(oldOwner, oldCreated);

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core

@Override
public Lock setLock(DocumentRef docRef) throws LockException {
  Document doc = resolveReference(docRef);
  // TODO: add a new permission named LOCK and use it instead of
  // WRITE_PROPERTIES
  checkPermission(doc, WRITE_PROPERTIES);
  Lock lock = new Lock(getPrincipal().getName(), new GregorianCalendar());
  Lock oldLock = doc.setLock(lock);
  if (oldLock != null) {
    throw new LockException("Document already locked by " + oldLock.getOwner() + ": " + docRef);
  }
  DocumentModel docModel = readModel(doc);
  Map<String, Serializable> options = new HashMap<>();
  options.put("lock", lock);
  notifyEvent(DocumentEventTypes.DOCUMENT_LOCKED, docModel, options, null, null, true, false);
  return lock;
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core

@Override
public Access checkPermission(Document doc, ACP mergedAcp, NuxeoPrincipal principal, String permission,
    String[] resolvedPermissions, String[] additionalPrincipals) {
  Access access = Access.UNKNOWN;
  // policy only applies on WRITE
  if (resolvedPermissions == null || !Arrays.asList(resolvedPermissions).contains(SecurityConstants.WRITE)) {
    return access;
  }
  // check the lock
  String username = principal.getName();
  Lock lock = doc.getLock();
  if (lock != null && !username.equals(lock.getOwner())) {
    // locked by another user => deny
    access = Access.DENY;
  }
  return access;
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-storage-sql

@Override
public Lock getLock(Serializable id) {
  if (log.isDebugEnabled()) {
    try {
      log.debug("getLock " + id + " while autoCommit=" + connection.getAutoCommit());
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }
  RowId rowId = new RowId(Model.LOCK_TABLE_NAME, id);
  Row row = readSimpleRow(rowId);
  return row == null ? null
      : new Lock((String) row.get(Model.LOCK_OWNER_KEY), (Calendar) row.get(Model.LOCK_CREATED_KEY));
}

代码示例来源:origin: org.nuxeo.ecm.platform/nuxeo-platform-webapp-core

@Override
public Map<String, Serializable> getLockDetails(DocumentModel document) {
  if (lockDetails == null || !StringUtils.equals(documentId, document.getId())) {
    lockDetails = new HashMap<String, Serializable>();
    documentId = document.getId();
    Lock lock = documentManager.getLockInfo(document.getRef());
    if (lock == null) {
      return lockDetails;
    }
    lockDetails.put(LOCKER, lock.getOwner());
    lockDetails.put(LOCK_CREATED, lock.getCreated());
  }
  return lockDetails;
}

代码示例来源:origin: org.nuxeo.ecm.platform/nuxeo-webdav

@Override
public String getCheckoutUser(DocumentRef ref) {
  Lock lock = getSession().getLockInfo(ref);
  if (lock != null) {
    return lock.getOwner();
  }
  return null;
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-storage-mem

@Override
public synchronized Lock getLock(String id) {
  State state = states.get(id);
  if (state == null) {
    // document not found
    throw new DocumentNotFoundException(id);
  }
  String owner = (String) state.get(KEY_LOCK_OWNER);
  if (owner == null) {
    return null;
  }
  Calendar created = (Calendar) state.get(KEY_LOCK_CREATED);
  return new Lock(owner, created);
}

代码示例来源:origin: opentoutatice-ecm.elasticsearch-customizer/opentoutatice-addon-elasticsearch-customizer-ecm

/**
 * Write lock informations of document.
 * 
 * @param jg
 * @param doc
 * @throws JsonGenerationException
 * @throws IOException
 */
// FIXME: create a lock index?
protected void writeLockInfos(JsonGenerator jg, DocumentModel doc) throws JsonGenerationException, IOException {
  Lock lock = doc.getLockInfo();
  if (lock != null) {
    jg.writeStringField("ttc:lockOwner", lock.getOwner());
    jg.writeStringField("ttc:lockCreated", ISODateTimeFormat.dateTime().print(new DateTime(lock.getCreated())));
  }
}

代码示例来源:origin: org.nuxeo.ecm.routing/nuxeo-routing-core

@Override
public boolean isLockedByCurrentUser(CoreSession session) {
  Lock lockInfo = session.getLockInfo(doc.getRef());
  if (lockInfo == null) {
    return false;
  }
  String lockOwner = lockInfo.getOwner();
  NuxeoPrincipal userName = session.getPrincipal();
  return userName.getName().equals(lockOwner);
}

相关文章