Commit 25ffef18 authored by Sebastien Robin's avatar Sebastien Robin

instead of propagating list of properties, propagate list of testers

This improve commit c64d4287 and it allows to keep current
configuration of rules. Now we use tester method getUpdatablePropertyDict
in order to know which properties we propagate in expand
parent 54c842c9
......@@ -93,7 +93,7 @@ class QuantitySplitSolver(SolverMixin, ConfigurableMixin, XMLObject):
# Copy at same level
rule = applied_rule.getSpecialiseValue()
kw = _getPropertyDict(simulation_movement,
property_id_set=rule.getUpdatablePropertyIdSet())
updating_tester_list=rule._getUpdatingTesterList())
kw.update({'portal_type':simulation_movement.getPortalType(),
'id':new_id,
'delivery':None,
......
......@@ -41,12 +41,12 @@ class MovementCollectionDiff(object):
# Declarative interfaces
zope.interface.implements(interfaces.IMovementCollectionDiff,)
def __init__(self, property_id_set=None):
def __init__(self, updating_tester_list=None):
self._deletable_movement_list = []
self._new_movement_list = []
self._updatable_movement_list = []
self._property_dict_dict = {}
self._property_id_set = property_id_set
self._updating_tester_list = updating_tester_list
def getDeletableMovementList(self):
"""
......@@ -89,9 +89,9 @@ class MovementCollectionDiff(object):
"""
property_dict = self._property_dict_dict.get(movement)
if property_dict is None:
if self._property_id_set is not None:
if self._updating_tester_list is not None:
property_dict = _getPropertyDict(movement,
property_id_set=self._property_id_set)
updating_tester_list=self._updating_tester_list)
else:
property_dict = _getPropertyList(movement)
property_dict.update(_getCategoryList(movement, acquire=False))
......@@ -116,11 +116,11 @@ def _getPropertyAndCategoryList(document):
property_dict.update(_getCategoryList(document))
return property_dict
def _getPropertyDict(document, property_id_set=None):
assert property_id_set is not None
def _getPropertyDict(document, updating_tester_list=None):
assert updating_tester_list is not None
property_dict = {}
for property_id in property_id_set:
property_dict[property_id] = document.getProperty(property_id)
for tester in updating_tester_list:
property_dict.update(tester.getUpdatablePropertyDict(document, None))
return property_dict
def _getPropertyList(document, acquire=True):
......
......@@ -41,7 +41,7 @@ class IMovementCollectionUpdater(Interface):
an IMovementCollectionDiff.
"""
def getMovementCollectionDiff(context, rounding=False, movement_generator=None,
property_id_set=None):
updating_tester_list=None):
"""
Return a IMovementCollectionDiff by comparing movements
the list of movements of context and the list of movements
......@@ -54,14 +54,14 @@ class IMovementCollectionUpdater(Interface):
(if not specified, a context implicit
IMovementGenerator will be used)
property_id_set -- an optional list of properties that we
care on movements. This allows to improve
updating_tester_list -- an optional list of testers used to get properties
that we care on movements. This allows to improve
performance by not looking at properties
we don't care
"""
def updateMovementCollection(context, rounding=False, movement_generator=None,
property_id_set=None):
updating_tester_list=None):
"""
Invoke getMovementCollectionDiff and update context with
the resulting IMovementCollectionDiff.
......@@ -73,8 +73,8 @@ class IMovementCollectionUpdater(Interface):
(if not specified, a context implicit
IMovementGenerator will be used)
property_id_set -- an optional list of properties that we
care on movements. This allows to improve
updating_tester_list -- an optional list of testers used to get properties
that we care on movements. This allows to improve
performance by not looking at properties
we don't care
"""
......@@ -52,7 +52,7 @@ class MovementCollectionUpdaterMixin:
# Implementation of IMovementCollectionUpdater
def getMovementCollectionDiff(self, context, rounding=False,
movement_generator=None,
property_id_set=None):
updating_tester_list=None):
"""
Return a IMovementCollectionDiff by comparing movements
the list of movements of context and the list of movements
......@@ -65,7 +65,7 @@ class MovementCollectionUpdaterMixin:
(if not specified, a context implicit
IMovementGenerator will be used)
property_id_set -- a set listing properties we are looking in movements
updating_tester_list -- a list of testers used to build updatable dicts
"""
# We suppose here that we have an IMovementCollection in hand
decision_movement_list = context.getMovementList()
......@@ -142,7 +142,7 @@ class MovementCollectionUpdaterMixin:
# Third, time to create the diff
movement_collection_diff = MovementCollectionDiff(
property_id_set=property_id_set)
updating_tester_list=updating_tester_list)
for (prevision_movement, decision_movement_list) in prevision_to_decision_map:
self._extendMovementCollectionDiff(movement_collection_diff, prevision_movement,
decision_movement_list)
......@@ -151,7 +151,7 @@ class MovementCollectionUpdaterMixin:
def updateMovementCollection(self, context, rounding=False,
movement_generator=None,
property_id_set=None):
updating_tester_list=None):
"""
Invoke getMovementCollectionDiff and update context with
the resulting IMovementCollectionDiff.
......@@ -163,11 +163,11 @@ class MovementCollectionUpdaterMixin:
(if not specified, a context implicit
IMovementGenerator will be used)
property_id_set -- a set listing properties we are looking in movements
updating_tester_list -- a list of testers used to build updatable dicts
"""
movement_diff = self.getMovementCollectionDiff(context,
rounding=rounding, movement_generator=movement_generator,
property_id_set=property_id_set)
updating_tester_list=updating_tester_list)
# Apply Diff
for movement in movement_diff.getDeletableMovementList():
......
......@@ -193,15 +193,6 @@ class RuleMixin(Predicate):
return False
return super(RuleMixin, self).test(*args, **kw)
@caching_instance_method(id="Rule.getUpdatablePropertyIdSet",
cache_factory='erp5_content_long',
cache_id_generator=lambda method_id, document: document.getUid())
def getUpdatablePropertyIdSet(self):
property_id_set = set()
[property_id_set.update(x.getTestedPropertyList()) for x in \
self._getUpdatingTesterList()]
return property_id_set
def expand(self, applied_rule, **kw):
"""
Expand this applied rule to create new documents inside the
......@@ -217,7 +208,7 @@ class RuleMixin(Predicate):
# although rounding in simulation is not recommended at all
self.updateMovementCollection(applied_rule,
movement_generator=self._getMovementGenerator(applied_rule),
property_id_set=self.getUpdatablePropertyIdSet())
updating_tester_list=self._getUpdatingTesterList())
# And forward expand
for movement in applied_rule.getMovementList():
movement.expand(**kw)
......
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