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):
' of ${category}, this should have account_type'
' in ${account_type_list}')
def checkConsistency(self, obj, fixit=0):
def _checkConsistency(self, obj, fixit=0):
"""Implement here the consistency checker
"""
if not self._checkConstraintCondition(obj):
return []
errors = []
if getattr(obj, 'getAccountType', _MARKER) is _MARKER:
errors.append(self._generateError(
......
......@@ -41,12 +41,9 @@ class AccountingTransactionBalance(Constraint):
message_transaction_not_balanced_for_destination = translateString(
'Transaction is not balanced for ${section_title}')
def checkConsistency(self, obj, fixit=0):
def _checkConsistency(self, obj, fixit=0):
"""Implement here the consistency checker
"""
if not self._checkConstraintCondition(obj):
return []
error_list = []
source_sum = dict()
destination_sum = dict()
......
......@@ -33,13 +33,10 @@ class BudgetConsumptionFeasability(Constraint):
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.
"""
if not self._checkConstraintCondition(object):
return []
errors = []
new_category_list = []
......
......@@ -54,13 +54,10 @@ class DocumentReferenceConstraint(Constraint):
'Multiple (${document_count}) documents ${document_reference} - '
'${document_language} - ${document_version} already exists')
def checkConsistency(self, document, fixit=0):
def _checkConsistency(self, document, fixit=0):
"""
Implement here the consistency checker
"""
if not self._checkConstraintCondition(document):
return []
# XXX we probably could check reference syntax here, based on regexp in
# preferences?
error_list = []
......
......@@ -54,12 +54,9 @@ class ResourceMeasuresConsistency(Constraint):
"Implicit measure for the management unit can't be created" \
" 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
"""
if not self._checkConstraintCondition(obj):
return []
error_list = []
portal = obj.getPortalObject()
......
......@@ -41,13 +41,10 @@ class TradeModelLineCellConsistency(Constraint):
message_cell_inexistance = translateString(
'Missing cells on line "${line}"')
def checkConsistency(self, document, fixit=0):
def _checkConsistency(self, document, fixit=0):
"""
Implement here the consistency checker
"""
if not self._checkConstraintCondition(document):
return []
error_list = []
base_id = self.constraint_definition['base_id']
for cell_coordinates in document.getCellKeyList(base_id=base_id):
......
......@@ -34,14 +34,11 @@ class TransactionQuantityValueFeasability(Constraint):
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
for the source and the destination
"""
if not self._checkConstraintCondition(object):
return []
errors = []
source_cell = object.getSourceValue()
destination_cell = object.getDestinationValue()
......
......@@ -33,14 +33,11 @@ class TransactionQuantityValueValidity(Constraint):
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
balance of the source.
"""
if not self._checkConstraintCondition(object):
return []
errors = []
source_cell = object.getSourceValue()
......
......@@ -46,13 +46,10 @@ class AccountingTransactionBalanceConstraint(ConstraintMixin):
PropertySheet.Reference,
PropertySheet.AccountingTransactionBalanceConstraint)
def checkConsistency(self, obj, fixit=0):
def _checkConsistency(self, obj, fixit=0):
"""
Check the object's consistency
"""
if not self.test(obj):
return []
error_list = []
source_sum = dict()
destination_sum = dict()
......
......@@ -48,13 +48,10 @@ class ResourceMeasuresConsistencyConstraint(ConstraintMixin):
PropertySheet.Reference,
PropertySheet.ResourceMeasuresConsistencyConstraint)
def checkConsistency(self, obj, fixit=0):
def _checkConsistency(self, obj, fixit=0):
"""
Check the object's consistency
"""
if not self.test(obj):
return []
error_list = []
portal = obj.getPortalObject()
......
......@@ -47,13 +47,10 @@ class TradeModelLineCellConsistencyConstraint(ConstraintMixin):
PropertySheet.Reference,
PropertySheet.TradeModelLineCellConsistencyConstraint)
def checkConsistency(self, document, fixit=0):
def _checkConsistency(self, document, fixit=0):
"""
Check the object's consistency
"""
if not self.test(document):
return []
base_id = self.getBaseId()
for cell_coordinates in document.getCellKeyList(base_id=base_id):
if document.getCell(base_id=base_id, *cell_coordinates) is None:
......
......@@ -45,14 +45,11 @@ class TransactionQuantityValueFeasabilityConstraint(ConstraintMixin):
PropertySheet.Predicate,
PropertySheet.Reference)
def checkConsistency(self, object, fixit=0):
def _checkConsistency(self, object, fixit=0):
"""
Check if the quantity of the transaction is possible
for the source and the destination
"""
if not self.test(object):
return []
errors = []
source_cell = object.getSourceValue()
destination_cell = object.getDestinationValue()
......
......@@ -42,14 +42,11 @@ class TransactionQuantityValueValidityConstraint(ConstraintMixin):
PropertySheet.Predicate,
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
balance of the source.
"""
if not self.test(object):
return []
errors = []
source_cell = object.getSourceValue()
......
......@@ -47,14 +47,12 @@ class AttributeBlacklisted(PropertyExistence):
message_invalid_attribute_blacklisted = "Attribute ${attribute_name}: "\
"value is blacklisted"
def checkConsistency(self, obj, fixit=0):
def _checkConsistency(self, obj, fixit=0):
"""Check the object's consistency.
We will make sure that each non None constraint_definition is
satisfied
"""
if not self._checkConstraintCondition(obj):
return []
errors = PropertyExistence.checkConsistency(self, obj, fixit=fixit)
errors = PropertyExistence._checkConsistency(self, obj, fixit=fixit)
for attribute_name, expression_blacklisted_list in self.constraint_definition.items():
message_id = None
mapping = dict(attribute_name=attribute_name)
......
......@@ -50,14 +50,12 @@ class AttributeEquality(PropertyExistence):
message_invalid_attribute_value_fixed = "Attribute ${attribute_name} "\
"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.
We will make sure that each non None constraint_definition is
satisfied (equality)
"""
if not self._checkConstraintCondition(obj):
return []
errors = PropertyExistence.checkConsistency(self, obj, fixit=fixit)
errors = PropertyExistence._checkConsistency(self, obj, fixit=fixit)
for attribute_name, expected_value in self.constraint_definition.items():
message_id = None
mapping = dict()
......
......@@ -51,15 +51,13 @@ class AttributeUnicity(PropertyExistence):
message_invalid_attribute_unicity = "Attribute ${attribute_name} "\
"value is ${value} but should be unique"
def checkConsistency(self, obj, fixit=0):
def _checkConsistency(self, obj, fixit=0):
"""Check the object's consistency.
We will make sure that each non None constraint_definition is
satisfied (unicity)
This Constraint use portal_catalog
"""
if not self._checkConstraintCondition(obj):
return []
errors = PropertyExistence.checkConsistency(self, obj, fixit=fixit)
errors = PropertyExistence._checkConsistency(self, obj, fixit=fixit)
for attribute_name, expression_criterion_dict in self.constraint_definition.items():
message_id = None
mapping = dict(attribute_name=attribute_name)
......
......@@ -52,11 +52,9 @@ class CategoryAcquiredMembershipState(Constraint):
"${workflow_variable} for object ${membership_url} is ${current_state} " \
"which is not in ${valid_state_list}"
def checkConsistency(self, obj, fixit=0):
def _checkConsistency(self, obj, fixit=0):
"""Check the object's consistency.
"""
if not self._checkConstraintCondition(obj):
return []
error_list = []
# Retrieve values inside de PropertySheet (_constraints)
base_category = self.constraint_definition['base_category']
......
......@@ -55,11 +55,9 @@ class CategoryExistence(Constraint):
return len(obj.getCategoryMembershipList(base_category,
portal_type=portal_type))
def checkConsistency(self, obj, fixit=0):
def _checkConsistency(self, obj, fixit=0):
"""Check the object's consistency.
"""
if not self._checkConstraintCondition(obj):
return []
error_list = []
portal_type = self.constraint_definition.get('portal_type', ())
# For each attribute name, we check if defined
......
......@@ -73,14 +73,12 @@ class CategoryMembershipArity(Constraint):
return len(obj.getCategoryMembershipList(base_category,
portal_type=portal_type))
def checkConsistency(self, obj, fixit=0):
def _checkConsistency(self, obj, fixit=0):
"""Check the object's consistency.
We are looking the definition of the constraing where
are defined the minimum and the maximum arity, and the
list of objects we wants to check the arity.
"""
if not self._checkConstraintCondition(obj):
return []
error_list = []
# Retrieve configuration values from PropertySheet (_constraints)
base_category = self.constraint_definition['base_category']
......
......@@ -51,11 +51,9 @@ class CategoryMembershipState(Constraint):
"${workflow_variable} for object ${membership_url} is ${current_state} " \
"which is not in ${valid_state_list}"
def checkConsistency(self, obj, fixit=0):
def _checkConsistency(self, obj, fixit=0):
"""Check the object's consistency.
"""
if not self._checkConstraintCondition(obj):
return []
error_list = []
# Retrieve values inside de PropertySheet (_constraints)
base_category = self.constraint_definition['base_category']
......
......@@ -51,11 +51,9 @@ class CategoryRelatedMembershipState(CategoryMembershipState):
},
"""
def checkConsistency(self, obj, fixit=0):
def _checkConsistency(self, obj, fixit=0):
"""Check the object's consistency.
"""
if not self._checkConstraintCondition(obj):
return []
error_list = []
# Retrieve values inside de PropertySheet (_constraints)
base_category = self.constraint_definition['base_category']
......
......@@ -103,6 +103,16 @@ class Constraint:
return 1 # no condition or a True condition was defined
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.
"""
......
......@@ -48,27 +48,26 @@ class ContentExistence(Constraint):
message_no_subobject_portal_type = "The document does not contain any"\
" 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.
"""
from Products.ERP5Type.Message import Message
error_list = []
if self._checkConstraintCondition(obj):
# Retrieve configuration values from PropertySheet (_constraints)
portal_type = self.constraint_definition.get('portal_type', ())
if not len(obj.contentValues(portal_type=portal_type)):
# Generate error message
mapping = {}
message_id = 'message_no_subobject'
if portal_type is not ():
message_id = 'message_no_subobject_portal_type'
# XXX maybe this could be factored out
if isinstance(portal_type, basestring):
portal_type = (portal_type, )
mapping['portal_type'] = str(Message('erp5_ui', ' or ')).join(
[str(Message('erp5_ui', pt)) for pt in portal_type])
# Add error
error_list.append(self._generateError(obj,
self._getMessage(message_id), mapping))
# Retrieve configuration values from PropertySheet (_constraints)
portal_type = self.constraint_definition.get('portal_type', ())
if not len(obj.contentValues(portal_type=portal_type)):
# Generate error message
mapping = {}
message_id = 'message_no_subobject'
if portal_type is not ():
message_id = 'message_no_subobject_portal_type'
# XXX maybe this could be factored out
if isinstance(portal_type, basestring):
portal_type = (portal_type, )
mapping['portal_type'] = str(Message('erp5_ui', ' or ')).join(
[str(Message('erp5_ui', pt)) for pt in portal_type])
# Add error
error_list.append(self._generateError(obj,
self._getMessage(message_id), mapping))
return error_list
......@@ -60,11 +60,9 @@ class PortalTypeClass(Constraint):
" definition. Portal Type class is ${portal_type_class},"\
" document class is ${document_class}"
def checkConsistency(self, obj, fixit=0):
def _checkConsistency(self, obj, fixit=0):
"""Check the object's consistency.
"""
if not self._checkConstraintCondition(obj):
return []
error_list = []
types_tool = getToolByName(obj, 'portal_types')
type_info = types_tool._getOb(obj.getPortalType(), None)
......
......@@ -51,11 +51,9 @@ class PropertyExistence(Constraint):
message_property_not_set = "Property existence error for property "\
"${property_id}, this property is not defined"
def checkConsistency(self, obj, fixit=0):
def _checkConsistency(self, obj, fixit=0):
"""Check the object's consistency.
"""
if not self._checkConstraintCondition(obj):
return []
error_list = []
# For each attribute name, we check if defined
for property_id in self.constraint_definition.keys():
......
......@@ -75,12 +75,9 @@ class PropertyTypeValidity(Constraint):
" 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.
"""
if not self._checkConstraintCondition(obj):
return []
error_list = []
# For each attribute name, we check type
for prop in obj.propertyMap():
......
......@@ -47,11 +47,11 @@ class StringAttributeMatch(PropertyExistence):
message_attribute_does_not_match = "Attribute ${attribute_name} is "\
"${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 that each attribute matches the regular expression.
"""
error_list = PropertyExistence.checkConsistency(
error_list = PropertyExistence._checkConsistency(
self, object, fixit=fixit)
if not error_list:
for attribute_name, regular_expression in\
......
......@@ -63,13 +63,11 @@ class TALESConstraint(Constraint):
message_expression_error = \
"Error while evaluating expression: ${error_text}"
def checkConsistency(self, obj, fixit=0):
def _checkConsistency(self, obj, fixit=0):
"""Check the object's consistency.
"""
# import this later to prevent circular import
from Products.ERP5Type.Utils import createExpressionContext
if not self._checkConstraintCondition(obj):
return []
error_list = []
expression_text = self.constraint_definition['expression']
expression = Expression(expression_text)
......
......@@ -66,13 +66,10 @@ class AttributeEqualityConstraint(ConstraintMixin):
security.declareProtected(Permissions.AccessContentsInformation,
'checkConsistency')
def checkConsistency(self, obj, fixit=False):
def _checkConsistency(self, obj, fixit=False):
"""
Check the object's consistency.
"""
if not self.test(obj):
return []
attribute_name = self.getConstraintAttributeName()
# If property does not exist, error will be raised by
......
......@@ -59,13 +59,10 @@ class CategoryExistenceConstraint(ConstraintMixin):
security.declareProtected(Permissions.AccessContentsInformation,
'checkConsistency')
def checkConsistency(self, obj, fixit=0):
def _checkConsistency(self, obj, fixit=0):
"""
Check the object's consistency.
"""
if not self.test(obj):
return []
error_list = []
portal_type_list = self.getConstraintPortalTypeList()
# For each attribute name, we check if defined
......
......@@ -65,15 +65,12 @@ class CategoryMembershipArityConstraint(ConstraintMixin):
return len(obj.getCategoryMembershipList(base_category_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
of the constraint where the minimum and the maximum arities are
defined, and the list of objects we wants to check the arity for
"""
if not self.test(obj):
return []
# Retrieve configuration values from PropertySheet
base_category_list = self.getConstraintBaseCategoryList()
min_arity = self.getMinArity()
......
......@@ -62,14 +62,11 @@ class ContentExistenceConstraint(ConstraintMixin):
PropertySheet.Reference,
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
of Portal Type has been given, check their Portal Types
"""
if not self.test(obj):
return []
portal_type = self._getExpressionValue(obj,
self.getConstraintPortalType())
......
......@@ -61,13 +61,10 @@ class PropertyExistenceConstraint(ConstraintMixin):
security.declareProtected(Permissions.AccessContentsInformation,
'checkConsistency')
def checkConsistency(self, obj, fixit=0):
def _checkConsistency(self, obj, fixit=0):
"""
Check the object's consistency.
"""
if not self.test(obj):
return []
error_list = []
# For each attribute name, we check if defined
for property_id in self.getConstraintPropertyList():
......
......@@ -68,13 +68,10 @@ class PropertyTypeValidityConstraint(ConstraintMixin):
# Properties of type eg. "object" can hold anything
_permissive_type_list = ('object', 'data')
def checkConsistency(self, obj, fixit=0):
def _checkConsistency(self, obj, fixit=0):
"""
Check the object's consistency.
"""
if not self.test(obj):
return []
error_list = []
# For each attribute name, we check type
for prop in obj.propertyMap():
......
......@@ -66,14 +66,11 @@ class TALESConstraint(ConstraintMixin):
PropertySheet.Reference,
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
evaluated to False
"""
if not self.test(obj):
return []
expression_text = self.getExpression()
try:
......
......@@ -76,10 +76,13 @@ class ConstraintMixin(Predicate):
'checkConsistency')
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 = []
return errors
if not self.test(obj):
return []
return self._checkConsistency(obj, fixit, **kw)
security.declareProtected(Permissions.AccessContentsInformation,
'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