Dave Ward 2b61b88c4c Merged V4.1-BUG-FIX to HEAD
38869: Merged BRANCHES/DEV/AMILLER/CLOUD1 to BRANCHES/DEV/V4.1-BUG-FIX
      38762: Site can not be created when (site count) quota exceeded
             Refactor core code to return "400 - Bad request," with indicative message, when a duplicate url is submitted.
   38897: ALF-13969: Tomcat shutdown with WARNING: Problem with directory [/opt/alfresco-4.0.1/tomcat/shared/lib], exists: [false], isDirectory: [false], canRead: [false]
   - Removed ${catalina.base}/shared/lib/*.jar from shared.loader definition in catalina.properties
   - Will update Wiki next
   38908: Fix for failing test since createSite change
   38939: Moved schema version up to 5100 (and 5101 for 'patch.show.audit')
   38941: Moved schema version up to 5110 (and 5111 for 'patch.show.audit') ... leave root for V4.1.0.x
   38953: ALF-14766: Ensure that DocLib tree drop targets are correctly set after creating new folders
   38954: Fix for ALF-14475: "CMIS : Wrong cmisra:numItems in folder sites and below with /cmisatom binding url"
   38974: Minor: removed unused code
   38987: ALF-13228 - updated manage permissions to handle custom group settings
   39006: Fix for ALF-14475 part 2: "CMIS : Wrong cmisra:numItems in folder sites and below with /cmisatom binding url"
   39022: Merge solution for ALF-13972
   39038: ALF-14388: Merge V3.4-BUG-FIX (3.4.11) to V4.1-BUG-FIX (4.1.1)
      39037: ALF-15069 CLONE - Edit Online option is not supported for '.docm', 'dotm', '.xlsm' files
         - Added "Online Edit" support for:
           docx docm dotx dotm - doc and docx were already supported
           pptm ppsx ppsm potx potm ppam sldx sldm - ppt and pptx were already supported
           xltx xlsm xltm xlam xlsb - xls and xlsx were already supported
   39065: ALF-14861 SOLR to scale for non-admin users in 100k sites and a subgroup of each of 1000 independent groupings with 1000 subgroups
   - first round of fixes on the SOLR side
     - ACL lookup improved and reduced the number of Long objects created
     - Specific cache and configuration for PATH queries (with admin reporting)
     - Specfic cache and configuration for AUTHORITY queries (with admin reporting)
     - PATH and AUTHORITY queries cache the LEAF result (and not the AUX result which requires lots of extra work)
       -  cache works better with lucene query implementation
    - AUTHORITY query supports AUTHORITIES separated by "|"
   39135: Fix for ALF-15071 SOLR: Typographical offence in log output
   39152: ALF-13211: Accepted path for preventing NPE when viewing JBPM sub-process which has no start-task
   39175: Merge DEV to V4.1-BUG-FIX (4.1.1)
      39161: ALF-14956 : Folder within a Folder navigation issue.
      Fix for browsing to folders from not first page of a parent folder.
   39191: ALF-14863: no scope is available when ScriptNode is used from within Activiti expression, causes issue when scope is needed (eg. creating javascript-arrays) + fixed typo in activiti-source jars
   39192: Fix for ALF-12209 Incorrect behavior on View Realtionship for the user who has no permissions
   - skip relationships to objects that can not be seen.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@40263 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2012-08-09 16:24:57 +00:00

233 lines
8.1 KiB
Java

/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
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.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
{
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
*/
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"));
// register onBeforeDelete class behaviour for the checked-out aspect
}
/**
* 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);
nodeService.removeAspect(checkedOutNodeRef, ContentModel.ASPECT_CHECKED_OUT);
}
finally
{
policyBehaviourFilter.enableBehaviour(checkedOutNodeRef, ContentModel.ASPECT_AUDITABLE);
}
}
}
/**
* @return Returns {@link WorkingCopyAspectCopyBehaviourCallback}
*/
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;
}
}
/**
* 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;
}
}
}
}