mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user