AR-166: Property constraints included in integrity checks

AR-194: Regular expression constraint applied to cm:name property to flag illegal characters
Other minor fixes
 - Dictionary bootstrap bean depends on I18N bean being constructed
 - RegexConstraint check can be inverted
 - Some I18N message fixes


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2549 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2006-03-15 17:49:09 +00:00
parent af18443867
commit 177e90545f
10 changed files with 171 additions and 38 deletions

View File

@@ -23,10 +23,12 @@ import java.util.Map;
import java.util.Set;
import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.Constraint;
import org.alfresco.service.cmr.dictionary.ConstraintDefinition;
import org.alfresco.service.cmr.dictionary.ConstraintException;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
@@ -52,11 +54,8 @@ public class PropertiesIntegrityEvent extends AbstractIntegrityEvent
public void checkIntegrity(List<IntegrityRecord> eventResults)
{
try
{
checkAllProperties(getNodeRef(), eventResults);
}
catch (InvalidNodeRefException e)
NodeRef nodeRef = getNodeRef();
if (!nodeService.exists(nodeRef))
{
// node has gone
if (logger.isDebugEnabled())
@@ -66,6 +65,10 @@ public class PropertiesIntegrityEvent extends AbstractIntegrityEvent
eventResults.clear();
return;
}
else
{
checkAllProperties(getNodeRef(), eventResults);
}
}
/**
@@ -123,7 +126,6 @@ public class PropertiesIntegrityEvent extends AbstractIntegrityEvent
for (PropertyDefinition propertyDef : propertyDefs)
{
QName propertyQName = propertyDef.getName();
Serializable propertyValue = nodeProperties.get(propertyQName);
// check that mandatory properties are set
if (propertyDef.isMandatory() && !nodeProperties.containsKey(propertyQName))
{
@@ -136,7 +138,30 @@ public class PropertiesIntegrityEvent extends AbstractIntegrityEvent
// next one
continue;
}
// TODO: Incorporate value constraint checks - JIRA AR166
Serializable propertyValue = nodeProperties.get(propertyQName);
// check constraints
List<ConstraintDefinition> constraintDefs = propertyDef.getConstraints();
for (ConstraintDefinition constraintDef : constraintDefs)
{
// get the constraint implementation
Constraint constraint = constraintDef.getConstraint();
try
{
constraint.evaluate(propertyValue);
}
catch (ConstraintException e)
{
IntegrityRecord result = new IntegrityRecord(
"Invalid property value: \n" +
" Node: " + nodeRef + "\n" +
" Type: " + typeQName + "\n" +
" Property: " + propertyQName + "\n" +
" Constraint: " + e.getMessage());
eventResults.add(result);
// next one
continue;
}
}
}
}
}