Merged V3.2 to HEAD

18023: RM: groundwork for custom metadata delete
    18071: MT - fix ETHREEOH-3730 (reject invitation shows "Invitation not found" instead of Yes / No options)
    18078: MT - fix ETHREEOH-3892 (it is not possible to create or manage any Tenants once the DOD5015 RM AMP is installed)
    18903: RM Caveats - fix ALF-1894 (improvement for ESC - remove hardcoded "rmc" model/namespace)
    19046: Improve dictionary debug logging (ALF-587)
    19096: Merging PATCHES/V3.2.r to V3.2
        19075: Merging DEV/BELARUS/V3.2-2010_02_24 to PATCHES/V3.2.r
            18881: ALF-587: MT Upgrades to 3.2r fail unable to find Alfresco content types
        19085: ALF-587 - test/build fix (follow on for r18881->r19075)
    19145: Dynamic Models - follow-on for ALF-587 (& ALFCOM-2977) + additional unit tests
    19176: Remove Java 6'ism
    19198: Build/test fix (follow-on to r19145 - do not validate model delete of version nodes)


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19260 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2010-03-12 17:06:36 +00:00
parent e96af8d097
commit 8f0ad2d96f
17 changed files with 1703 additions and 323 deletions

View File

@@ -46,7 +46,6 @@ import org.alfresco.service.cmr.dictionary.NamespaceDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.surf.util.ParameterCheck;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -54,7 +53,7 @@ import org.apache.commons.logging.LogFactory;
/**
* Default implementation of the Dictionary.
*
* @author David Caruana
* @author David Caruana, janv
*
*/
public class DictionaryDAOImpl implements DictionaryDAO
@@ -190,7 +189,7 @@ public class DictionaryDAOImpl implements DictionaryDAO
DictionaryRegistry dictionaryRegistry = initDictionaryRegistry(tenantDomain);
if (dictionaryRegistry == null)
{
{
// unexpected
throw new AlfrescoRuntimeException("Failed to init dictionaryRegistry " + tenantDomain);
}
@@ -298,13 +297,13 @@ public class DictionaryDAOImpl implements DictionaryDAO
// Publish new Model Definition
getCompiledModels(tenantDomain).put(modelName, compiledModel);
if (logger.isDebugEnabled())
if (logger.isTraceEnabled())
{
logger.debug("Registered model " + modelName.toPrefixString(namespaceDAO));
logger.trace("Registered model: " + modelName.toPrefixString(namespaceDAO));
for (M2Namespace namespace : model.getNamespaces())
{
logger.debug("Registered namespace '" + namespace.getUri() + "' (prefix '" + namespace.getPrefix() + "')");
logger.trace("Registered namespace: '" + namespace.getUri() + "' (prefix '" + namespace.getPrefix() + "')");
}
}
@@ -942,10 +941,37 @@ public class DictionaryDAOImpl implements DictionaryDAO
*/
public Collection<ConstraintDefinition> getConstraints(QName modelName)
{
return getConstraints(modelName, false);
}
public Collection<ConstraintDefinition> getConstraints(QName modelName, boolean referenceableDefsOnly)
{
CompiledModel model = getCompiledModel(modelName);
return model.getConstraints();
if (referenceableDefsOnly)
{
return getReferenceableConstraintDefs(model);
}
else
{
return model.getConstraints();
}
}
private Collection<ConstraintDefinition> getReferenceableConstraintDefs(CompiledModel model)
{
Collection<ConstraintDefinition> conDefs = model.getConstraints();
Collection<PropertyDefinition> propDefs = model.getProperties();
for (PropertyDefinition propDef : propDefs)
{
for (ConstraintDefinition conDef : propDef.getConstraints())
{
conDefs.remove(conDef);
}
}
return conDefs;
}
// re-entrant (eg. via reset)
private DictionaryRegistry getDictionaryRegistry(String tenantDomain)
{
@@ -974,9 +1000,9 @@ public class DictionaryDAOImpl implements DictionaryDAO
readLock.unlock();
}
if (logger.isDebugEnabled())
if (logger.isTraceEnabled())
{
logger.debug("getDictionaryRegistry: not in cache (or threadlocal) - re-init ["+Thread.currentThread().getId()+", "+AlfrescoTransactionSupport.getTransactionId()+"]"+(tenantDomain.equals(TenantService.DEFAULT_DOMAIN) ? "" : " (Tenant: "+tenantDomain+")"));
logger.trace("getDictionaryRegistry: not in cache (or threadlocal) - re-init ["+Thread.currentThread().getId()+", "+AlfrescoTransactionSupport.getTransactionId()+"]"+(tenantDomain.equals(TenantService.DEFAULT_DOMAIN) ? "" : " (Tenant: "+tenantDomain+")"));
}
// reset caches - may have been invalidated (e.g. in a cluster)
@@ -1088,13 +1114,12 @@ public class DictionaryDAOImpl implements DictionaryDAO
/**
* Return diffs between input model and model in the Dictionary.
*
* If the input model does not exist in the Dictionary or is equivalent to the one in the Dictionary
* then no diffs will be returned.
* If the input model does not exist in the Dictionary then no diffs will be returned.
*
* @param model
* @return model diffs (if any)
*/
private List<M2ModelDiff> diffModel(M2Model model)
public List<M2ModelDiff> diffModel(M2Model model)
{
// Compile model definition
CompiledModel compiledModel = model.compile(this, namespaceDAO);
@@ -1140,7 +1165,8 @@ public class DictionaryDAOImpl implements DictionaryDAO
{
Collection<TypeDefinition> previousTypes = previousVersion.getTypes();
Collection<AspectDefinition> previousAspects = previousVersion.getAspects();
Collection<ConstraintDefinition> previousConDefs = getReferenceableConstraintDefs(previousVersion);
if (model == null)
{
// delete model
@@ -1151,13 +1177,18 @@ public class DictionaryDAOImpl implements DictionaryDAO
for (AspectDefinition previousAspect : previousAspects)
{
M2ModelDiffs.add(new M2ModelDiff(previousAspect.getName(), M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_DELETED));
}
}
for (ConstraintDefinition previousConDef : previousConDefs)
{
M2ModelDiffs.add(new M2ModelDiff(previousConDef.getName(), M2ModelDiff.TYPE_CONSTRAINT, M2ModelDiff.DIFF_DELETED));
}
}
else
{
// update model
Collection<TypeDefinition> types = model.getTypes();
Collection<AspectDefinition> aspects = model.getAspects();
Collection<ConstraintDefinition> conDefs = getReferenceableConstraintDefs(model);
if (previousTypes.size() != 0)
{
@@ -1182,6 +1213,18 @@ public class DictionaryDAOImpl implements DictionaryDAO
M2ModelDiffs.add(new M2ModelDiff(aspect.getName(), M2ModelDiff.TYPE_ASPECT, M2ModelDiff.DIFF_CREATED));
}
}
if (previousConDefs.size() != 0)
{
M2ModelDiffs.addAll(M2ConstraintDefinition.diffConstraintLists(new ArrayList<ConstraintDefinition>(previousConDefs), new ArrayList<ConstraintDefinition>(conDefs)));
}
else
{
for (ConstraintDefinition conDef : conDefs)
{
M2ModelDiffs.add(new M2ModelDiff(conDef.getName(), M2ModelDiff.TYPE_CONSTRAINT, M2ModelDiff.DIFF_CREATED));
}
}
}
}
else
@@ -1211,41 +1254,6 @@ public class DictionaryDAOImpl implements DictionaryDAO
return M2ModelDiffs;
}
/**
* 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
*
* @param newOrUpdatedModel
*/
public void validateModel(M2Model newOrUpdatedModel)
{
// Check that all the passed values are not null
ParameterCheck.mandatory("newOrUpdatedModel", newOrUpdatedModel);
List<M2ModelDiff> modelDiffs = diffModel(newOrUpdatedModel);
for (M2ModelDiff modelDiff : modelDiffs)
{
if (modelDiff.getDiffType().equals(M2ModelDiff.DIFF_DELETED))
{
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() + "'");
}
}
}
/* package */ class DictionaryRegistry
{
private Map<String, List<CompiledModel>> uriToModels = new HashMap<String, List<CompiledModel>>(0);