mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
.externalToolBuilders
config
source
cpp
java
org
alfresco
email
filesys
jcr
linkvalidation
model
repo
action
activities
admin
attributes
audit
avm
blogIntegration
cache
clt
coci
config
configuration
content
copy
deploy
descriptor
dictionary
domain
exporter
forum
i18n
importer
jscript
lock
model
module
node
ownable
person
policy
preference
processor
remote
rule
search
security
service
site
tagging
template
tenant
thumbnail
transaction
usage
version
common
counter
versionlabel
AbstractVersionServiceImpl.java
VersionHistoryImpl.java
VersionHistoryImplTest.java
VersionImpl.java
VersionImplTest.java
VersionLabelComparator.java
VersionUtil.java
BaseVersionStoreTest.java
ContentServiceImplTest.java
NodeServiceImpl.java
NodeServiceImplTest.java
VersionModel.java
VersionServiceImpl.java
VersionServiceImplTest.java
VersionServicePolicies.java
VersionStoreBaseTest_model.xml
VersionTestSuite.java
VersionableAspect.java
version_model.xml
workflow
sandbox
service
tools
util
apache
queryRegister.dtd
meta-inf
test-resources
web
.classpath
.project
build.xml
6580: AVM bulk import performance tweaks. 6582: WCM-767, WCM-768 6583: Fix for AWC-1528 (potential NPE in ErrorsRenderer) 6584: Fix for AWC-1256 (Links produced by inline HTML editor are incorrect) 6585: AR-1635: event listeners added in a beforeCommit event are now executed successfully 6586: AR-1561 Update Web Scripts readme.html to be consistent with "Category Search Sample" (or vice-versa) 6587: Fix for AWC-1390 (Paste all doesn't work for forum items) 6588: AR-1701 Script getDocument call doesn't check for non-existent content 6589: Fix for AWC-1530 - Saved search does not work for custom properties of type d:text with list constraint 6591: Improvement for submit speed. 6592: Removed obsolete tests. 6594: Index tracking sample to include AVM index tracking 6595: Added the AVM helpers methods from the FreeMarker AVM API that were missing from the JavaScript API 6597: Rationalize post commit execution hooks for deployment receiver 6598: Properly escape path names for ProgramRunnable. 6599: AVM store name lookup cache is (theoretically) clusterable. 6600: Some or other gramatically incorrect stuff about Chiba. 6601: Fix for AR-1121 and AR-1673 6602: AR-1655: Versioning is not MLText aware 6603: Updated messages from lang packs 6604: Fixed AR-1476: JCR import end element escaping 6605: Updated Japanese lang messages git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6746 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
318 lines
11 KiB
Java
318 lines
11 KiB
Java
/*
|
|
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
* As a special exception to the terms and conditions of version 2.0 of
|
|
* the GPL, you may redistribute this Program in connection with Free/Libre
|
|
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
|
* FLOSS exception. You should have recieved a copy of the text describing
|
|
* the FLOSS exception, and it is also available here:
|
|
* http://www.alfresco.com/legal/licensing"
|
|
*/
|
|
package org.alfresco.repo.version.common;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.Collection;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
|
|
import org.alfresco.repo.node.MLPropertyInterceptor;
|
|
import org.alfresco.repo.policy.ClassPolicyDelegate;
|
|
import org.alfresco.repo.policy.PolicyComponent;
|
|
import org.alfresco.repo.policy.PolicyScope;
|
|
import org.alfresco.repo.version.VersionServicePolicies;
|
|
import org.alfresco.repo.version.VersionServicePolicies.AfterCreateVersionPolicy;
|
|
import org.alfresco.repo.version.VersionServicePolicies.BeforeCreateVersionPolicy;
|
|
import org.alfresco.repo.version.VersionServicePolicies.CalculateVersionLabelPolicy;
|
|
import org.alfresco.repo.version.VersionServicePolicies.OnCreateVersionPolicy;
|
|
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
|
|
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
|
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
|
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
|
import org.alfresco.service.cmr.repository.AssociationRef;
|
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
|
import org.alfresco.service.cmr.repository.NodeRef;
|
|
import org.alfresco.service.cmr.repository.NodeService;
|
|
import org.alfresco.service.cmr.version.Version;
|
|
import org.alfresco.service.cmr.version.VersionServiceException;
|
|
import org.alfresco.service.namespace.QName;
|
|
import org.alfresco.service.namespace.RegexQNamePattern;
|
|
|
|
/**
|
|
* Abstract version service implementation.
|
|
*
|
|
* @author Roy Wetherall
|
|
*/
|
|
public abstract class AbstractVersionServiceImpl
|
|
{
|
|
/**
|
|
* The common node service
|
|
*/
|
|
protected NodeService nodeService ;
|
|
|
|
/**
|
|
* Policy component
|
|
*/
|
|
protected PolicyComponent policyComponent;
|
|
|
|
/**
|
|
* The dictionary service
|
|
*/
|
|
protected DictionaryService dictionaryService;
|
|
|
|
/**
|
|
* Policy delegates
|
|
*/
|
|
private ClassPolicyDelegate<BeforeCreateVersionPolicy> beforeCreateVersionDelegate;
|
|
private ClassPolicyDelegate<AfterCreateVersionPolicy> afterCreateVersionDelegate;
|
|
private ClassPolicyDelegate<OnCreateVersionPolicy> onCreateVersionDelegate;
|
|
private ClassPolicyDelegate<CalculateVersionLabelPolicy> calculateVersionLabelDelegate;
|
|
|
|
/**
|
|
* Sets the general node service
|
|
*
|
|
* @param nodeService the node service
|
|
*/
|
|
public void setNodeService(NodeService nodeService)
|
|
{
|
|
this.nodeService = nodeService;
|
|
}
|
|
|
|
/**
|
|
* Sets the policy component
|
|
*
|
|
* @param policyComponent the policy component
|
|
*/
|
|
public void setPolicyComponent(PolicyComponent policyComponent)
|
|
{
|
|
this.policyComponent = policyComponent;
|
|
}
|
|
|
|
/**
|
|
* Sets the dictionary service
|
|
*
|
|
* @param dictionaryService the dictionary service
|
|
*/
|
|
public void setDictionaryService(DictionaryService dictionaryService)
|
|
{
|
|
this.dictionaryService = dictionaryService;
|
|
}
|
|
|
|
/**
|
|
* Initialise method
|
|
*/
|
|
public void initialise()
|
|
{
|
|
// Register the policies
|
|
this.beforeCreateVersionDelegate = this.policyComponent.registerClassPolicy(VersionServicePolicies.BeforeCreateVersionPolicy.class);
|
|
this.afterCreateVersionDelegate = this.policyComponent.registerClassPolicy(VersionServicePolicies.AfterCreateVersionPolicy.class);
|
|
this.onCreateVersionDelegate = this.policyComponent.registerClassPolicy(VersionServicePolicies.OnCreateVersionPolicy.class);
|
|
this.calculateVersionLabelDelegate = this.policyComponent.registerClassPolicy(VersionServicePolicies.CalculateVersionLabelPolicy.class);
|
|
}
|
|
|
|
/**
|
|
* Invokes the before create version policy behaviour
|
|
*
|
|
* @param nodeRef the node being versioned
|
|
*/
|
|
protected void invokeBeforeCreateVersion(NodeRef nodeRef)
|
|
{
|
|
// invoke for node type
|
|
QName nodeTypeQName = nodeService.getType(nodeRef);
|
|
this.beforeCreateVersionDelegate.get(nodeTypeQName).beforeCreateVersion(nodeRef);
|
|
// invoke for node aspects
|
|
Set<QName> nodeAspectQNames = nodeService.getAspects(nodeRef);
|
|
this.beforeCreateVersionDelegate.get(nodeAspectQNames).beforeCreateVersion(nodeRef);
|
|
}
|
|
|
|
/**
|
|
* Invoke the after create version policy bahaviour
|
|
*
|
|
* @param nodeRef the nodeRef versioned
|
|
* @param version the created version
|
|
*/
|
|
protected void invokeAfterCreateVersion(NodeRef nodeRef, Version version)
|
|
{
|
|
// invoke for node type
|
|
QName nodeTypeQName = nodeService.getType(nodeRef);
|
|
this.afterCreateVersionDelegate.get(nodeTypeQName).afterCreateVersion(nodeRef, version);
|
|
// invoke for node aspects
|
|
Set<QName> nodeAspectQNames = nodeService.getAspects(nodeRef);
|
|
this.afterCreateVersionDelegate.get(nodeAspectQNames).afterCreateVersion(nodeRef, version);
|
|
}
|
|
|
|
/**
|
|
* Invoke the on create version policy behaviour
|
|
*
|
|
*/
|
|
protected void invokeOnCreateVersion(
|
|
NodeRef nodeRef,
|
|
Map<String, Serializable> versionProperties,
|
|
PolicyScope nodeDetails)
|
|
{
|
|
// Sort out the policies for the node type
|
|
QName classRef = this.nodeService.getType(nodeRef);
|
|
invokeOnCreateVersion(classRef, nodeRef, versionProperties, nodeDetails);
|
|
|
|
// Sort out the policies for the aspects
|
|
Collection<QName> aspects = this.nodeService.getAspects(nodeRef);
|
|
for (QName aspect : aspects)
|
|
{
|
|
invokeOnCreateVersion(aspect, nodeRef, versionProperties, nodeDetails);
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Invokes the on create version policy behaviour for a given type
|
|
*
|
|
* @param classRef
|
|
* @param nodeDetails
|
|
* @param nodeRef
|
|
* @param versionProperties
|
|
*/
|
|
private void invokeOnCreateVersion(
|
|
QName classRef,
|
|
NodeRef nodeRef,
|
|
Map<String, Serializable> versionProperties,
|
|
PolicyScope nodeDetails)
|
|
{
|
|
Collection<OnCreateVersionPolicy> policies = this.onCreateVersionDelegate.getList(classRef);
|
|
if (policies.size() == 0)
|
|
{
|
|
// Call the default implementation
|
|
defaultOnCreateVersion(
|
|
classRef,
|
|
nodeRef,
|
|
versionProperties,
|
|
nodeDetails);
|
|
}
|
|
else
|
|
{
|
|
// Call the policy definitions
|
|
for (VersionServicePolicies.OnCreateVersionPolicy policy : policies)
|
|
{
|
|
policy.onCreateVersion(
|
|
classRef,
|
|
nodeRef,
|
|
versionProperties,
|
|
nodeDetails);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Default implementation of the on create version policy. Called if no behaviour is registered for the
|
|
* policy for the specified type.
|
|
*
|
|
* @param nodeRef
|
|
* @param versionProperties
|
|
* @param nodeDetails
|
|
*/
|
|
protected void defaultOnCreateVersion(
|
|
QName classRef,
|
|
NodeRef nodeRef,
|
|
Map<String, Serializable> versionProperties,
|
|
PolicyScope nodeDetails)
|
|
{
|
|
ClassDefinition classDefinition = this.dictionaryService.getClass(classRef);
|
|
if (classDefinition != null)
|
|
{
|
|
boolean wasMLAware = MLPropertyInterceptor.setMLAware(true);
|
|
try
|
|
{
|
|
// Copy the properties
|
|
Map<QName,PropertyDefinition> propertyDefinitions = classDefinition.getProperties();
|
|
for (QName propertyName : propertyDefinitions.keySet())
|
|
{
|
|
Serializable propValue = this.nodeService.getProperty(nodeRef, propertyName);
|
|
nodeDetails.addProperty(classRef, propertyName, propValue);
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
MLPropertyInterceptor.setMLAware(wasMLAware);
|
|
}
|
|
|
|
// Version the associations (child and target)
|
|
Map<QName, AssociationDefinition> assocDefs = classDefinition.getAssociations();
|
|
|
|
// TODO: Need way of getting child assocs of a given type
|
|
if (classDefinition.isContainer())
|
|
{
|
|
List<ChildAssociationRef> childAssocRefs = this.nodeService.getChildAssocs(nodeRef);
|
|
for (ChildAssociationRef childAssocRef : childAssocRefs)
|
|
{
|
|
if (assocDefs.containsKey(childAssocRef.getTypeQName()))
|
|
{
|
|
nodeDetails.addChildAssociation(classDefinition.getName(), childAssocRef);
|
|
}
|
|
}
|
|
}
|
|
|
|
// TODO: Need way of getting assocs of a given type
|
|
List<AssociationRef> nodeAssocRefs = this.nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL);
|
|
for (AssociationRef nodeAssocRef : nodeAssocRefs)
|
|
{
|
|
if (assocDefs.containsKey(nodeAssocRef.getTypeQName()))
|
|
{
|
|
nodeDetails.addAssociation(classDefinition.getName(), nodeAssocRef);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Invoke the calculate version label policy behaviour
|
|
*
|
|
* @param classRef
|
|
* @param preceedingVersion
|
|
* @param versionNumber
|
|
* @param versionProperties
|
|
* @return
|
|
*/
|
|
protected String invokeCalculateVersionLabel(
|
|
QName classRef,
|
|
Version preceedingVersion,
|
|
int versionNumber,
|
|
Map<String, Serializable>versionProperties)
|
|
{
|
|
String versionLabel = null;
|
|
|
|
Collection<CalculateVersionLabelPolicy> behaviours = this.calculateVersionLabelDelegate.getList(classRef);
|
|
if (behaviours.size() == 0)
|
|
{
|
|
// Default the version label to the version numbder
|
|
versionLabel = Integer.toString(versionNumber);
|
|
}
|
|
else if (behaviours.size() == 1)
|
|
{
|
|
// Call the policy behaviour
|
|
CalculateVersionLabelPolicy[] arr = behaviours.toArray(new CalculateVersionLabelPolicy[]{});
|
|
versionLabel = arr[0].calculateVersionLabel(classRef, preceedingVersion, versionNumber, versionProperties);
|
|
}
|
|
else
|
|
{
|
|
// Error since we can only deal with a single caculate version label policy
|
|
throw new VersionServiceException("More than one CalculateVersionLabelPolicy behaviour has been registered for the type " + classRef.toString());
|
|
}
|
|
|
|
return versionLabel;
|
|
}
|
|
|
|
}
|