From f989d6fa2d4db73680f737f75a507c639dfdbff9 Mon Sep 17 00:00:00 2001 From: Mark Rogers Date: Wed, 23 Jul 2014 14:42:53 +0000 Subject: [PATCH] Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud) 77084: Merged PLATFORM1 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud) 72906: ACE-956 - Configure Hybrid Sync - step 1 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@77933 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/bootstrap-context.xml | 1 + .../repo/dictionary/DictionaryModelType.java | 13 ++- .../DictionaryRepositoryBootstrap.java | 85 ++++++++++++++++--- .../repo/dictionary/DynamicModelPolicies.java | 25 ++++++ 4 files changed, 111 insertions(+), 13 deletions(-) create mode 100644 source/java/org/alfresco/repo/dictionary/DynamicModelPolicies.java diff --git a/config/alfresco/bootstrap-context.xml b/config/alfresco/bootstrap-context.xml index deca0b7235..86b376ac27 100644 --- a/config/alfresco/bootstrap-context.xml +++ b/config/alfresco/bootstrap-context.xml @@ -147,6 +147,7 @@ + diff --git a/source/java/org/alfresco/repo/dictionary/DictionaryModelType.java b/source/java/org/alfresco/repo/dictionary/DictionaryModelType.java index 029c546112..2e45384171 100644 --- a/source/java/org/alfresco/repo/dictionary/DictionaryModelType.java +++ b/source/java/org/alfresco/repo/dictionary/DictionaryModelType.java @@ -251,6 +251,10 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda */ public void init() { + if(logger.isDebugEnabled()) + { + logger.debug("init : bind class behaviours for " + ContentModel.TYPE_DICTIONARY_MODEL); + } // Register interest in the onContentUpdate policy for the dictionary model type policyComponent.bindClassBehaviour( ContentServicePolicies.OnContentUpdatePolicy.QNAME, @@ -298,12 +302,16 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda */ public void onContentUpdate(NodeRef nodeRef, boolean newContent) { - if (logger.isTraceEnabled()) + if (logger.isTraceEnabled()) { logger.trace("onContentUpdate: nodeRef="+nodeRef+ " ["+AlfrescoTransactionSupport.getTransactionId()+"]"); } - queueModel(nodeRef); + Boolean value = (Boolean)nodeService.getProperty(nodeRef, ContentModel.PROP_MODEL_ACTIVE); + if ((value != null) && (value == true)) + { + queueModel(nodeRef); + } } @SuppressWarnings("unchecked") @@ -679,6 +687,7 @@ public class DictionaryModelType implements ContentServicePolicies.OnContentUpda props.put(ContentModel.PROP_MODEL_AUTHOR, modelDefinition.getAuthor()); props.put(ContentModel.PROP_MODEL_PUBLISHED_DATE, modelDefinition.getPublishedDate()); props.put(ContentModel.PROP_MODEL_VERSION, modelDefinition.getVersion()); + nodeService.setProperties(nodeRef, props); // Validate model against dictionary - could be new, unchanged or updated diff --git a/source/java/org/alfresco/repo/dictionary/DictionaryRepositoryBootstrap.java b/source/java/org/alfresco/repo/dictionary/DictionaryRepositoryBootstrap.java index 36607cc6cf..a53996fdd2 100644 --- a/source/java/org/alfresco/repo/dictionary/DictionaryRepositoryBootstrap.java +++ b/source/java/org/alfresco/repo/dictionary/DictionaryRepositoryBootstrap.java @@ -33,6 +33,8 @@ import org.alfresco.model.ContentModel; import org.alfresco.repo.content.EmptyContentReader; import org.alfresco.repo.i18n.MessageDeployer; import org.alfresco.repo.i18n.MessageService; +import org.alfresco.repo.policy.ClassPolicyDelegate; +import org.alfresco.repo.policy.PolicyComponent; import org.alfresco.repo.tenant.TenantAdminService; import org.alfresco.repo.tenant.TenantDeployer; import org.alfresco.repo.tenant.TenantService; @@ -51,11 +53,13 @@ import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.RegexQNamePattern; import org.alfresco.service.transaction.TransactionService; import org.alfresco.util.Pair; +import org.alfresco.util.PropertyCheck; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationEvent; import org.springframework.extensions.surf.util.AbstractLifecycleBean; +import org.alfresco.repo.dictionary.DynamicModelPolicies.OnLoadDynamicModel; /** * Bootstrap the dictionary from specified locations within the repository @@ -93,6 +97,10 @@ public class DictionaryRepositoryBootstrap extends AbstractLifecycleBean impleme /** The transaction service */ private TransactionService transactionService; + + /** The policy component */ + private PolicyComponent policyComponent; + /** * Sets the Dictionary DAO @@ -186,12 +194,27 @@ public class DictionaryRepositoryBootstrap extends AbstractLifecycleBean impleme this.repositoryMessagesLocations = repositoryLocations; } - + private ClassPolicyDelegate onLoadDynamicModelDelegate; + /** * Initialise - after bootstrap of schema and tenant admin service */ public void init() { + PropertyCheck.mandatory(this, "dictionaryDAO", dictionaryDAO); + PropertyCheck.mandatory(this, "contentService", contentService); + PropertyCheck.mandatory(this, "nodeService", nodeService); + PropertyCheck.mandatory(this, "tenantAdminService", tenantAdminService); + PropertyCheck.mandatory(this, "namespaceService", namespaceService); + PropertyCheck.mandatory(this, "messageService", messageService); + PropertyCheck.mandatory(this, "transactionService", transactionService); + PropertyCheck.mandatory(this, "policyComponent", policyComponent); + + if(onLoadDynamicModelDelegate == null) + { + onLoadDynamicModelDelegate = policyComponent.registerClassPolicy(DynamicModelPolicies.OnLoadDynamicModel.class); + } + transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback() { public Object execute() throws Exception @@ -215,6 +238,10 @@ public class DictionaryRepositoryBootstrap extends AbstractLifecycleBean impleme @Override public void onDictionaryInit() { + if(onLoadDynamicModelDelegate == null) + { + onLoadDynamicModelDelegate = policyComponent.registerClassPolicy(DynamicModelPolicies.OnLoadDynamicModel.class); + } RetryingTransactionCallback initCallback = new RetryingTransactionCallback() { @Override @@ -252,7 +279,8 @@ public class DictionaryRepositoryBootstrap extends AbstractLifecycleBean impleme if (this.repositoryModelsLocations != null) { - Map> modelMap = new HashMap>(); + // URI to model map + Map modelMap = new HashMap(); if (logger.isTraceEnabled()) { @@ -300,7 +328,7 @@ public class DictionaryRepositoryBootstrap extends AbstractLifecycleBean impleme for (M2Namespace namespace : model.getNamespaces()) { - modelMap.put(namespace.getUri(), new Pair(repositoryLocation, model)); + modelMap.put(namespace.getUri(), new DynamicModelInfo(repositoryLocation, model, dictionaryModel)); } } } @@ -326,12 +354,12 @@ public class DictionaryRepositoryBootstrap extends AbstractLifecycleBean impleme } // Load the models ensuring that they are loaded in the correct order - for (Map.Entry> entry : modelMap.entrySet()) + for (Map.Entry entry : modelMap.entrySet()) { - RepositoryLocation importedLocation = entry.getValue().getFirst(); - M2Model importedModel = entry.getValue().getSecond(); - + RepositoryLocation importedLocation = entry.getValue().location; + M2Model importedModel = entry.getValue().model; loadModel(modelMap, loadedModels, importedModel, importedLocation); + notifyDynamicModelLoaded(entry.getValue()); } } @@ -345,6 +373,17 @@ public class DictionaryRepositoryBootstrap extends AbstractLifecycleBean impleme } } + public void notifyDynamicModelLoaded(DynamicModelInfo entry) + { + if(onLoadDynamicModelDelegate == null) + { + onLoadDynamicModelDelegate = policyComponent.registerClassPolicy(DynamicModelPolicies.OnLoadDynamicModel.class); + } + + DynamicModelPolicies.OnLoadDynamicModel policy = onLoadDynamicModelDelegate.get(ContentModel.TYPE_CONTENT); + policy.onLoadDynamicModel(entry.model, entry.nodeRef); + } + /* * (non-Javadoc) * @see org.alfresco.repo.dictionary.DictionaryListener#afterInit() @@ -490,6 +529,21 @@ public class DictionaryRepositoryBootstrap extends AbstractLifecycleBean impleme return nodeRefs; } + private class DynamicModelInfo + { + RepositoryLocation location; + M2Model model; + NodeRef nodeRef; + + + DynamicModelInfo(RepositoryLocation location, M2Model model, NodeRef nodeRef) + { + this.location = location; + this.model = model; + this.nodeRef = nodeRef; + } + } + /** * Loads a model (and its dependents) if it does not exist in the list of loaded models. * @@ -497,18 +551,18 @@ public class DictionaryRepositoryBootstrap extends AbstractLifecycleBean impleme * @param loadedModels the list of models already loaded * @param model the model to try and load */ - private void loadModel(Map> modelMap, List loadedModels, M2Model model, RepositoryLocation modelLocation) + private void loadModel(Map modelMap, List loadedModels, M2Model model, RepositoryLocation modelLocation) { String modelName = model.getName(); if (loadedModels.contains(modelName) == false) { for (M2Namespace importNamespace : model.getImports()) { - Pair entry = modelMap.get(importNamespace.getUri()); + DynamicModelInfo entry = modelMap.get(importNamespace.getUri()); if (entry != null) { - RepositoryLocation importedLocation = entry.getFirst(); - M2Model importedModel = entry.getSecond(); + RepositoryLocation importedLocation = entry.location; + M2Model importedModel = entry.model; // Ensure that the imported model is loaded first loadModel(modelMap, loadedModels, importedModel, importedLocation); @@ -688,4 +742,13 @@ public class DictionaryRepositoryBootstrap extends AbstractLifecycleBean impleme } return parentNodeRef; } + + + public PolicyComponent getPolicyComponent() { + return policyComponent; + } + + public void setPolicyComponent(PolicyComponent policyComponent) { + this.policyComponent = policyComponent; + } } diff --git a/source/java/org/alfresco/repo/dictionary/DynamicModelPolicies.java b/source/java/org/alfresco/repo/dictionary/DynamicModelPolicies.java new file mode 100644 index 0000000000..445c3bb220 --- /dev/null +++ b/source/java/org/alfresco/repo/dictionary/DynamicModelPolicies.java @@ -0,0 +1,25 @@ +package org.alfresco.repo.dictionary; + +import org.alfresco.repo.policy.ClassPolicy; +import org.alfresco.service.cmr.repository.NodeRef; + +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; + +public class DynamicModelPolicies +{ + + public interface OnLoadDynamicModel extends ClassPolicy + { + public static final QName QNAME = QName.createQName(NamespaceService.ALFRESCO_URI, "onLoadDynamicModel"); + + /** + * Called after a new dynamic model has been loaded. + * + * @param model the model loaded + * @param nodeRef the node ref of the model + */ + public void onLoadDynamicModel(M2Model model, NodeRef nodeRef); + } + +}