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