Scheduled maintenance on Saturday, 27 September 2025, from 07:00 AM to 4:00 PM GMT (09:00 AM to 6:00 PM CEST) - some services may be unavailable -

Skip to content
Snippets Groups Projects
Context.py 1.56 KiB
Newer Older
  • Learn to ignore specific revisions
  • Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    from typing import Dict
    from ...engines._DatabaseEngine import _DatabaseEngine
    from ..entity._Entity import _Entity
    from ..entity.EntityAttributes import EntityAttributes
    from ..entity.EntityCollection import EntityCollection
    from .Keys import KEY_CONTEXT, KEY_TOPOLOGIES
    from .Topology import Topology
    
    VALIDATORS = {}
    
    class Context(_Entity):
        def __init__(self, context_uuid : str, database_engine : _DatabaseEngine):
            self._database_engine = database_engine
            super().__init__(parent=self)
            self._context_uuid = context_uuid
            self._attributes = EntityAttributes(self, KEY_CONTEXT, validators=VALIDATORS)
            self._topologies = EntityCollection(self, KEY_TOPOLOGIES)
    
        @property
        def database_engine(self) -> _DatabaseEngine: return self._database_engine
    
        @property
        def parent(self) -> 'Context': return self
    
        @property
        def context(self) -> 'Context': return self
    
        @property
        def context_uuid(self) -> str: return self._context_uuid
    
        @property
        def attributes(self) -> EntityAttributes: return self._attributes
    
        @property
        def topologies(self) -> EntityCollection: return self._topologies
    
        def topology(self, topology_uuid : str) -> Topology: return Topology(topology_uuid, self)
    
        def create(self) -> 'Context': return self
    
        def delete(self):
            for topology_uuid in self.topologies.get(): self.topology(topology_uuid).delete()
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
            self.attributes.delete()
    
    Lluis Gifre Renom's avatar
    Lluis Gifre Renom committed
    
        def dump(self) -> Dict:
            return {topology_uuid : self.topology(topology_uuid).dump() for topology_uuid in self.topologies.get()}