mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2)
125498 slanglois: MNT-16155 Update source headers - remove svn:eol-style property on Java and JSP source files git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.1.N/root@125605 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,264 +1,264 @@
|
||||
|
||||
package org.alfresco.repo.coci;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.copy.CopyBehaviourCallback;
|
||||
import org.alfresco.repo.copy.CopyDetails;
|
||||
import org.alfresco.repo.copy.CopyServicePolicies;
|
||||
import org.alfresco.repo.copy.DefaultCopyBehaviourCallback;
|
||||
import org.alfresco.repo.node.NodeServicePolicies;
|
||||
import org.alfresco.repo.policy.BehaviourFilter;
|
||||
import org.alfresco.repo.policy.JavaBehaviour;
|
||||
import org.alfresco.repo.policy.PolicyComponent;
|
||||
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
|
||||
import org.alfresco.service.cmr.lock.LockService;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.GUID;
|
||||
|
||||
public class WorkingCopyAspect implements CopyServicePolicies.OnCopyNodePolicy, NodeServicePolicies.OnRemoveAspectPolicy
|
||||
{
|
||||
private PolicyComponent policyComponent;
|
||||
private NodeService nodeService;
|
||||
private LockService lockService;
|
||||
private CheckOutCheckInService checkOutCheckInService;
|
||||
private BehaviourFilter policyBehaviourFilter;
|
||||
|
||||
|
||||
/**
|
||||
* The working copy aspect copy behaviour callback.
|
||||
*/
|
||||
private WorkingCopyAspectCopyBehaviourCallback workingCopyAspectCopyBehaviourCallback = new WorkingCopyAspectCopyBehaviourCallback();
|
||||
|
||||
/**
|
||||
* Sets the policy component
|
||||
*/
|
||||
public void setPolicyComponent(PolicyComponent policyComponent)
|
||||
{
|
||||
this.policyComponent = policyComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the node service
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the lock service
|
||||
*/
|
||||
public void setLockService(LockService lockService)
|
||||
{
|
||||
this.lockService = lockService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param checkOutCheckInService the service dealing with working copies
|
||||
*/
|
||||
public void setCheckOutCheckInService(CheckOutCheckInService checkOutCheckInService)
|
||||
{
|
||||
this.checkOutCheckInService = checkOutCheckInService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param policyBehaviourFilter BehaviourFilter
|
||||
*/
|
||||
public void setPolicyBehaviourFilter(BehaviourFilter policyBehaviourFilter)
|
||||
{
|
||||
this.policyBehaviourFilter = policyBehaviourFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise method
|
||||
*/
|
||||
public void init()
|
||||
{
|
||||
// Register copy behaviour for the working copy aspect
|
||||
this.policyComponent.bindClassBehaviour(
|
||||
CopyServicePolicies.OnCopyNodePolicy.QNAME,
|
||||
ContentModel.TYPE_CMOBJECT,
|
||||
new JavaBehaviour(this, "getCopyCallback"));
|
||||
this.policyComponent.bindClassBehaviour(
|
||||
CopyServicePolicies.OnCopyNodePolicy.QNAME,
|
||||
ContentModel.ASPECT_WORKING_COPY,
|
||||
new JavaBehaviour(this, "getCopyCallback"));
|
||||
this.policyComponent.bindClassBehaviour(
|
||||
CopyServicePolicies.OnCopyNodePolicy.QNAME,
|
||||
ContentModel.ASPECT_CHECKED_OUT,
|
||||
new JavaBehaviour(this, "getCopyCallback"));
|
||||
|
||||
// register onBeforeDelete class behaviour for the working copy aspect
|
||||
this.policyComponent.bindClassBehaviour(
|
||||
NodeServicePolicies.BeforeDeleteNodePolicy.QNAME,
|
||||
ContentModel.ASPECT_WORKING_COPY,
|
||||
new JavaBehaviour(this, "beforeDeleteWorkingCopy"));
|
||||
|
||||
// Watch for removal of the aspect and ensure that the cm:workingcopylink assoc is removed
|
||||
this.policyComponent.bindClassBehaviour(
|
||||
NodeServicePolicies.OnRemoveAspectPolicy.QNAME,
|
||||
ContentModel.ASPECT_WORKING_COPY,
|
||||
new JavaBehaviour(this, "onRemoveAspect"));
|
||||
|
||||
this.policyComponent.bindAssociationBehaviour(
|
||||
NodeServicePolicies.OnDeleteAssociationPolicy.QNAME,
|
||||
ContentModel.ASPECT_CMIS_CREATED_CHECKEDOUT,
|
||||
ContentModel.ASSOC_WORKING_COPY_LINK,
|
||||
new JavaBehaviour(this, "onDeleteCmisCreatedCheckoutWorkingCopyAssociation"));
|
||||
}
|
||||
|
||||
/**
|
||||
* beforeDeleteNode policy behaviour
|
||||
*
|
||||
* @param nodeRef the node reference about to be deleted
|
||||
*/
|
||||
public void beforeDeleteWorkingCopy(NodeRef nodeRef)
|
||||
{
|
||||
NodeRef checkedOutNodeRef = checkOutCheckInService.getCheckedOut(nodeRef);
|
||||
if (checkedOutNodeRef != null)
|
||||
{
|
||||
policyBehaviourFilter.disableBehaviour(checkedOutNodeRef, ContentModel.ASPECT_AUDITABLE);
|
||||
try
|
||||
{
|
||||
lockService.unlock(checkedOutNodeRef, false, true);
|
||||
nodeService.removeAspect(checkedOutNodeRef, ContentModel.ASPECT_CHECKED_OUT);
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
policyBehaviourFilter.enableBehaviour(checkedOutNodeRef, ContentModel.ASPECT_AUDITABLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* onDeleteAssociation policy behaviour If the node has the aspect ASPECT_CMIS_CREATED_CHECKEDOUT and ASSOC_WORKING_COPY_LINK association is deleted, delete the node. Fix for MNT-14850.
|
||||
*
|
||||
* @param nodeAssocRef ASSOC_WORKING_COPY_LINK association where the source is the checkedOut node and the target is the workingCopy
|
||||
*/
|
||||
public void onDeleteCmisCreatedCheckoutWorkingCopyAssociation(AssociationRef nodeAssocRef)
|
||||
{
|
||||
NodeRef checkedOutNodeRef = nodeAssocRef.getSourceRef();
|
||||
policyBehaviourFilter.disableBehaviour(checkedOutNodeRef, ContentModel.ASPECT_AUDITABLE);
|
||||
try
|
||||
{
|
||||
|
||||
nodeService.deleteNode(checkedOutNodeRef);
|
||||
}
|
||||
finally
|
||||
{
|
||||
policyBehaviourFilter.enableBehaviour(checkedOutNodeRef, ContentModel.ASPECT_AUDITABLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemoveAspect(NodeRef nodeRef, QName aspectTypeQName)
|
||||
{
|
||||
// This is simply not allowed.
|
||||
throw new UnsupportedOperationException("Use CheckOutCheckInservice to manipulate working copies.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns CopyBehaviourCallback
|
||||
*/
|
||||
public CopyBehaviourCallback getCopyCallback(QName classRef, CopyDetails copyDetails)
|
||||
{
|
||||
return this.workingCopyAspectCopyBehaviourCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dual behaviour to ensure that <b>cm:name</b> is not copied if the source node has the
|
||||
* <b>cm:workingCopy</b> aspect, and to prevent the <b>cm:workingCopy</b> aspect from
|
||||
* being carried to the new node.
|
||||
*
|
||||
* @author Derek Hulley
|
||||
* @since 3.2
|
||||
*/
|
||||
private class WorkingCopyAspectCopyBehaviourCallback extends DefaultCopyBehaviourCallback
|
||||
{
|
||||
/**
|
||||
* Disallows copying of the {@link ContentModel#ASPECT_WORKING_COPY <b>cm:workingCopy</b>} aspect.
|
||||
*/
|
||||
@Override
|
||||
public boolean getMustCopy(QName classQName, CopyDetails copyDetails)
|
||||
{
|
||||
if (classQName.equals(ContentModel.ASPECT_WORKING_COPY))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows copy of workingCopy top-level node to be renamed
|
||||
*/
|
||||
@Override
|
||||
public boolean isTopLevelCanBeRenamed(QName classQName, CopyDetails copyDetails)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents copying off the {@link ContentModel#PROP_NAME <b>cm:name</b>} property.
|
||||
*/
|
||||
@Override
|
||||
public Map<QName, Serializable> getCopyProperties(
|
||||
QName classQName,
|
||||
CopyDetails copyDetails,
|
||||
Map<QName, Serializable> properties)
|
||||
{
|
||||
if (classQName.equals(ContentModel.ASPECT_WORKING_COPY))
|
||||
{
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
else if (copyDetails.getSourceNodeAspectQNames().contains(ContentModel.ASPECT_WORKING_COPY))
|
||||
{
|
||||
// Generate a new name for a new copy of a working copy
|
||||
String newName = null;
|
||||
|
||||
if (copyDetails.isTargetNodeIsNew())
|
||||
{
|
||||
// This is a copy of a working copy to a new node (not a check in). Try to derive a new name from the
|
||||
// node it is checked out from
|
||||
NodeRef checkedOutFrom = checkOutCheckInService.getCheckedOut(copyDetails.getSourceNodeRef());
|
||||
if (checkedOutFrom != null)
|
||||
{
|
||||
String oldName = (String) nodeService.getProperty(checkedOutFrom, ContentModel.PROP_NAME);
|
||||
int extIndex = oldName.lastIndexOf('.');
|
||||
newName = extIndex == -1 ? oldName + "_" + GUID.generate() : oldName.substring(0, extIndex)
|
||||
+ "_" + GUID.generate() + oldName.substring(extIndex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// This is a check-in i.e. a copy to an existing node, so keep a null cm:name
|
||||
}
|
||||
|
||||
if (newName == null)
|
||||
{
|
||||
properties.remove(ContentModel.PROP_NAME);
|
||||
}
|
||||
else
|
||||
{
|
||||
properties.put(ContentModel.PROP_NAME, newName);
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
else
|
||||
{
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
package org.alfresco.repo.coci;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.copy.CopyBehaviourCallback;
|
||||
import org.alfresco.repo.copy.CopyDetails;
|
||||
import org.alfresco.repo.copy.CopyServicePolicies;
|
||||
import org.alfresco.repo.copy.DefaultCopyBehaviourCallback;
|
||||
import org.alfresco.repo.node.NodeServicePolicies;
|
||||
import org.alfresco.repo.policy.BehaviourFilter;
|
||||
import org.alfresco.repo.policy.JavaBehaviour;
|
||||
import org.alfresco.repo.policy.PolicyComponent;
|
||||
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
|
||||
import org.alfresco.service.cmr.lock.LockService;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.GUID;
|
||||
|
||||
public class WorkingCopyAspect implements CopyServicePolicies.OnCopyNodePolicy, NodeServicePolicies.OnRemoveAspectPolicy
|
||||
{
|
||||
private PolicyComponent policyComponent;
|
||||
private NodeService nodeService;
|
||||
private LockService lockService;
|
||||
private CheckOutCheckInService checkOutCheckInService;
|
||||
private BehaviourFilter policyBehaviourFilter;
|
||||
|
||||
|
||||
/**
|
||||
* The working copy aspect copy behaviour callback.
|
||||
*/
|
||||
private WorkingCopyAspectCopyBehaviourCallback workingCopyAspectCopyBehaviourCallback = new WorkingCopyAspectCopyBehaviourCallback();
|
||||
|
||||
/**
|
||||
* Sets the policy component
|
||||
*/
|
||||
public void setPolicyComponent(PolicyComponent policyComponent)
|
||||
{
|
||||
this.policyComponent = policyComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the node service
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the lock service
|
||||
*/
|
||||
public void setLockService(LockService lockService)
|
||||
{
|
||||
this.lockService = lockService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param checkOutCheckInService the service dealing with working copies
|
||||
*/
|
||||
public void setCheckOutCheckInService(CheckOutCheckInService checkOutCheckInService)
|
||||
{
|
||||
this.checkOutCheckInService = checkOutCheckInService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param policyBehaviourFilter BehaviourFilter
|
||||
*/
|
||||
public void setPolicyBehaviourFilter(BehaviourFilter policyBehaviourFilter)
|
||||
{
|
||||
this.policyBehaviourFilter = policyBehaviourFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise method
|
||||
*/
|
||||
public void init()
|
||||
{
|
||||
// Register copy behaviour for the working copy aspect
|
||||
this.policyComponent.bindClassBehaviour(
|
||||
CopyServicePolicies.OnCopyNodePolicy.QNAME,
|
||||
ContentModel.TYPE_CMOBJECT,
|
||||
new JavaBehaviour(this, "getCopyCallback"));
|
||||
this.policyComponent.bindClassBehaviour(
|
||||
CopyServicePolicies.OnCopyNodePolicy.QNAME,
|
||||
ContentModel.ASPECT_WORKING_COPY,
|
||||
new JavaBehaviour(this, "getCopyCallback"));
|
||||
this.policyComponent.bindClassBehaviour(
|
||||
CopyServicePolicies.OnCopyNodePolicy.QNAME,
|
||||
ContentModel.ASPECT_CHECKED_OUT,
|
||||
new JavaBehaviour(this, "getCopyCallback"));
|
||||
|
||||
// register onBeforeDelete class behaviour for the working copy aspect
|
||||
this.policyComponent.bindClassBehaviour(
|
||||
NodeServicePolicies.BeforeDeleteNodePolicy.QNAME,
|
||||
ContentModel.ASPECT_WORKING_COPY,
|
||||
new JavaBehaviour(this, "beforeDeleteWorkingCopy"));
|
||||
|
||||
// Watch for removal of the aspect and ensure that the cm:workingcopylink assoc is removed
|
||||
this.policyComponent.bindClassBehaviour(
|
||||
NodeServicePolicies.OnRemoveAspectPolicy.QNAME,
|
||||
ContentModel.ASPECT_WORKING_COPY,
|
||||
new JavaBehaviour(this, "onRemoveAspect"));
|
||||
|
||||
this.policyComponent.bindAssociationBehaviour(
|
||||
NodeServicePolicies.OnDeleteAssociationPolicy.QNAME,
|
||||
ContentModel.ASPECT_CMIS_CREATED_CHECKEDOUT,
|
||||
ContentModel.ASSOC_WORKING_COPY_LINK,
|
||||
new JavaBehaviour(this, "onDeleteCmisCreatedCheckoutWorkingCopyAssociation"));
|
||||
}
|
||||
|
||||
/**
|
||||
* beforeDeleteNode policy behaviour
|
||||
*
|
||||
* @param nodeRef the node reference about to be deleted
|
||||
*/
|
||||
public void beforeDeleteWorkingCopy(NodeRef nodeRef)
|
||||
{
|
||||
NodeRef checkedOutNodeRef = checkOutCheckInService.getCheckedOut(nodeRef);
|
||||
if (checkedOutNodeRef != null)
|
||||
{
|
||||
policyBehaviourFilter.disableBehaviour(checkedOutNodeRef, ContentModel.ASPECT_AUDITABLE);
|
||||
try
|
||||
{
|
||||
lockService.unlock(checkedOutNodeRef, false, true);
|
||||
nodeService.removeAspect(checkedOutNodeRef, ContentModel.ASPECT_CHECKED_OUT);
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
policyBehaviourFilter.enableBehaviour(checkedOutNodeRef, ContentModel.ASPECT_AUDITABLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* onDeleteAssociation policy behaviour If the node has the aspect ASPECT_CMIS_CREATED_CHECKEDOUT and ASSOC_WORKING_COPY_LINK association is deleted, delete the node. Fix for MNT-14850.
|
||||
*
|
||||
* @param nodeAssocRef ASSOC_WORKING_COPY_LINK association where the source is the checkedOut node and the target is the workingCopy
|
||||
*/
|
||||
public void onDeleteCmisCreatedCheckoutWorkingCopyAssociation(AssociationRef nodeAssocRef)
|
||||
{
|
||||
NodeRef checkedOutNodeRef = nodeAssocRef.getSourceRef();
|
||||
policyBehaviourFilter.disableBehaviour(checkedOutNodeRef, ContentModel.ASPECT_AUDITABLE);
|
||||
try
|
||||
{
|
||||
|
||||
nodeService.deleteNode(checkedOutNodeRef);
|
||||
}
|
||||
finally
|
||||
{
|
||||
policyBehaviourFilter.enableBehaviour(checkedOutNodeRef, ContentModel.ASPECT_AUDITABLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemoveAspect(NodeRef nodeRef, QName aspectTypeQName)
|
||||
{
|
||||
// This is simply not allowed.
|
||||
throw new UnsupportedOperationException("Use CheckOutCheckInservice to manipulate working copies.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns CopyBehaviourCallback
|
||||
*/
|
||||
public CopyBehaviourCallback getCopyCallback(QName classRef, CopyDetails copyDetails)
|
||||
{
|
||||
return this.workingCopyAspectCopyBehaviourCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dual behaviour to ensure that <b>cm:name</b> is not copied if the source node has the
|
||||
* <b>cm:workingCopy</b> aspect, and to prevent the <b>cm:workingCopy</b> aspect from
|
||||
* being carried to the new node.
|
||||
*
|
||||
* @author Derek Hulley
|
||||
* @since 3.2
|
||||
*/
|
||||
private class WorkingCopyAspectCopyBehaviourCallback extends DefaultCopyBehaviourCallback
|
||||
{
|
||||
/**
|
||||
* Disallows copying of the {@link ContentModel#ASPECT_WORKING_COPY <b>cm:workingCopy</b>} aspect.
|
||||
*/
|
||||
@Override
|
||||
public boolean getMustCopy(QName classQName, CopyDetails copyDetails)
|
||||
{
|
||||
if (classQName.equals(ContentModel.ASPECT_WORKING_COPY))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows copy of workingCopy top-level node to be renamed
|
||||
*/
|
||||
@Override
|
||||
public boolean isTopLevelCanBeRenamed(QName classQName, CopyDetails copyDetails)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents copying off the {@link ContentModel#PROP_NAME <b>cm:name</b>} property.
|
||||
*/
|
||||
@Override
|
||||
public Map<QName, Serializable> getCopyProperties(
|
||||
QName classQName,
|
||||
CopyDetails copyDetails,
|
||||
Map<QName, Serializable> properties)
|
||||
{
|
||||
if (classQName.equals(ContentModel.ASPECT_WORKING_COPY))
|
||||
{
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
else if (copyDetails.getSourceNodeAspectQNames().contains(ContentModel.ASPECT_WORKING_COPY))
|
||||
{
|
||||
// Generate a new name for a new copy of a working copy
|
||||
String newName = null;
|
||||
|
||||
if (copyDetails.isTargetNodeIsNew())
|
||||
{
|
||||
// This is a copy of a working copy to a new node (not a check in). Try to derive a new name from the
|
||||
// node it is checked out from
|
||||
NodeRef checkedOutFrom = checkOutCheckInService.getCheckedOut(copyDetails.getSourceNodeRef());
|
||||
if (checkedOutFrom != null)
|
||||
{
|
||||
String oldName = (String) nodeService.getProperty(checkedOutFrom, ContentModel.PROP_NAME);
|
||||
int extIndex = oldName.lastIndexOf('.');
|
||||
newName = extIndex == -1 ? oldName + "_" + GUID.generate() : oldName.substring(0, extIndex)
|
||||
+ "_" + GUID.generate() + oldName.substring(extIndex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// This is a check-in i.e. a copy to an existing node, so keep a null cm:name
|
||||
}
|
||||
|
||||
if (newName == null)
|
||||
{
|
||||
properties.remove(ContentModel.PROP_NAME);
|
||||
}
|
||||
else
|
||||
{
|
||||
properties.put(ContentModel.PROP_NAME, newName);
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
else
|
||||
{
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user