userAuthorities = authorityService.getAuthoritiesForUser(AuthenticationUtil.getRunAsUser());
// ignore checkForLock for admins
if (!userAuthorities.contains(PermissionService.ADMINISTRATOR_AUTHORITY))
{
checkForLock(nodeRef);
}
}
/**
* Ensures that the parent is not locked.
*
* @see #checkForLock(NodeRef)
*/
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean isNewNode)
{
LockType lockType = getLockType(childAssocRef.getParentRef());
if(lockType != null)
{
switch (lockType)
{
case WRITE_LOCK:
case READ_ONLY_LOCK:
checkForLock(childAssocRef.getParentRef());
break;
case NODE_LOCK:
// don't check for lock
}
}
}
/**
* Ensures that node is not locked.
*
* @see #checkForLock(NodeRef)
*/
public void beforeUpdateNode(NodeRef nodeRef)
{
checkForLock(nodeRef);
}
/**
* Ensures that node is not locked.
*
* @see #checkForLock(NodeRef)
*/
public void beforeDeleteNode(NodeRef nodeRef)
{
checkForLock(nodeRef);
}
/**
* @return Returns {@link DoNothingCopyBehaviourCallback}
*/
public CopyBehaviourCallback getCopyCallback(QName classRef, CopyDetails copyDetails)
{
return DoNothingCopyBehaviourCallback.getInstance();
}
/**
* OnCreateVersion behaviour for the lock aspect
*
* Ensures that the property values of the lock aspect are not 'frozen' in
* the version store.
*/
public void onCreateVersion(
QName classRef,
NodeRef versionableNode,
Map versionProperties,
PolicyScope nodeDetails)
{
// Add the lock aspect, but do not version the property values
// TODO: disable the LockAspectInterceptor for this thread, re-enable in finally.
// (we need to add this aspect for real).
nodeDetails.addAspect(ContentModel.ASPECT_LOCKABLE);
}
/**
* Get the current user reference
*
* @return the current user reference
*/
private String getUserName()
{
return this.authenticationService.getCurrentUserName();
}
/**
* @see org.alfresco.service.cmr.lock.LockService#getLocks()
* @deprecated Uses search and does not report on ephemeral locks.
*/
@Deprecated
public List getLocks(StoreRef storeRef)
{
return getLocks(
storeRef,
"ASPECT:\"" + ContentModel.ASPECT_LOCKABLE.toString() +
"\" +@\\{http\\://www.alfresco.org/model/content/1.0\\}" + ContentModel.PROP_LOCK_OWNER.getLocalName() + ":\"" + getUserName() + "\"");
}
/**
* Get the locks given a store and query string.
*
* @param storeRef the store reference
* @param query the query string
* @return the locked nodes
* @deprecated Uses search and does not report on ephemeral locks.
*/
@Deprecated
private List getLocks(StoreRef storeRef, String query)
{
List result = new ArrayList();
ResultSet resultSet = null;
try
{
resultSet = this.searchService.query(
storeRef,
SearchService.LANGUAGE_LUCENE,
query);
result = resultSet.getNodeRefs();
}
finally
{
if (resultSet != null)
{
resultSet.close();
}
}
return result;
}
/**
* @see org.alfresco.service.cmr.lock.LockService#getLocks(org.alfresco.service.cmr.lock.LockType)
* @deprecated Uses search and does not report on ephemeral locks.
*/
@Deprecated
public List getLocks(StoreRef storeRef, LockType lockType)
{
return getLocks(
storeRef,
"ASPECT:\"" + ContentModel.ASPECT_LOCKABLE.toString() +
"\" +@\\{http\\://www.alfresco.org/model/content/1.0\\}" + ContentModel.PROP_LOCK_OWNER.getLocalName() + ":\"" + getUserName() + "\"" +
" +@\\{http\\://www.alfresco.org/model/content/1.0\\}" + ContentModel.PROP_LOCK_TYPE.getLocalName() + ":\"" + lockType.toString() + "\"");
}
@Override
public void onMoveNode(ChildAssociationRef oldChildAssocRef, ChildAssociationRef newChildAssocRef)
{
NodeRef nodeRef = oldChildAssocRef.getChildRef();
checkForLock(nodeRef);
}
@Override
public void suspendLocks()
{
getBehaviourFilter().disableBehaviour(ContentModel.ASPECT_LOCKABLE);
}
@Override
public void enableLocks()
{
getBehaviourFilter().enableBehaviour(ContentModel.ASPECT_LOCKABLE);
}
@Override
public String getAdditionalInfo(NodeRef nodeRef)
{
LockState lockState = getLockState(nodeRef);
String additionalInfo = lockState.getAdditionalInfo();
return additionalInfo;
}
@Override
public LockState getLockState(NodeRef nodeRef)
{
// Check in-memory for ephemeral locks first.
nodeRef = tenantService.getName(nodeRef);
LockState lockState = lockStore.get(nodeRef);
//ALF-20361: It is possible that a rollback has resulted in a "non-lock" lock state being added to
//the lock store. Because of that, we check both whether the retrieved lockState is null and, if it isn't,
//whether it represents a real lock
if (lockState == null || !lockState.isLockInfo())
{
// No in-memory state, so get from the DB.
if (nodeService.exists(nodeRef) && nodeService.hasAspect(nodeRef, ContentModel.ASPECT_LOCKABLE))
{
String lockOwner = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_LOCK_OWNER);
Date expiryDate = (Date) nodeService.getProperty(nodeRef, ContentModel.PROP_EXPIRY_DATE);
String lockTypeStr = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_LOCK_TYPE);
LockType lockType = lockTypeStr != null ? LockType.valueOf(lockTypeStr) : null;
String lifetimeStr = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_LOCK_LIFETIME);
Lifetime lifetime = lifetimeStr != null ? Lifetime.valueOf(lifetimeStr) : null;
// Mark lockstate as PERSISTENT as it was in the persistent storage!
lockState = LockState.createLock(
nodeRef,
lockType,
lockOwner,
expiryDate,
lifetime,
null);
}
else
{
// There is no lock information
lockState = LockState.createUnlocked(nodeRef);
}
}
// Never return a null LockState
Assert.notNull(lockState);
return lockState;
}
public void setBehaviourFilter(BehaviourFilter behaviourFilter)
{
this.behaviourFilter = behaviourFilter;
}
public BehaviourFilter getBehaviourFilter()
{
return behaviourFilter;
}
public void setNodeIndexer(NodeIndexer nodeIndexer)
{
this.nodeIndexer = nodeIndexer;
}
@Override
public void flush()
{
}
@Override
public void beforeCommit(boolean readOnly)
{
}
@Override
public void beforeCompletion()
{
}
@Override
public void afterCommit()
{
}
@Override
public void afterRollback()
{
// As rollback has occurred we are unable to keep hold of any ephemeral locks set during this transaction.
Map lockedNodes = TransactionalResourceHelper.getMap(KEY_MODIFIED_NODES);
for (LockState lockInfo : lockedNodes.values())
{
lockStore.set(lockInfo.getNodeRef(), lockInfo);
}
}
}