def propagate(self, event): """Re-emit state change for the derived union (as Derived*Event's). TODO: We should fetch the old and new state of the namespace item in stead of the old and new values of the item that changed. If multiplicity is [0..1]: send DerivedSet if len(union) < 2 if multiplicity is [*]: send DerivedAdded and DerivedDeleted if value not in derived union and """ if event.property not in self.subsets: return # Make sure unions are created again self.version += 1 if not isinstance(event, AssociationUpdated): return values = self._union(event.element, exclude=event.property) if self.upper == 1: assert isinstance(event, AssociationSet) old_value, new_value = event.old_value, event.new_value # This is a [0..1] event if not self.single: new_values = set(values) if new_value: new_values.add(new_value) if len(new_values) > 1: # In an in-between state. Do not emit notifications return if values: new_value = next(iter(values)) # Only one subset element, so pass the values on self.handle(DerivedSet(event.element, self, old_value, new_value)) else: if isinstance(event, AssociationSet): old_value, new_value = event.old_value, event.new_value if old_value and old_value not in values: self.handle(DerivedDeleted(event.element, self, old_value)) if new_value and new_value not in values: self.handle(DerivedAdded(event.element, self, new_value)) elif isinstance(event, AssociationAdded): new_value = event.new_value if new_value not in values: self.handle(DerivedAdded(event.element, self, new_value)) elif isinstance(event, AssociationDeleted): old_value = event.old_value if old_value not in values: self.handle(DerivedDeleted(event.element, self, old_value)) elif isinstance(event, AssociationUpdated): self.handle(DerivedUpdated(event.element, self)) else: log.error("Don't know how to handle event " + str(event) + " for derived union")
def propagate(self, event): """ Re-emit state change for the derived properties as Derived*Event's. TODO: We should fetch the old and new state of the namespace item in stead of the old and new values of the item that changed. If multiplicity is [0..1]: send DerivedSet if len(union) < 2 if multiplicity is [*]: send DerivedAdded and DerivedDeleted if value not in derived union and """ if event.property in self.subsets: if not isinstance(event, AssociationUpdated): return # mimic the events for Set/Add/Delete if self.upper == 1: # This is a [0..1] event # TODO: This is an error: [0..*] associations may be used for updating [0..1] associations # assert isinstance( # event, AssociationSet # ), f"Can only handle [0..1] set-events, not {event} for {event.element}" old_value = self._get(event.element) # Make sure unions are created again self.version += 1 new_value = self._get(event.element) if old_value != new_value: self.handle( DerivedSet(event.element, self, old_value, new_value)) else: # Make sure unions are created again self.version += 1 if isinstance(event, AssociationSet): self.handle( DerivedDeleted(event.element, self, event.old_value)) self.handle( DerivedAdded(event.element, self, event.new_value)) elif isinstance(event, AssociationAdded): self.handle( DerivedAdded(event.element, self, event.new_value)) elif isinstance(event, AssociationDeleted): self.handle( DerivedDeleted(event.element, self, event.old_value)) elif isinstance(event, AssociationUpdated): self.handle(DerivedUpdated(event.element, self)) else: log.error("Don't know how to handle event " + str(event) + " for derived union")