Merged BRANCHES/V3.2 to HEAD:

19177: (RECORD ONLY) Updated record-only entries for V3.1 branch
   19321: (RECORD ONLY) Removed deep svn:mergeinfo
   19331: (RECORD ONLY) Merged HEAD to BRANCHES/V3.2:
        19324: Follow-up on ALF-765 by upgrading EHCache to 2.0.0Performing merge across the whole of the branch
   19526: Moved ContentServicePolicy static QNames onto policy classes
   19539: (RECORD ONLY) Merged HEAD to V3.2
         19538: Build fix - fix build speed
   19541: Added extraction of custom, mapped metadata from PDF documents
   19543: (RECORD ONLY) Removed deep svn:mergeinfo
   19598: (RECORD ONLY) Backported (merge not possible) HEAD rev 18790 for IndexInfo fixes
   19626: Fix for ALF-732:  Possible memory leak using the .getNodeRefs() method against a ResultSet ...
   19629: (RECORD ONLY) Merged HEAD to V3.2
        19625: Fix to allow Share logo to swapped out for a different one without having to modify the header CSS.
        19628: Corrected Share header component height.
   19649: ALF-885: Cannot retrieve cm:title from an AVM node in FreeMarker (if persisted with actual type set to MLText)
   19694: (RECORD ONLY) Merged V3.2 to HEAD: r19310 bad back merge - record-only
   19713: (RECORD ONLY) Removed svn:mergeinfo


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19719 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2010-04-01 01:05:03 +00:00
parent f11ce22967
commit f27434f2c6
10 changed files with 562 additions and 513 deletions

View File

@@ -32,9 +32,11 @@ import org.alfresco.service.namespace.QName;
*/
public interface ContentServicePolicies
{
/** The QName's of the policies */
/** @deprecated Use {@link OnContentUpdatePolicy#QNAME} */
public static final QName ON_CONTENT_UPDATE = QName.createQName(NamespaceService.ALFRESCO_URI, "onContentUpdate");
/** @deprecated Use {@link OnContentPropertyUpdatePolicy#QNAME} */
public static final QName ON_CONTENT_PROPERTY_UPDATE = QName.createQName(NamespaceService.ALFRESCO_URI, "onContentPropertyUpdate");
/** @deprecated Use {@link OnContentReadPolicy#QNAME} */
public static final QName ON_CONTENT_READ = QName.createQName(NamespaceService.ALFRESCO_URI, "onContentRead");
/**
@@ -44,6 +46,7 @@ public interface ContentServicePolicies
*/
public interface OnContentUpdatePolicy extends ClassPolicy
{
public static final QName QNAME = QName.createQName(NamespaceService.ALFRESCO_URI, "onContentUpdate");
/**
* @param nodeRef the node reference
*/
@@ -59,6 +62,7 @@ public interface ContentServicePolicies
*/
public interface OnContentPropertyUpdatePolicy extends ClassPolicy
{
public static final QName QNAME = QName.createQName(NamespaceService.ALFRESCO_URI, "onContentPropertyUpdate");
/**
* @param nodeRef the node reference
* @param propertyQName the name of the property that changed
@@ -86,6 +90,7 @@ public interface ContentServicePolicies
*/
public interface OnContentReadPolicy extends ClassPolicy
{
public static final QName QNAME = QName.createQName(NamespaceService.ALFRESCO_URI, "onContentRead");
/**
* @param nodeRef the node reference
*/

View File

@@ -42,6 +42,7 @@ import org.apache.pdfbox.pdmodel.PDDocumentInformation;
* <b>title:</b> -- cm:title
* <b>subject:</b> -- cm:description
* <b>created:</b> -- cm:created
* <b>Any custom property:</b> -- [not mapped]
* </pre>
*
* TIKA Note - all the fields (plus a few others) are present
@@ -124,7 +125,18 @@ public class PdfBoxMetadataExtracter extends AbstractMappingMetadataExtracter
Date parsedDate = sdf.parse(dateWithoutLeadingDColon);
putRawValue(KEY_CREATED, parsedDate, rawProperties);
}
}
}
// Extract remaining custom properties
for (String customProp : super.getMapping().keySet())
{
if (rawProperties.keySet().contains(customProp))
{
// Ignore it
continue;
}
String customValue = docInfo.getCustomMetadataValue(customProp);
putRawValue(customProp, customValue, rawProperties);
}
}
}
finally

View File

@@ -19,12 +19,12 @@
package org.alfresco.repo.dictionary;
import java.io.Serializable;
import java.util.Collection;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.CopyOnWriteArraySet;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
@@ -39,16 +39,16 @@ import org.alfresco.repo.tenant.TenantAdminService;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.repo.transaction.TransactionListenerAdapter;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.repo.version.Version2Model;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.repo.version.Version2Model;
import org.alfresco.repo.workflow.BPMEngineRegistry;
import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.ConstraintDefinition;
import org.alfresco.service.cmr.dictionary.ConstraintDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryException;
import org.alfresco.service.cmr.dictionary.ModelDefinition;
import org.alfresco.service.cmr.dictionary.NamespaceDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentReader;
@@ -63,7 +63,7 @@ import org.alfresco.service.cmr.workflow.WorkflowService;
import org.alfresco.service.cmr.workflow.WorkflowTaskDefinition;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.GUID;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -122,8 +122,8 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
/** The tenant deployer service */
private TenantAdminService tenantAdminService;
private TransactionService transactionService;
private TransactionService transactionService;
/** Transaction listener */
private DictionaryModelTypeTransactionListener transactionListener;
@@ -210,14 +210,14 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
this.tenantAdminService = tenantAdminService;
}
/**
* Set the transaction service
*/
public void setTransactionService(TransactionService transactionService)
{
this.transactionService = transactionService;
}
/**
* Set the transaction service
*/
public void setTransactionService(TransactionService transactionService)
{
this.transactionService = transactionService;
}
public void setStoreUrls(List<String> storeUrls)
{
this.storeUrls = storeUrls;
@@ -231,38 +231,38 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
{
// Register interest in the onContentUpdate policy for the dictionary model type
policyComponent.bindClassBehaviour(
ContentServicePolicies.ON_CONTENT_UPDATE,
ContentModel.TYPE_DICTIONARY_MODEL,
ContentServicePolicies.OnContentUpdatePolicy.QNAME,
ContentModel.TYPE_DICTIONARY_MODEL,
new JavaBehaviour(this, "onContentUpdate"));
// Register interest in the onUpdateProperties policy for the dictionary model type
policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "onUpdateProperties"),
ContentModel.TYPE_DICTIONARY_MODEL,
ContentModel.TYPE_DICTIONARY_MODEL,
new JavaBehaviour(this, "onUpdateProperties"));
// Register interest in the beforeDeleteNode policy for the dictionary model type
policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "beforeDeleteNode"),
ContentModel.TYPE_DICTIONARY_MODEL,
ContentModel.TYPE_DICTIONARY_MODEL,
new JavaBehaviour(this, "beforeDeleteNode"));
// Register interest in the onDeleteNode policy for the dictionary model type
policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "onDeleteNode"),
ContentModel.TYPE_DICTIONARY_MODEL,
ContentModel.TYPE_DICTIONARY_MODEL,
new JavaBehaviour(this, "onDeleteNode"));
// Register interest in the onRemoveAspect policy
policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "onRemoveAspect"),
this,
this,
new JavaBehaviour(this, "onRemoveAspect"));
// Register interest in the onCreateNode policy
policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateNode"),
this,
this,
new JavaBehaviour(this, "onCreateNode"));
// Create the transaction listener
@@ -276,25 +276,25 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
*/
public void onContentUpdate(NodeRef nodeRef, boolean newContent)
{
if (logger.isTraceEnabled())
{
logger.trace("onContentUpdate: nodeRef="+nodeRef+ " ["+AlfrescoTransactionSupport.getTransactionId()+"]");
}
if (logger.isTraceEnabled())
{
logger.trace("onContentUpdate: nodeRef="+nodeRef+ " ["+AlfrescoTransactionSupport.getTransactionId()+"]");
}
queueModel(nodeRef);
}
@SuppressWarnings("unchecked")
private void queueModel(NodeRef nodeRef)
{
Set<NodeRef> pendingModels = (Set<NodeRef>)AlfrescoTransactionSupport.getResource(KEY_PENDING_MODELS);
if (pendingModels == null)
Set<NodeRef> pendingModels = (Set<NodeRef>)AlfrescoTransactionSupport.getResource(KEY_PENDING_MODELS);
if (pendingModels == null)
{
//pendingModels = Collections.newSetFromMap(new ConcurrentHashMap()); // Java 6
pendingModels = new CopyOnWriteArraySet<NodeRef>();
AlfrescoTransactionSupport.bindResource(KEY_PENDING_MODELS, pendingModels);
//pendingModels = Collections.newSetFromMap(new ConcurrentHashMap()); // Java 6
pendingModels = new CopyOnWriteArraySet<NodeRef>();
AlfrescoTransactionSupport.bindResource(KEY_PENDING_MODELS, pendingModels);
}
pendingModels.add(tenantService.getName(nodeRef));
pendingModels.add(tenantService.getName(nodeRef));
AlfrescoTransactionSupport.bindListener(this.transactionListener);
}
@@ -311,11 +311,11 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
Map<QName, Serializable> before,
Map<QName, Serializable> after)
{
if (logger.isTraceEnabled())
{
logger.trace("onUpdateProperties: nodeRef="+nodeRef+ " ["+AlfrescoTransactionSupport.getTransactionId()+"]");
}
if (logger.isTraceEnabled())
{
logger.trace("onUpdateProperties: nodeRef="+nodeRef+ " ["+AlfrescoTransactionSupport.getTransactionId()+"]");
}
Boolean beforeValue = (Boolean)before.get(ContentModel.PROP_MODEL_ACTIVE);
Boolean afterValue = (Boolean)after.get(ContentModel.PROP_MODEL_ACTIVE);
@@ -336,40 +336,40 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
public void onRemoveAspect(NodeRef nodeRef, QName aspect)
{
if (logger.isTraceEnabled())
{
logger.trace("onRemoveAspect: nodeRef="+nodeRef+ " ["+AlfrescoTransactionSupport.getTransactionId()+"]");
}
// undo/cancel checkout removes the "workingcopy" aspect prior to deleting the node - hence need to track here
if (aspect.equals(ContentModel.ASPECT_WORKING_COPY))
{
AlfrescoTransactionSupport.bindResource(KEY_WORKING_COPY, nodeRef);
}
if (logger.isTraceEnabled())
{
logger.trace("onRemoveAspect: nodeRef="+nodeRef+ " ["+AlfrescoTransactionSupport.getTransactionId()+"]");
}
// undo/cancel checkout removes the "workingcopy" aspect prior to deleting the node - hence need to track here
if (aspect.equals(ContentModel.ASPECT_WORKING_COPY))
{
AlfrescoTransactionSupport.bindResource(KEY_WORKING_COPY, nodeRef);
}
}
@SuppressWarnings("unchecked")
public void beforeDeleteNode(NodeRef nodeRef)
{
boolean workingCopy = nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY);
NodeRef wcNodeRef = (NodeRef)AlfrescoTransactionSupport.getResource(KEY_WORKING_COPY);
if ((wcNodeRef != null) && (wcNodeRef.equals(nodeRef)))
{
workingCopy = true;
}
boolean isVersionNode = nodeRef.getStoreRef().getIdentifier().equals(Version2Model.STORE_ID);
// Ignore if the node is a working copy or version node
if (! (workingCopy || isVersionNode))
boolean workingCopy = nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY);
NodeRef wcNodeRef = (NodeRef)AlfrescoTransactionSupport.getResource(KEY_WORKING_COPY);
if ((wcNodeRef != null) && (wcNodeRef.equals(nodeRef)))
{
workingCopy = true;
}
boolean isVersionNode = nodeRef.getStoreRef().getIdentifier().equals(Version2Model.STORE_ID);
// Ignore if the node is a working copy or version node
if (! (workingCopy || isVersionNode))
{
QName modelName = (QName)this.nodeService.getProperty(nodeRef, ContentModel.PROP_MODEL_NAME);
if (logger.isTraceEnabled())
{
logger.trace("beforeDeleteNode: nodeRef="+nodeRef+" validate model delete (modelName="+modelName+")");
}
if (logger.isTraceEnabled())
{
logger.trace("beforeDeleteNode: nodeRef="+nodeRef+" validate model delete (modelName="+modelName+")");
}
if (modelName != null)
{
// Validate model delete against usages - content and/or workflows
@@ -378,8 +378,8 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
Set<NodeRef> pendingModelDeletes = (Set<NodeRef>)AlfrescoTransactionSupport.getResource(KEY_PENDING_DELETE_MODELS);
if (pendingModelDeletes == null)
{
//pendingModelDeletes = Collections.newSetFromMap(new ConcurrentHashMap()); // Java 6
pendingModelDeletes = new CopyOnWriteArraySet<NodeRef>();
//pendingModelDeletes = Collections.newSetFromMap(new ConcurrentHashMap()); // Java 6
pendingModelDeletes = new CopyOnWriteArraySet<NodeRef>();
AlfrescoTransactionSupport.bindResource(KEY_PENDING_DELETE_MODELS, pendingModelDeletes);
}
pendingModelDeletes.add(tenantService.getName(nodeRef));
@@ -387,26 +387,26 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
AlfrescoTransactionSupport.bindListener(this.transactionListener);
}
}
else
{
if (logger.isTraceEnabled())
{
logger.trace("beforeDeleteNode: nodeRef="+nodeRef+ " ignored ("+(workingCopy ? " workingCopy " : "")+(isVersionNode ? " isVersionNode " : "")+") ["+AlfrescoTransactionSupport.getTransactionId()+"]");
}
}
else
{
if (logger.isTraceEnabled())
{
logger.trace("beforeDeleteNode: nodeRef="+nodeRef+ " ignored ("+(workingCopy ? " workingCopy " : "")+(isVersionNode ? " isVersionNode " : "")+") ["+AlfrescoTransactionSupport.getTransactionId()+"]");
}
}
}
//@SuppressWarnings("unchecked")
//@SuppressWarnings("unchecked")
public void onDeleteNode(ChildAssociationRef childAssocRef, boolean isNodeArchived)
{
/*
/*
NodeRef nodeRef = childAssocRef.getChildRef();
if (logger.isTraceEnabled())
{
logger.trace("onDeleteNode: nodeRef="+nodeRef+ " ["+AlfrescoTransactionSupport.getTransactionId()+"]");
}
if (logger.isTraceEnabled())
{
logger.trace("onDeleteNode: nodeRef="+nodeRef+ " ["+AlfrescoTransactionSupport.getTransactionId()+"]");
}
Set<NodeRef> pendingDeleteModels = (Set<NodeRef>)AlfrescoTransactionSupport.getResource(KEY_PENDING_DELETE_MODELS);
if (pendingDeleteModels != null)
@@ -426,32 +426,32 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
return null;
}
}, tenantSystemUserName);
if (logger.isTraceEnabled())
{
logger.trace("onDeleteNode: Dictionary destroyed ["+AlfrescoTransactionSupport.getTransactionId()+"]");
}
if (logger.isTraceEnabled())
{
logger.trace("onDeleteNode: Dictionary destroyed ["+AlfrescoTransactionSupport.getTransactionId()+"]");
}
}
}
*/
*/
}
public void onCreateNode(ChildAssociationRef childAssocRef)
{
NodeRef nodeRef = childAssocRef.getChildRef();
if (logger.isTraceEnabled())
{
logger.trace("onCreateNode: nodeRef="+nodeRef+ " ["+AlfrescoTransactionSupport.getTransactionId()+"]");
}
if (logger.isTraceEnabled())
{
logger.trace("onCreateNode: nodeRef="+nodeRef+ " ["+AlfrescoTransactionSupport.getTransactionId()+"]");
}
if (nodeService.getType(nodeRef).equals(ContentModel.TYPE_DICTIONARY_MODEL))
{
Boolean value = (Boolean)nodeService.getProperty(nodeRef, ContentModel.PROP_MODEL_ACTIVE);
if ((value != null) && (value == true))
{
queueModel(nodeRef);
}
Boolean value = (Boolean)nodeService.getProperty(nodeRef, ContentModel.PROP_MODEL_ACTIVE);
if ((value != null) && (value == true))
{
queueModel(nodeRef);
}
}
}
@@ -474,81 +474,81 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
this.contentService = contentService;
}
@SuppressWarnings("unchecked")
@Override
public void afterCommit()
{
Set<NodeRef> pendingModels = (Set<NodeRef>)AlfrescoTransactionSupport.getResource(KEY_PENDING_MODELS);
Set<NodeRef> pendingDeleteModels = (Set<NodeRef>)AlfrescoTransactionSupport.getResource(KEY_PENDING_DELETE_MODELS);
if (logger.isTraceEnabled())
{
logger.trace("afterCommit: pendingModelsCnt="+(pendingModels != null ? pendingModels.size() : "0")+
", pendingDeleteModelsCnt="+(pendingDeleteModels != null ? pendingDeleteModels.size() : "0"));
}
Set<String> systemTenants = new HashSet<String>(10);
if (pendingModels != null)
{
// unbind the resource from the transaction
AlfrescoTransactionSupport.unbindResource(KEY_PENDING_MODELS);
for (NodeRef nodeRef : pendingModels)
{
String tenantDomain = tenantService.getDomain(nodeRef.getStoreRef().getIdentifier());
String tenantSystemUserName = tenantService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenantDomain);
systemTenants.add(tenantSystemUserName);
}
}
if (pendingDeleteModels != null)
{
// unbind the resource from the transaction
AlfrescoTransactionSupport.unbindResource(KEY_PENDING_DELETE_MODELS);
for (NodeRef nodeRef : pendingDeleteModels)
{
String tenantDomain = tenantService.getDomain(nodeRef.getStoreRef().getIdentifier());
String tenantSystemUserName = tenantService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenantDomain);
systemTenants.add(tenantSystemUserName);
}
}
if (systemTenants.size() > 0)
{
for (final String tenantSystemUserName : systemTenants)
{
RetryingTransactionCallback<Void> work = new RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
AuthenticationUtil.runAs(new RunAsWork<Object>()
{
public Object doWork()
{
// invalidate - to force lazy re-init
// note: since afterCommit - need to either clear shared cache or destroy in separate txn
dictionaryDAO.destroy();
if (logger.isTraceEnabled())
{
logger.trace("afterCommit: Dictionary destroyed ["+AlfrescoTransactionSupport.getTransactionId()+"]");
}
return null;
}
}, tenantSystemUserName);
return null;
}
};
transactionService.getRetryingTransactionHelper().doInTransaction(work, true, true);
}
}
}
@SuppressWarnings("unchecked")
@Override
public void afterCommit()
{
Set<NodeRef> pendingModels = (Set<NodeRef>)AlfrescoTransactionSupport.getResource(KEY_PENDING_MODELS);
Set<NodeRef> pendingDeleteModels = (Set<NodeRef>)AlfrescoTransactionSupport.getResource(KEY_PENDING_DELETE_MODELS);
if (logger.isTraceEnabled())
{
logger.trace("afterCommit: pendingModelsCnt="+(pendingModels != null ? pendingModels.size() : "0")+
", pendingDeleteModelsCnt="+(pendingDeleteModels != null ? pendingDeleteModels.size() : "0"));
}
Set<String> systemTenants = new HashSet<String>(10);
if (pendingModels != null)
{
// unbind the resource from the transaction
AlfrescoTransactionSupport.unbindResource(KEY_PENDING_MODELS);
for (NodeRef nodeRef : pendingModels)
{
String tenantDomain = tenantService.getDomain(nodeRef.getStoreRef().getIdentifier());
String tenantSystemUserName = tenantService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenantDomain);
systemTenants.add(tenantSystemUserName);
}
}
if (pendingDeleteModels != null)
{
// unbind the resource from the transaction
AlfrescoTransactionSupport.unbindResource(KEY_PENDING_DELETE_MODELS);
for (NodeRef nodeRef : pendingDeleteModels)
{
String tenantDomain = tenantService.getDomain(nodeRef.getStoreRef().getIdentifier());
String tenantSystemUserName = tenantService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenantDomain);
systemTenants.add(tenantSystemUserName);
}
}
if (systemTenants.size() > 0)
{
for (final String tenantSystemUserName : systemTenants)
{
RetryingTransactionCallback<Void> work = new RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
AuthenticationUtil.runAs(new RunAsWork<Object>()
{
public Object doWork()
{
// invalidate - to force lazy re-init
// note: since afterCommit - need to either clear shared cache or destroy in separate txn
dictionaryDAO.destroy();
if (logger.isTraceEnabled())
{
logger.trace("afterCommit: Dictionary destroyed ["+AlfrescoTransactionSupport.getTransactionId()+"]");
}
return null;
}
}, tenantSystemUserName);
return null;
}
};
transactionService.getRetryingTransactionHelper().doInTransaction(work, true, true);
}
}
}
/**
* @see org.alfresco.repo.transaction.TransactionListener#beforeCommit(boolean)
*/
@@ -560,9 +560,9 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
if (pendingModels != null)
{
if (logger.isTraceEnabled())
if (logger.isTraceEnabled())
{
logger.trace("beforeCommit: pendingModelsCnt="+pendingModels.size());
logger.trace("beforeCommit: pendingModelsCnt="+pendingModels.size());
}
for (NodeRef pendingNodeRef : pendingModels)
@@ -576,12 +576,12 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
{
public Object doWork()
{
// Ignore if the node no longer exists
if (! nodeService.exists(nodeRef))
{
return null;
}
// Ignore if the node no longer exists
if (! nodeService.exists(nodeRef))
{
return null;
}
// Find out whether the model is active
boolean isActive = false;
Boolean value = (Boolean)nodeService.getProperty(nodeRef, ContentModel.PROP_MODEL_ACTIVE);
@@ -590,12 +590,12 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
isActive = value.booleanValue();
}
// Ignore if the node is a working copy
if (! (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY)))
// Ignore if the node is a working copy
if (! (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY)))
{
if (isActive == true)
{
// 1. Compile the model and update the details on the node
// 1. Compile the model and update the details on the node
// 2. Re-put the model
ContentReader contentReader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
@@ -605,8 +605,8 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
M2Model m2Model = M2Model.createModel(contentReader.getContentInputStream());
// Try and compile the model
CompiledModel compiledModel= m2Model.compile(dictionaryDAO, namespaceDAO);
ModelDefinition modelDefinition = compiledModel.getModelDefinition();
CompiledModel compiledModel= m2Model.compile(dictionaryDAO, namespaceDAO);
ModelDefinition modelDefinition = compiledModel.getModelDefinition();
// Update the meta data for the model
Map<QName, Serializable> props = nodeService.getProperties(nodeRef);
@@ -617,16 +617,16 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
props.put(ContentModel.PROP_MODEL_VERSION, modelDefinition.getVersion());
nodeService.setProperties(nodeRef, props);
// Validate model against dictionary - could be new, unchanged or updated
validateModel(modelDefinition.getName(), m2Model, compiledModel);
// Validate model against dictionary - could be new, unchanged or updated
validateModel(modelDefinition.getName(), m2Model, compiledModel);
// invalidate - to force lazy re-init
//dictionaryDAO.destroy();
if (logger.isTraceEnabled())
{
logger.trace("beforeCommit: activating nodeRef="+nodeRef+" ("+modelDefinition.getName()+")");
}
//dictionaryDAO.destroy();
if (logger.isTraceEnabled())
{
logger.trace("beforeCommit: activating nodeRef="+nodeRef+" ("+modelDefinition.getName()+")");
}
}
}
else
@@ -638,12 +638,12 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
validateModelDelete(modelName);
// invalidate - to force lazy re-init
//dictionaryDAO.destroy();
if (logger.isTraceEnabled())
{
logger.trace("beforeCommit: deactivating nodeRef="+nodeRef+" ("+modelName+")");
}
//dictionaryDAO.destroy();
if (logger.isTraceEnabled())
{
logger.trace("beforeCommit: deactivating nodeRef="+nodeRef+" ("+modelName+")");
}
}
}
}
@@ -685,7 +685,7 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
private void validateModelDelete(final QName modelName)
{
// TODO add model locking during delete (would need to be tenant-aware & cluster-aware) to avoid potential
// for concurrent addition of new content/workflow as model is being deleted
// for concurrent addition of new content/workflow as model is being deleted
try
{
@@ -693,11 +693,11 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
}
catch (DictionaryException e)
{
if (logger.isDebugEnabled())
{
logger.debug("Dictionary model '" + modelName + "' does not exist ... skip delete validation : " + e);
}
return;
if (logger.isDebugEnabled())
{
logger.debug("Dictionary model '" + modelName + "' does not exist ... skip delete validation : " + e);
}
return;
}
// TODO - in case of MT we do not currently allow deletion of an overridden model (with usages) ... but could allow if (re-)inherited model is equivalent to an incremental update only ?
@@ -803,162 +803,162 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda
}
}
/**
* validate against dictionary
*
* if new model
* then nothing to validate
*
* else if an existing model
* then could be updated (or unchanged) so validate to currently only allow incremental updates
* - addition of new types, aspects (except default aspects), properties, associations
* - no deletion of types, aspects or properties or associations
* - no addition, update or deletion of default/mandatory aspects
*
* @paramn modelName
* @param newOrUpdatedModel
*/
private void validateModel(QName modelName, M2Model model, CompiledModel compiledModel)
{
List<M2ModelDiff> modelDiffs = dictionaryDAO.diffModel(model);
for (M2ModelDiff modelDiff : modelDiffs)
{
if (modelDiff.getDiffType().equals(M2ModelDiff.DIFF_DELETED))
{
// TODO - check tenants if model is shared / inherited
if (modelDiff.getElementType().equals(M2ModelDiff.TYPE_PROPERTY))
{
validatePropertyDelete(modelName, modelDiff.getElementName(), false);
continue;
}
else if (modelDiff.getElementType().equals(M2ModelDiff.TYPE_CONSTRAINT))
{
validateConstraintDelete(compiledModel, modelDiff.getElementName(), false);
continue;
}
else
{
throw new AlfrescoRuntimeException("Failed to validate model update - found deleted " + modelDiff.getElementType() + " '" + modelDiff.getElementName() + "'");
}
}
if (modelDiff.getDiffType().equals(M2ModelDiff.DIFF_UPDATED))
{
throw new AlfrescoRuntimeException("Failed to validate model update - found non-incrementally updated " + modelDiff.getElementType() + " '" + modelDiff.getElementName() + "'");
}
}
// TODO validate that any deleted constraints are not being referenced - else currently will become anon - or push down into model compilation (check backwards compatibility ...)
}
private void validatePropertyDelete(QName modelName, QName propertyName, boolean sharedModel)
{
String tenantDomain = TenantService.DEFAULT_DOMAIN;
if (sharedModel)
{
tenantDomain = " for tenant [" + tenantService.getCurrentUserDomain() + "]";
}
boolean found = false;
// check for property usages
for (PropertyDefinition prop : dictionaryDAO.getProperties(modelName, null))
{
// TODO ... match property
if (prop.getName().equals(propertyName))
{
// found
found = true;
validateIndexedProperty(tenantDomain, prop);
break;
}
}
if (! found)
{
throw new AlfrescoRuntimeException("Failed to validate property delete" + tenantDomain + " - property definition '" + propertyName + "' not defined in model '" + modelName + "'");
}
}
private void validateIndexedProperty(String tenantDomain, PropertyDefinition propDef)
{
QName propName = propDef.getName();
if (! propDef.isIndexed())
{
// TODO ... implement DB-level referential integrity
throw new AlfrescoRuntimeException("Failed to validate property delete" + tenantDomain + " - cannot delete unindexed property definition '" + propName);
}
for (String storeUrl : this.storeUrls)
{
StoreRef store = new StoreRef(storeUrl);
// search for indexed PROPERTY
String escapePropName = propName.toPrefixString().replace(":", "\\:");
ResultSet rs = searchService.query(store, SearchService.LANGUAGE_LUCENE, "@"+escapePropName+":*");
try
{
if (rs.length() > 0)
{
throw new AlfrescoRuntimeException("Failed to validate property delete" + tenantDomain + " - found " + rs.length() + " nodes in store " + store + " with PROPERTY '" + propName + "'" );
}
}
finally
{
rs.close();
}
}
}
// validate delete of a referencable constraint def
private void validateConstraintDelete(CompiledModel compiledModel, QName constraintName, boolean sharedModel)
{
String tenantDomain = TenantService.DEFAULT_DOMAIN;
if (sharedModel)
{
tenantDomain = " for tenant [" + tenantService.getCurrentUserDomain() + "]";
}
Set<QName> referencedBy = new HashSet<QName>(0);
// check for references to constraint definition
// note: could be anon prop constraint (if no referenceable constraint)
Collection<QName> allModels = dictionaryDAO.getModels();
for (QName model : allModels)
{
Collection<PropertyDefinition> propDefs = null;
if (compiledModel.getModelDefinition().getName().equals(model))
{
// TODO deal with multiple pending model updates
propDefs = compiledModel.getProperties();
}
else
{
propDefs = dictionaryDAO.getProperties(model);
}
for (PropertyDefinition propDef : propDefs)
{
for (ConstraintDefinition conDef : propDef.getConstraints())
{
if (constraintName.equals(conDef.getRef()))
{
referencedBy.add(conDef.getName());
}
}
}
}
if (referencedBy.size() == 1)
{
throw new AlfrescoRuntimeException("Failed to validate constraint delete" + tenantDomain + " - constraint definition '" + constraintName + "' is being referenced by '" + referencedBy.toArray()[0] + "' property constraint");
}
else if (referencedBy.size() > 1)
{
throw new AlfrescoRuntimeException("Failed to validate constraint delete" + tenantDomain + " - constraint definition '" + constraintName + "' is being referenced by " + referencedBy.size() + " property constraints");
}
}
/**
* validate against dictionary
*
* if new model
* then nothing to validate
*
* else if an existing model
* then could be updated (or unchanged) so validate to currently only allow incremental updates
* - addition of new types, aspects (except default aspects), properties, associations
* - no deletion of types, aspects or properties or associations
* - no addition, update or deletion of default/mandatory aspects
*
* @paramn modelName
* @param newOrUpdatedModel
*/
private void validateModel(QName modelName, M2Model model, CompiledModel compiledModel)
{
List<M2ModelDiff> modelDiffs = dictionaryDAO.diffModel(model);
for (M2ModelDiff modelDiff : modelDiffs)
{
if (modelDiff.getDiffType().equals(M2ModelDiff.DIFF_DELETED))
{
// TODO - check tenants if model is shared / inherited
if (modelDiff.getElementType().equals(M2ModelDiff.TYPE_PROPERTY))
{
validatePropertyDelete(modelName, modelDiff.getElementName(), false);
continue;
}
else if (modelDiff.getElementType().equals(M2ModelDiff.TYPE_CONSTRAINT))
{
validateConstraintDelete(compiledModel, modelDiff.getElementName(), false);
continue;
}
else
{
throw new AlfrescoRuntimeException("Failed to validate model update - found deleted " + modelDiff.getElementType() + " '" + modelDiff.getElementName() + "'");
}
}
if (modelDiff.getDiffType().equals(M2ModelDiff.DIFF_UPDATED))
{
throw new AlfrescoRuntimeException("Failed to validate model update - found non-incrementally updated " + modelDiff.getElementType() + " '" + modelDiff.getElementName() + "'");
}
}
// TODO validate that any deleted constraints are not being referenced - else currently will become anon - or push down into model compilation (check backwards compatibility ...)
}
private void validatePropertyDelete(QName modelName, QName propertyName, boolean sharedModel)
{
String tenantDomain = TenantService.DEFAULT_DOMAIN;
if (sharedModel)
{
tenantDomain = " for tenant [" + tenantService.getCurrentUserDomain() + "]";
}
boolean found = false;
// check for property usages
for (PropertyDefinition prop : dictionaryDAO.getProperties(modelName, null))
{
// TODO ... match property
if (prop.getName().equals(propertyName))
{
// found
found = true;
validateIndexedProperty(tenantDomain, prop);
break;
}
}
if (! found)
{
throw new AlfrescoRuntimeException("Failed to validate property delete" + tenantDomain + " - property definition '" + propertyName + "' not defined in model '" + modelName + "'");
}
}
private void validateIndexedProperty(String tenantDomain, PropertyDefinition propDef)
{
QName propName = propDef.getName();
if (! propDef.isIndexed())
{
// TODO ... implement DB-level referential integrity
throw new AlfrescoRuntimeException("Failed to validate property delete" + tenantDomain + " - cannot delete unindexed property definition '" + propName);
}
for (String storeUrl : this.storeUrls)
{
StoreRef store = new StoreRef(storeUrl);
// search for indexed PROPERTY
String escapePropName = propName.toPrefixString().replace(":", "\\:");
ResultSet rs = searchService.query(store, SearchService.LANGUAGE_LUCENE, "@"+escapePropName+":*");
try
{
if (rs.length() > 0)
{
throw new AlfrescoRuntimeException("Failed to validate property delete" + tenantDomain + " - found " + rs.length() + " nodes in store " + store + " with PROPERTY '" + propName + "'" );
}
}
finally
{
rs.close();
}
}
}
// validate delete of a referencable constraint def
private void validateConstraintDelete(CompiledModel compiledModel, QName constraintName, boolean sharedModel)
{
String tenantDomain = TenantService.DEFAULT_DOMAIN;
if (sharedModel)
{
tenantDomain = " for tenant [" + tenantService.getCurrentUserDomain() + "]";
}
Set<QName> referencedBy = new HashSet<QName>(0);
// check for references to constraint definition
// note: could be anon prop constraint (if no referenceable constraint)
Collection<QName> allModels = dictionaryDAO.getModels();
for (QName model : allModels)
{
Collection<PropertyDefinition> propDefs = null;
if (compiledModel.getModelDefinition().getName().equals(model))
{
// TODO deal with multiple pending model updates
propDefs = compiledModel.getProperties();
}
else
{
propDefs = dictionaryDAO.getProperties(model);
}
for (PropertyDefinition propDef : propDefs)
{
for (ConstraintDefinition conDef : propDef.getConstraints())
{
if (constraintName.equals(conDef.getRef()))
{
referencedBy.add(conDef.getName());
}
}
}
}
if (referencedBy.size() == 1)
{
throw new AlfrescoRuntimeException("Failed to validate constraint delete" + tenantDomain + " - constraint definition '" + constraintName + "' is being referenced by '" + referencedBy.toArray()[0] + "' property constraint");
}
else if (referencedBy.size() > 1)
{
throw new AlfrescoRuntimeException("Failed to validate constraint delete" + tenantDomain + " - constraint definition '" + constraintName + "' is being referenced by " + referencedBy.size() + " property constraints");
}
}
}

View File

@@ -44,6 +44,7 @@ import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.Path;
import org.alfresco.service.cmr.repository.Period;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.cmr.repository.datatype.TypeConverter.Converter;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.EqualsHelper;
import org.alfresco.util.VersionNumber;
@@ -268,12 +269,36 @@ public class PropertyValue implements Cloneable, Serializable
return ValueType.STRING;
}
}
else if (value instanceof String)
{
return ValueType.STRING;
}
return ValueType.DB_ATTRIBUTE;
}
@SuppressWarnings("unchecked")
@Override
Serializable convert(Serializable value)
{
// NOTE: since 2.2.1, PropertyValue is only used by AVM (which does not natively support MLText, other than single/default string)
if (value != null)
{
if (value instanceof String)
{
return value;
}
else if (value instanceof MLText)
{
if (((MLText)value).size() <= 1)
{
return (String)((Converter<MLText, String>)DefaultTypeConverter.INSTANCE.getConverter(MLText.class, String.class)).convert((MLText)value);
}
else
{
throw new UnsupportedOperationException("PropertyValue MLText is not supported for AVM");
}
}
}
return DefaultTypeConverter.INSTANCE.convert(MLText.class, value);
}
},

View File

@@ -37,7 +37,6 @@ import org.springframework.context.ApplicationContext;
*/
public class PropertyValueTest extends TestCase
{
@SuppressWarnings("unused")
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
public void testMLText()
@@ -54,11 +53,21 @@ public class PropertyValueTest extends TestCase
PropertyValue propertyValue = new PropertyValue(DataTypeDefinition.MLTEXT, mlText);
assertNotNull("MLText not persisted as a string", propertyValue.getStringValue());
// multiple languages
mlText = new MLText(Locale.GERMAN, "hallo");
mlText.addValue(Locale.ITALIAN, "ciao");
propertyValue = new PropertyValue(DataTypeDefinition.MLTEXT, mlText);
assertNotNull("MLText not persisted as an attribute", propertyValue.getAttributeValue());
try
{
// multiple languages
mlText = new MLText(Locale.GERMAN, "hallo");
mlText.addValue(Locale.ITALIAN, "ciao");
propertyValue = new PropertyValue(DataTypeDefinition.MLTEXT, mlText);
assertNotNull("MLText not persisted as an attribute", propertyValue.getAttributeValue());
fail();
}
catch (UnsupportedOperationException uoe)
{
// expected
// NOTE: since 2.2.1, PropertyValue is only used by AVM (which does not natively support MLText, other than single/default string)
}
return null;
}

View File

@@ -76,7 +76,7 @@ public class OnContentUpdateRuleTrigger extends RuleTriggerAbstractBase
{
// Bind behaviour
this.policyComponent.bindClassBehaviour(
ContentServicePolicies.ON_CONTENT_UPDATE,
ContentServicePolicies.OnContentUpdatePolicy.QNAME,
this,
new JavaBehaviour(this, "onContentUpdate"));
}

View File

@@ -18,6 +18,7 @@
*/
package org.alfresco.repo.security.permissions.impl.acegi;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
import java.util.ListIterator;
@@ -120,26 +121,20 @@ public class FilteringResultSet extends ACLEntryAfterInvocationProvider implemen
public List<NodeRef> getNodeRefs()
{
List<NodeRef> answer = unfiltered.getNodeRefs();
for (int i = unfiltered.length() - 1; i >= 0; i--)
ArrayList<NodeRef> answer = new ArrayList<NodeRef>(length());
for(ResultSetRow row : this)
{
if (!inclusionMask.get(i))
{
answer.remove(i);
}
answer.add(row.getNodeRef());
}
return answer;
}
public List<ChildAssociationRef> getChildAssocRefs()
{
List<ChildAssociationRef> answer = unfiltered.getChildAssocRefs();
for (int i = unfiltered.length() - 1; i >= 0; i--)
ArrayList<ChildAssociationRef> answer = new ArrayList<ChildAssociationRef>(length());
for(ResultSetRow row : this)
{
if (!inclusionMask.get(i))
{
answer.remove(i);
}
answer.add(row.getChildAssocRef());
}
return answer;
}

View File

@@ -81,6 +81,9 @@ public class FilteringResultSetTest extends TestCase
filtering.setIncluded(i, true);
assertEquals(1, filtering.length());
assertEquals("n"+i, filtering.getNodeRef(0).getId());
assertEquals(1, filtering.getNodeRefs().size());
assertEquals(1, filtering.getChildAssocRefs().size());
assertEquals("n"+i, filtering.getNodeRefs().get(0).getId());
filtering.setIncluded(i, false);
assertEquals(0, filtering.length());
}

View File

@@ -143,7 +143,7 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
new JavaBehaviour(this, "afterCreateVersion", Behaviour.NotificationFrequency.EVERY_EVENT));
this.policyComponent.bindClassBehaviour(
ContentServicePolicies.ON_CONTENT_UPDATE,
ContentServicePolicies.OnContentUpdatePolicy.QNAME,
ContentModel.ASPECT_VERSIONABLE,
new JavaBehaviour(this, "onContentUpdate", Behaviour.NotificationFrequency.TRANSACTION_COMMIT));

View File

@@ -1,4 +1,4 @@
/*
/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
@@ -14,127 +14,127 @@
* 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.workflow;
import java.io.Serializable;
import java.util.Map;
import org.alfresco.repo.content.ContentServicePolicies;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
/**
* Workflow Definition type behaviour.
*
* @author JanV
*/
public class WorkflowDefinitionType implements ContentServicePolicies.OnContentUpdatePolicy,
NodeServicePolicies.OnUpdatePropertiesPolicy,
NodeServicePolicies.BeforeDeleteNodePolicy
{
/** The policy component */
private PolicyComponent policyComponent;
/** The workflow deployer / undeployer */
private WorkflowDeployer workflowDeployer;
/**
* Set the policy component
*
* @param policyComponent the policy component
*/
public void setPolicyComponent(PolicyComponent policyComponent)
{
this.policyComponent = policyComponent;
}
/**
* Set the workflow deployer / undeployer
*
* @param workflowDeployer the workflow deployer / undeployer
*/
public void setWorkflowDeployer(WorkflowDeployer workflowDeployer)
{
this.workflowDeployer = workflowDeployer;
}
/**
* The initialise method
*/
public void init()
{
// Register interest in the onContentUpdate policy for the workflow definition type
policyComponent.bindClassBehaviour(
ContentServicePolicies.ON_CONTENT_UPDATE,
WorkflowModel.TYPE_WORKFLOW_DEF,
new JavaBehaviour(this, "onContentUpdate"));
// Register interest in the onPropertyUpdate policy for the workflow definition type
policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "onUpdateProperties"),
WorkflowModel.TYPE_WORKFLOW_DEF,
new JavaBehaviour(this, "onUpdateProperties"));
// Register interest in the node delete policy
policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "beforeDeleteNode"),
WorkflowModel.TYPE_WORKFLOW_DEF,
new JavaBehaviour(this, "beforeDeleteNode"));
}
/**
* On content update behaviour implementation
*
* @param nodeRef the node reference whose content has been updated
*/
public void onContentUpdate(NodeRef nodeRef, boolean newContent)
{
workflowDeployer.deploy(nodeRef, true);
}
/**
* On update properties behaviour implementation
*
* @param nodeRef the node reference
* @param before the values of the properties before update
* @param after the values of the properties after the update
*/
public void onUpdateProperties(
NodeRef nodeRef,
Map<QName, Serializable> before,
Map<QName, Serializable> after)
{
Boolean beforeValue = (Boolean)before.get(WorkflowModel.PROP_WORKFLOW_DEF_DEPLOYED);
Boolean afterValue = (Boolean)after.get(WorkflowModel.PROP_WORKFLOW_DEF_DEPLOYED);
if (afterValue != null &&
(beforeValue == null || (beforeValue != null && afterValue != null && beforeValue.equals(afterValue) == false)))
{
if (afterValue.booleanValue() == true)
{
workflowDeployer.deploy(nodeRef, true);
}
else
{
workflowDeployer.undeploy(nodeRef);
}
}
else if (afterValue == null && beforeValue != null)
{
// Undeploy the definition since the value has been cleared
workflowDeployer.undeploy(nodeRef);
}
}
public void beforeDeleteNode(NodeRef nodeRef)
{
workflowDeployer.undeploy(nodeRef);
}
}
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.workflow;
import java.io.Serializable;
import java.util.Map;
import org.alfresco.repo.content.ContentServicePolicies;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
/**
* Workflow Definition type behaviour.
*
* @author JanV
*/
public class WorkflowDefinitionType implements ContentServicePolicies.OnContentUpdatePolicy,
NodeServicePolicies.OnUpdatePropertiesPolicy,
NodeServicePolicies.BeforeDeleteNodePolicy
{
/** The policy component */
private PolicyComponent policyComponent;
/** The workflow deployer / undeployer */
private WorkflowDeployer workflowDeployer;
/**
* Set the policy component
*
* @param policyComponent the policy component
*/
public void setPolicyComponent(PolicyComponent policyComponent)
{
this.policyComponent = policyComponent;
}
/**
* Set the workflow deployer / undeployer
*
* @param workflowDeployer the workflow deployer / undeployer
*/
public void setWorkflowDeployer(WorkflowDeployer workflowDeployer)
{
this.workflowDeployer = workflowDeployer;
}
/**
* The initialise method
*/
public void init()
{
// Register interest in the onContentUpdate policy for the workflow definition type
policyComponent.bindClassBehaviour(
ContentServicePolicies.OnContentUpdatePolicy.QNAME,
WorkflowModel.TYPE_WORKFLOW_DEF,
new JavaBehaviour(this, "onContentUpdate"));
// Register interest in the onPropertyUpdate policy for the workflow definition type
policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "onUpdateProperties"),
WorkflowModel.TYPE_WORKFLOW_DEF,
new JavaBehaviour(this, "onUpdateProperties"));
// Register interest in the node delete policy
policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "beforeDeleteNode"),
WorkflowModel.TYPE_WORKFLOW_DEF,
new JavaBehaviour(this, "beforeDeleteNode"));
}
/**
* On content update behaviour implementation
*
* @param nodeRef the node reference whose content has been updated
*/
public void onContentUpdate(NodeRef nodeRef, boolean newContent)
{
workflowDeployer.deploy(nodeRef, true);
}
/**
* On update properties behaviour implementation
*
* @param nodeRef the node reference
* @param before the values of the properties before update
* @param after the values of the properties after the update
*/
public void onUpdateProperties(
NodeRef nodeRef,
Map<QName, Serializable> before,
Map<QName, Serializable> after)
{
Boolean beforeValue = (Boolean)before.get(WorkflowModel.PROP_WORKFLOW_DEF_DEPLOYED);
Boolean afterValue = (Boolean)after.get(WorkflowModel.PROP_WORKFLOW_DEF_DEPLOYED);
if (afterValue != null &&
(beforeValue == null || (beforeValue != null && afterValue != null && beforeValue.equals(afterValue) == false)))
{
if (afterValue.booleanValue() == true)
{
workflowDeployer.deploy(nodeRef, true);
}
else
{
workflowDeployer.undeploy(nodeRef);
}
}
else if (afterValue == null && beforeValue != null)
{
// Undeploy the definition since the value has been cleared
workflowDeployer.undeploy(nodeRef);
}
}
public void beforeDeleteNode(NodeRef nodeRef)
{
workflowDeployer.undeploy(nodeRef);
}
}