Commit 108c65c7 authored by Arnaud Fontaine's avatar Arnaud Fontaine

Fix missing condition checks for ZODB and filesystem Constraints by

modifying checkConsistency() to always check the condition and then
calling _checkConsistency() which is overriden in the child class



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40950 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7d6e9374
...@@ -58,12 +58,9 @@ class AccountTypeConstraint(Constraint): ...@@ -58,12 +58,9 @@ class AccountTypeConstraint(Constraint):
' of ${category}, this should have account_type' ' of ${category}, this should have account_type'
' in ${account_type_list}') ' in ${account_type_list}')
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
"""Implement here the consistency checker """Implement here the consistency checker
""" """
if not self._checkConstraintCondition(obj):
return []
errors = [] errors = []
if getattr(obj, 'getAccountType', _MARKER) is _MARKER: if getattr(obj, 'getAccountType', _MARKER) is _MARKER:
errors.append(self._generateError( errors.append(self._generateError(
......
...@@ -41,12 +41,9 @@ class AccountingTransactionBalance(Constraint): ...@@ -41,12 +41,9 @@ class AccountingTransactionBalance(Constraint):
message_transaction_not_balanced_for_destination = translateString( message_transaction_not_balanced_for_destination = translateString(
'Transaction is not balanced for ${section_title}') 'Transaction is not balanced for ${section_title}')
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
"""Implement here the consistency checker """Implement here the consistency checker
""" """
if not self._checkConstraintCondition(obj):
return []
error_list = [] error_list = []
source_sum = dict() source_sum = dict()
destination_sum = dict() destination_sum = dict()
......
...@@ -33,13 +33,10 @@ class BudgetConsumptionFeasability(Constraint): ...@@ -33,13 +33,10 @@ class BudgetConsumptionFeasability(Constraint):
Check if there is enough budget to consumed. Check if there is enough budget to consumed.
""" """
def checkConsistency(self, object, fixit=0): def _checkConsistency(self, object, fixit=0):
""" """
Check if there is enough budget to consumed. Check if there is enough budget to consumed.
""" """
if not self._checkConstraintCondition(object):
return []
errors = [] errors = []
new_category_list = [] new_category_list = []
......
...@@ -54,13 +54,10 @@ class DocumentReferenceConstraint(Constraint): ...@@ -54,13 +54,10 @@ class DocumentReferenceConstraint(Constraint):
'Multiple (${document_count}) documents ${document_reference} - ' 'Multiple (${document_count}) documents ${document_reference} - '
'${document_language} - ${document_version} already exists') '${document_language} - ${document_version} already exists')
def checkConsistency(self, document, fixit=0): def _checkConsistency(self, document, fixit=0):
""" """
Implement here the consistency checker Implement here the consistency checker
""" """
if not self._checkConstraintCondition(document):
return []
# XXX we probably could check reference syntax here, based on regexp in # XXX we probably could check reference syntax here, based on regexp in
# preferences? # preferences?
error_list = [] error_list = []
......
...@@ -54,12 +54,9 @@ class ResourceMeasuresConsistency(Constraint): ...@@ -54,12 +54,9 @@ class ResourceMeasuresConsistency(Constraint):
"Implicit measure for the management unit can't be created" \ "Implicit measure for the management unit can't be created" \
" because 'metric_type/${metric_type}' category doesn't exist." " because 'metric_type/${metric_type}' category doesn't exist."
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
"""Implement here the consistency checker """Implement here the consistency checker
""" """
if not self._checkConstraintCondition(obj):
return []
error_list = [] error_list = []
portal = obj.getPortalObject() portal = obj.getPortalObject()
......
...@@ -41,13 +41,10 @@ class TradeModelLineCellConsistency(Constraint): ...@@ -41,13 +41,10 @@ class TradeModelLineCellConsistency(Constraint):
message_cell_inexistance = translateString( message_cell_inexistance = translateString(
'Missing cells on line "${line}"') 'Missing cells on line "${line}"')
def checkConsistency(self, document, fixit=0): def _checkConsistency(self, document, fixit=0):
""" """
Implement here the consistency checker Implement here the consistency checker
""" """
if not self._checkConstraintCondition(document):
return []
error_list = [] error_list = []
base_id = self.constraint_definition['base_id'] base_id = self.constraint_definition['base_id']
for cell_coordinates in document.getCellKeyList(base_id=base_id): for cell_coordinates in document.getCellKeyList(base_id=base_id):
......
...@@ -34,14 +34,11 @@ class TransactionQuantityValueFeasability(Constraint): ...@@ -34,14 +34,11 @@ class TransactionQuantityValueFeasability(Constraint):
for the source and the destination for the source and the destination
""" """
def checkConsistency(self, object, fixit=0): def _checkConsistency(self, object, fixit=0):
""" """
Check if the quantity of the transaction is possible Check if the quantity of the transaction is possible
for the source and the destination for the source and the destination
""" """
if not self._checkConstraintCondition(object):
return []
errors = [] errors = []
source_cell = object.getSourceValue() source_cell = object.getSourceValue()
destination_cell = object.getDestinationValue() destination_cell = object.getDestinationValue()
......
...@@ -33,14 +33,11 @@ class TransactionQuantityValueValidity(Constraint): ...@@ -33,14 +33,11 @@ class TransactionQuantityValueValidity(Constraint):
Explain here what this constraint checker does Explain here what this constraint checker does
""" """
def checkConsistency(self, object, fixit=0): def _checkConsistency(self, object, fixit=0):
""" """
Check if the quantity of the transaction is greater than the Check if the quantity of the transaction is greater than the
balance of the source. balance of the source.
""" """
if not self._checkConstraintCondition(object):
return []
errors = [] errors = []
source_cell = object.getSourceValue() source_cell = object.getSourceValue()
......
...@@ -46,13 +46,10 @@ class AccountingTransactionBalanceConstraint(ConstraintMixin): ...@@ -46,13 +46,10 @@ class AccountingTransactionBalanceConstraint(ConstraintMixin):
PropertySheet.Reference, PropertySheet.Reference,
PropertySheet.AccountingTransactionBalanceConstraint) PropertySheet.AccountingTransactionBalanceConstraint)
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
""" """
Check the object's consistency Check the object's consistency
""" """
if not self.test(obj):
return []
error_list = [] error_list = []
source_sum = dict() source_sum = dict()
destination_sum = dict() destination_sum = dict()
......
...@@ -48,13 +48,10 @@ class ResourceMeasuresConsistencyConstraint(ConstraintMixin): ...@@ -48,13 +48,10 @@ class ResourceMeasuresConsistencyConstraint(ConstraintMixin):
PropertySheet.Reference, PropertySheet.Reference,
PropertySheet.ResourceMeasuresConsistencyConstraint) PropertySheet.ResourceMeasuresConsistencyConstraint)
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
""" """
Check the object's consistency Check the object's consistency
""" """
if not self.test(obj):
return []
error_list = [] error_list = []
portal = obj.getPortalObject() portal = obj.getPortalObject()
......
...@@ -47,13 +47,10 @@ class TradeModelLineCellConsistencyConstraint(ConstraintMixin): ...@@ -47,13 +47,10 @@ class TradeModelLineCellConsistencyConstraint(ConstraintMixin):
PropertySheet.Reference, PropertySheet.Reference,
PropertySheet.TradeModelLineCellConsistencyConstraint) PropertySheet.TradeModelLineCellConsistencyConstraint)
def checkConsistency(self, document, fixit=0): def _checkConsistency(self, document, fixit=0):
""" """
Check the object's consistency Check the object's consistency
""" """
if not self.test(document):
return []
base_id = self.getBaseId() base_id = self.getBaseId()
for cell_coordinates in document.getCellKeyList(base_id=base_id): for cell_coordinates in document.getCellKeyList(base_id=base_id):
if document.getCell(base_id=base_id, *cell_coordinates) is None: if document.getCell(base_id=base_id, *cell_coordinates) is None:
......
...@@ -45,14 +45,11 @@ class TransactionQuantityValueFeasabilityConstraint(ConstraintMixin): ...@@ -45,14 +45,11 @@ class TransactionQuantityValueFeasabilityConstraint(ConstraintMixin):
PropertySheet.Predicate, PropertySheet.Predicate,
PropertySheet.Reference) PropertySheet.Reference)
def checkConsistency(self, object, fixit=0): def _checkConsistency(self, object, fixit=0):
""" """
Check if the quantity of the transaction is possible Check if the quantity of the transaction is possible
for the source and the destination for the source and the destination
""" """
if not self.test(object):
return []
errors = [] errors = []
source_cell = object.getSourceValue() source_cell = object.getSourceValue()
destination_cell = object.getDestinationValue() destination_cell = object.getDestinationValue()
......
...@@ -42,14 +42,11 @@ class TransactionQuantityValueValidityConstraint(ConstraintMixin): ...@@ -42,14 +42,11 @@ class TransactionQuantityValueValidityConstraint(ConstraintMixin):
PropertySheet.Predicate, PropertySheet.Predicate,
PropertySheet.Reference) PropertySheet.Reference)
def checkConsistency(self, object, fixit=0): def _checkConsistency(self, object, fixit=0):
""" """
Check if the quantity of the transaction is greater than the Check if the quantity of the transaction is greater than the
balance of the source. balance of the source.
""" """
if not self.test(object):
return []
errors = [] errors = []
source_cell = object.getSourceValue() source_cell = object.getSourceValue()
......
...@@ -47,14 +47,12 @@ class AttributeBlacklisted(PropertyExistence): ...@@ -47,14 +47,12 @@ class AttributeBlacklisted(PropertyExistence):
message_invalid_attribute_blacklisted = "Attribute ${attribute_name}: "\ message_invalid_attribute_blacklisted = "Attribute ${attribute_name}: "\
"value is blacklisted" "value is blacklisted"
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
"""Check the object's consistency. """Check the object's consistency.
We will make sure that each non None constraint_definition is We will make sure that each non None constraint_definition is
satisfied satisfied
""" """
if not self._checkConstraintCondition(obj): errors = PropertyExistence._checkConsistency(self, obj, fixit=fixit)
return []
errors = PropertyExistence.checkConsistency(self, obj, fixit=fixit)
for attribute_name, expression_blacklisted_list in self.constraint_definition.items(): for attribute_name, expression_blacklisted_list in self.constraint_definition.items():
message_id = None message_id = None
mapping = dict(attribute_name=attribute_name) mapping = dict(attribute_name=attribute_name)
......
...@@ -50,14 +50,12 @@ class AttributeEquality(PropertyExistence): ...@@ -50,14 +50,12 @@ class AttributeEquality(PropertyExistence):
message_invalid_attribute_value_fixed = "Attribute ${attribute_name} "\ message_invalid_attribute_value_fixed = "Attribute ${attribute_name} "\
"value is ${current_value} but should be ${expected_value} (Fixed)" "value is ${current_value} but should be ${expected_value} (Fixed)"
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
"""Check the object's consistency. """Check the object's consistency.
We will make sure that each non None constraint_definition is We will make sure that each non None constraint_definition is
satisfied (equality) satisfied (equality)
""" """
if not self._checkConstraintCondition(obj): errors = PropertyExistence._checkConsistency(self, obj, fixit=fixit)
return []
errors = PropertyExistence.checkConsistency(self, obj, fixit=fixit)
for attribute_name, expected_value in self.constraint_definition.items(): for attribute_name, expected_value in self.constraint_definition.items():
message_id = None message_id = None
mapping = dict() mapping = dict()
......
...@@ -51,15 +51,13 @@ class AttributeUnicity(PropertyExistence): ...@@ -51,15 +51,13 @@ class AttributeUnicity(PropertyExistence):
message_invalid_attribute_unicity = "Attribute ${attribute_name} "\ message_invalid_attribute_unicity = "Attribute ${attribute_name} "\
"value is ${value} but should be unique" "value is ${value} but should be unique"
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
"""Check the object's consistency. """Check the object's consistency.
We will make sure that each non None constraint_definition is We will make sure that each non None constraint_definition is
satisfied (unicity) satisfied (unicity)
This Constraint use portal_catalog This Constraint use portal_catalog
""" """
if not self._checkConstraintCondition(obj): errors = PropertyExistence._checkConsistency(self, obj, fixit=fixit)
return []
errors = PropertyExistence.checkConsistency(self, obj, fixit=fixit)
for attribute_name, expression_criterion_dict in self.constraint_definition.items(): for attribute_name, expression_criterion_dict in self.constraint_definition.items():
message_id = None message_id = None
mapping = dict(attribute_name=attribute_name) mapping = dict(attribute_name=attribute_name)
......
...@@ -52,11 +52,9 @@ class CategoryAcquiredMembershipState(Constraint): ...@@ -52,11 +52,9 @@ class CategoryAcquiredMembershipState(Constraint):
"${workflow_variable} for object ${membership_url} is ${current_state} " \ "${workflow_variable} for object ${membership_url} is ${current_state} " \
"which is not in ${valid_state_list}" "which is not in ${valid_state_list}"
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
"""Check the object's consistency. """Check the object's consistency.
""" """
if not self._checkConstraintCondition(obj):
return []
error_list = [] error_list = []
# Retrieve values inside de PropertySheet (_constraints) # Retrieve values inside de PropertySheet (_constraints)
base_category = self.constraint_definition['base_category'] base_category = self.constraint_definition['base_category']
......
...@@ -55,11 +55,9 @@ class CategoryExistence(Constraint): ...@@ -55,11 +55,9 @@ class CategoryExistence(Constraint):
return len(obj.getCategoryMembershipList(base_category, return len(obj.getCategoryMembershipList(base_category,
portal_type=portal_type)) portal_type=portal_type))
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
"""Check the object's consistency. """Check the object's consistency.
""" """
if not self._checkConstraintCondition(obj):
return []
error_list = [] error_list = []
portal_type = self.constraint_definition.get('portal_type', ()) portal_type = self.constraint_definition.get('portal_type', ())
# For each attribute name, we check if defined # For each attribute name, we check if defined
......
...@@ -73,14 +73,12 @@ class CategoryMembershipArity(Constraint): ...@@ -73,14 +73,12 @@ class CategoryMembershipArity(Constraint):
return len(obj.getCategoryMembershipList(base_category, return len(obj.getCategoryMembershipList(base_category,
portal_type=portal_type)) portal_type=portal_type))
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
"""Check the object's consistency. """Check the object's consistency.
We are looking the definition of the constraing where We are looking the definition of the constraing where
are defined the minimum and the maximum arity, and the are defined the minimum and the maximum arity, and the
list of objects we wants to check the arity. list of objects we wants to check the arity.
""" """
if not self._checkConstraintCondition(obj):
return []
error_list = [] error_list = []
# Retrieve configuration values from PropertySheet (_constraints) # Retrieve configuration values from PropertySheet (_constraints)
base_category = self.constraint_definition['base_category'] base_category = self.constraint_definition['base_category']
......
...@@ -51,11 +51,9 @@ class CategoryMembershipState(Constraint): ...@@ -51,11 +51,9 @@ class CategoryMembershipState(Constraint):
"${workflow_variable} for object ${membership_url} is ${current_state} " \ "${workflow_variable} for object ${membership_url} is ${current_state} " \
"which is not in ${valid_state_list}" "which is not in ${valid_state_list}"
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
"""Check the object's consistency. """Check the object's consistency.
""" """
if not self._checkConstraintCondition(obj):
return []
error_list = [] error_list = []
# Retrieve values inside de PropertySheet (_constraints) # Retrieve values inside de PropertySheet (_constraints)
base_category = self.constraint_definition['base_category'] base_category = self.constraint_definition['base_category']
......
...@@ -51,11 +51,9 @@ class CategoryRelatedMembershipState(CategoryMembershipState): ...@@ -51,11 +51,9 @@ class CategoryRelatedMembershipState(CategoryMembershipState):
}, },
""" """
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
"""Check the object's consistency. """Check the object's consistency.
""" """
if not self._checkConstraintCondition(obj):
return []
error_list = [] error_list = []
# Retrieve values inside de PropertySheet (_constraints) # Retrieve values inside de PropertySheet (_constraints)
base_category = self.constraint_definition['base_category'] base_category = self.constraint_definition['base_category']
......
...@@ -103,6 +103,16 @@ class Constraint: ...@@ -103,6 +103,16 @@ class Constraint:
return 1 # no condition or a True condition was defined return 1 # no condition or a True condition was defined
def checkConsistency(self, obj, fixit=0, **kw): def checkConsistency(self, obj, fixit=0, **kw):
"""
Check the object's consistency. Note that _checkConsistency()
should be overriden in the Constraints rather than this one.
"""
if not self._checkConstraintCondition(obj):
return []
return self._checkConsistency(obj, fixit, **kw)
def _checkConsistency(self, obj, fixit=0, **kw):
""" """
Default method is to return no error. Default method is to return no error.
""" """
......
...@@ -48,12 +48,11 @@ class ContentExistence(Constraint): ...@@ -48,12 +48,11 @@ class ContentExistence(Constraint):
message_no_subobject_portal_type = "The document does not contain any"\ message_no_subobject_portal_type = "The document does not contain any"\
" subobject of portal portal type ${portal_type}" " subobject of portal portal type ${portal_type}"
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
"""Checks that object contains a subobject. """Checks that object contains a subobject.
""" """
from Products.ERP5Type.Message import Message from Products.ERP5Type.Message import Message
error_list = [] error_list = []
if self._checkConstraintCondition(obj):
# Retrieve configuration values from PropertySheet (_constraints) # Retrieve configuration values from PropertySheet (_constraints)
portal_type = self.constraint_definition.get('portal_type', ()) portal_type = self.constraint_definition.get('portal_type', ())
if not len(obj.contentValues(portal_type=portal_type)): if not len(obj.contentValues(portal_type=portal_type)):
......
...@@ -60,11 +60,9 @@ class PortalTypeClass(Constraint): ...@@ -60,11 +60,9 @@ class PortalTypeClass(Constraint):
" definition. Portal Type class is ${portal_type_class},"\ " definition. Portal Type class is ${portal_type_class},"\
" document class is ${document_class}" " document class is ${document_class}"
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
"""Check the object's consistency. """Check the object's consistency.
""" """
if not self._checkConstraintCondition(obj):
return []
error_list = [] error_list = []
types_tool = getToolByName(obj, 'portal_types') types_tool = getToolByName(obj, 'portal_types')
type_info = types_tool._getOb(obj.getPortalType(), None) type_info = types_tool._getOb(obj.getPortalType(), None)
......
...@@ -51,11 +51,9 @@ class PropertyExistence(Constraint): ...@@ -51,11 +51,9 @@ class PropertyExistence(Constraint):
message_property_not_set = "Property existence error for property "\ message_property_not_set = "Property existence error for property "\
"${property_id}, this property is not defined" "${property_id}, this property is not defined"
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
"""Check the object's consistency. """Check the object's consistency.
""" """
if not self._checkConstraintCondition(obj):
return []
error_list = [] error_list = []
# For each attribute name, we check if defined # For each attribute name, we check if defined
for property_id in self.constraint_definition.keys(): for property_id in self.constraint_definition.keys():
......
...@@ -75,12 +75,9 @@ class PropertyTypeValidity(Constraint): ...@@ -75,12 +75,9 @@ class PropertyTypeValidity(Constraint):
" should be of type ${expected_type} but is of type ${actual_type} (Fixed)" " should be of type ${expected_type} but is of type ${actual_type} (Fixed)"
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
"""Check the object's consistency. """Check the object's consistency.
""" """
if not self._checkConstraintCondition(obj):
return []
error_list = [] error_list = []
# For each attribute name, we check type # For each attribute name, we check type
for prop in obj.propertyMap(): for prop in obj.propertyMap():
......
...@@ -47,11 +47,11 @@ class StringAttributeMatch(PropertyExistence): ...@@ -47,11 +47,11 @@ class StringAttributeMatch(PropertyExistence):
message_attribute_does_not_match = "Attribute ${attribute_name} is "\ message_attribute_does_not_match = "Attribute ${attribute_name} is "\
"${attribute_value} and does not match ${regular_expression}." "${attribute_value} and does not match ${regular_expression}."
def checkConsistency(self, object, fixit=0): def _checkConsistency(self, object, fixit=0):
"""Check the object's consistency. """Check the object's consistency.
Check that each attribute matches the regular expression. Check that each attribute matches the regular expression.
""" """
error_list = PropertyExistence.checkConsistency( error_list = PropertyExistence._checkConsistency(
self, object, fixit=fixit) self, object, fixit=fixit)
if not error_list: if not error_list:
for attribute_name, regular_expression in\ for attribute_name, regular_expression in\
......
...@@ -63,13 +63,11 @@ class TALESConstraint(Constraint): ...@@ -63,13 +63,11 @@ class TALESConstraint(Constraint):
message_expression_error = \ message_expression_error = \
"Error while evaluating expression: ${error_text}" "Error while evaluating expression: ${error_text}"
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
"""Check the object's consistency. """Check the object's consistency.
""" """
# import this later to prevent circular import # import this later to prevent circular import
from Products.ERP5Type.Utils import createExpressionContext from Products.ERP5Type.Utils import createExpressionContext
if not self._checkConstraintCondition(obj):
return []
error_list = [] error_list = []
expression_text = self.constraint_definition['expression'] expression_text = self.constraint_definition['expression']
expression = Expression(expression_text) expression = Expression(expression_text)
......
...@@ -66,13 +66,10 @@ class AttributeEqualityConstraint(ConstraintMixin): ...@@ -66,13 +66,10 @@ class AttributeEqualityConstraint(ConstraintMixin):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'checkConsistency') 'checkConsistency')
def checkConsistency(self, obj, fixit=False): def _checkConsistency(self, obj, fixit=False):
""" """
Check the object's consistency. Check the object's consistency.
""" """
if not self.test(obj):
return []
attribute_name = self.getConstraintAttributeName() attribute_name = self.getConstraintAttributeName()
# If property does not exist, error will be raised by # If property does not exist, error will be raised by
......
...@@ -59,13 +59,10 @@ class CategoryExistenceConstraint(ConstraintMixin): ...@@ -59,13 +59,10 @@ class CategoryExistenceConstraint(ConstraintMixin):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'checkConsistency') 'checkConsistency')
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
""" """
Check the object's consistency. Check the object's consistency.
""" """
if not self.test(obj):
return []
error_list = [] error_list = []
portal_type_list = self.getConstraintPortalTypeList() portal_type_list = self.getConstraintPortalTypeList()
# For each attribute name, we check if defined # For each attribute name, we check if defined
......
...@@ -65,15 +65,12 @@ class CategoryMembershipArityConstraint(ConstraintMixin): ...@@ -65,15 +65,12 @@ class CategoryMembershipArityConstraint(ConstraintMixin):
return len(obj.getCategoryMembershipList(base_category_list, return len(obj.getCategoryMembershipList(base_category_list,
portal_type=portal_type_list)) portal_type=portal_type_list))
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
""" """
Check the object's consistency. We are looking at the definition Check the object's consistency. We are looking at the definition
of the constraint where the minimum and the maximum arities are of the constraint where the minimum and the maximum arities are
defined, and the list of objects we wants to check the arity for defined, and the list of objects we wants to check the arity for
""" """
if not self.test(obj):
return []
# Retrieve configuration values from PropertySheet # Retrieve configuration values from PropertySheet
base_category_list = self.getConstraintBaseCategoryList() base_category_list = self.getConstraintBaseCategoryList()
min_arity = self.getMinArity() min_arity = self.getMinArity()
......
...@@ -62,14 +62,11 @@ class ContentExistenceConstraint(ConstraintMixin): ...@@ -62,14 +62,11 @@ class ContentExistenceConstraint(ConstraintMixin):
PropertySheet.Reference, PropertySheet.Reference,
PropertySheet.ContentExistenceConstraint) PropertySheet.ContentExistenceConstraint)
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
""" """
Checks that object contains at least one subobject and, if a list Checks that object contains at least one subobject and, if a list
of Portal Type has been given, check their Portal Types of Portal Type has been given, check their Portal Types
""" """
if not self.test(obj):
return []
portal_type = self._getExpressionValue(obj, portal_type = self._getExpressionValue(obj,
self.getConstraintPortalType()) self.getConstraintPortalType())
......
...@@ -61,13 +61,10 @@ class PropertyExistenceConstraint(ConstraintMixin): ...@@ -61,13 +61,10 @@ class PropertyExistenceConstraint(ConstraintMixin):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'checkConsistency') 'checkConsistency')
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
""" """
Check the object's consistency. Check the object's consistency.
""" """
if not self.test(obj):
return []
error_list = [] error_list = []
# For each attribute name, we check if defined # For each attribute name, we check if defined
for property_id in self.getConstraintPropertyList(): for property_id in self.getConstraintPropertyList():
......
...@@ -68,13 +68,10 @@ class PropertyTypeValidityConstraint(ConstraintMixin): ...@@ -68,13 +68,10 @@ class PropertyTypeValidityConstraint(ConstraintMixin):
# Properties of type eg. "object" can hold anything # Properties of type eg. "object" can hold anything
_permissive_type_list = ('object', 'data') _permissive_type_list = ('object', 'data')
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
""" """
Check the object's consistency. Check the object's consistency.
""" """
if not self.test(obj):
return []
error_list = [] error_list = []
# For each attribute name, we check type # For each attribute name, we check type
for prop in obj.propertyMap(): for prop in obj.propertyMap():
......
...@@ -66,14 +66,11 @@ class TALESConstraint(ConstraintMixin): ...@@ -66,14 +66,11 @@ class TALESConstraint(ConstraintMixin):
PropertySheet.Reference, PropertySheet.Reference,
PropertySheet.TALESConstraint) PropertySheet.TALESConstraint)
def checkConsistency(self, obj, fixit=0): def _checkConsistency(self, obj, fixit=0):
""" """
Check that the Expression does not contain an error and is not Check that the Expression does not contain an error and is not
evaluated to False evaluated to False
""" """
if not self.test(obj):
return []
expression_text = self.getExpression() expression_text = self.getExpression()
try: try:
......
...@@ -76,10 +76,13 @@ class ConstraintMixin(Predicate): ...@@ -76,10 +76,13 @@ class ConstraintMixin(Predicate):
'checkConsistency') 'checkConsistency')
def checkConsistency(self, obj, fixit=0, **kw): def checkConsistency(self, obj, fixit=0, **kw):
""" """
Default method is to return no error. Check the pre-condition before checking the consistency.
_checkConsistency() must be define in the child class.
""" """
errors = [] if not self.test(obj):
return errors return []
return self._checkConsistency(obj, fixit, **kw)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'fixConsistency') 'fixConsistency')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment