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
This commit is contained in:
Mark Rogers
2014-07-23 14:42:53 +00:00
parent 025ea2b305
commit f989d6fa2d
4 changed files with 111 additions and 13 deletions

View File

@@ -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

View File

@@ -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<OnLoadDynamicModel> 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<Object>()
{
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<Void> initCallback = new RetryingTransactionCallback<Void>()
{
@Override
@@ -252,7 +279,8 @@ public class DictionaryRepositoryBootstrap extends AbstractLifecycleBean impleme
if (this.repositoryModelsLocations != null)
{
Map<String, Pair<RepositoryLocation, M2Model>> modelMap = new HashMap<String, Pair<RepositoryLocation, M2Model>>();
// URI to model map
Map<String, DynamicModelInfo> modelMap = new HashMap<String, DynamicModelInfo>();
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, M2Model>(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<String, Pair<RepositoryLocation, M2Model>> entry : modelMap.entrySet())
for (Map.Entry<String, DynamicModelInfo> 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<String, Pair<RepositoryLocation, M2Model>> modelMap, List<String> loadedModels, M2Model model, RepositoryLocation modelLocation)
private void loadModel(Map<String, DynamicModelInfo> modelMap, List<String> loadedModels, M2Model model, RepositoryLocation modelLocation)
{
String modelName = model.getName();
if (loadedModels.contains(modelName) == false)
{
for (M2Namespace importNamespace : model.getImports())
{
Pair<RepositoryLocation, M2Model> 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;
}
}

View File

@@ -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);
}
}