Changeset b24d72e in flexoentity


Ignore:
Timestamp:
11/21/25 11:01:43 (8 weeks ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
master
Children:
a475496
Parents:
9592936
Message:

move DomainManager to FlexoGrader

Files:
2 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • flexoentity/__init__.py

    r9592936 rb24d72e  
    1414from .flexo_entity import FlexoEntity, EntityType, EntityState
    1515from .domain import Domain
    16 from .domain_manager import DomainManager
    1716
    1817__all__ = [
     
    2221    "EntityType",
    2322    "Domain",
    24     "DomainManager"
    2523    "EntityState",
    2624    "logger"
  • flexoentity/flexo_entity.py

    r9592936 rb24d72e  
    205205    @classmethod
    206206    def with_domain_id(cls, domain_id: str, **kwargs):
    207         from .domain_manager import DomainManager
     207        # from .domain_manager import DomainManager
    208208        entity_type = getattr(cls, "ENTITY_TYPE", None)
    209209        if not entity_type:
    210210            raise ValueError(f"{cls.__name__} must define ENTITY_TYPE")
    211211
    212         if entity_type == EntityType.DOMAIN:
    213             DomainManager.create(domain_id=domain_id,
    214                                  fullname=kwargs.get("fullname", ""),
    215                                  description=kwargs.get("description", ""))
    216         else:
     212        #if entity_type == EntityType.DOMAIN:
     213        #    DomainManager.create(domain_id=domain_id,
     214        #                         fullname=kwargs.get("fullname", ""),
     215        #                         description=kwargs.get("description", ""))
     216        #else:
    217217            # require that this domain already exists
    218             if domain_id not in DomainManager.all_domain_ids():
    219                 raise ValueError(
    220                     f"Domain '{domain_id}' does not exist. "
    221                     f"Create it first via Domain.with_domain_id(...)."
    222                 )
     218        #    if domain_id not in DomainManager.all_domain_ids():
     219        #        raise ValueError(
     220        #            f"Domain '{domain_id}' does not exist. "
     221        #            f"Create it first via Domain.with_domain_id(...)."
     222        #        )
    223223
    224224        flexo_id = FlexOID.safe_generate(
     
    235235
    236236    def __post_init__(self):
    237         """
    238         FINAL LOGIC:
    239             - If flexo_id exists → restore domain_id via DomainManager.
    240             - If flexo_id missing → create via safe_generate.
    241             - Domain must always match flexo_id.domain.
    242         """
    243237        if not self._in_factory:
    244238            raise RuntimeError(
    245                 f"{self.__class__.__name__} must be created via with_domain_id() "
    246                 f"or from_dict(), not via direct construction."
     239                f"{self.__class__.__name__} must be created via "
     240                f"with_domain_id() or from_dict()."
    247241            )
    248         # Step 1: If flexo_id exists, restore canonical domain
    249         if self.flexo_id:
    250             return
    251         # Step 2: flexo_id missing → generate one
    252         entity_type = getattr(self.__class__, "ENTITY_TYPE", None)
    253         if not entity_type:
    254             raise ValueError(f"{self.__class__.__name__} must define ENTITY_TYPE")
    255 
    256         if not self.domain_id:
    257             raise ValueError(
    258                 f"{self.__class__.__name__} created without domain; "
    259                 f"use {self.__class__.__name__}.with_domain_id(domain=...) or pass domain explicitly."
     242
     243        if not self.flexo_id:
     244            raise RuntimeError(
     245                f"{self.__class__.__name__} created without flexo_id. "
     246                f"Factory must assign it before __post_init__."
    260247            )
    261248
    262         # Create identity
    263         self.flexo_id = FlexOID.safe_generate(
    264             domain_id=self.domain_id,
    265             entity_type=entity_type.value,
    266             state=EntityState.DRAFT.value,
    267             text=self.text_seed,
    268             version=1,
    269         )
    270 
    271         # Compute fingerprint
    272         self.fingerprint = self._compute_fingerprint()
     249        if not self.fingerprint:
     250            self.fingerprint = self._compute_fingerprint()
    273251
    274252    def __str__(self):
     
    282260        return {
    283261            "flexo_id": str(self.flexo_id),
    284             "domain_id": self.domain_id,
     262            "domain_id": self.flexo_id.domain_id,
    285263            "fingerprint": self.fingerprint,
    286264            "origin": self.origin,
     
    359337            raise ValueError(
    360338                f"Illegal state transition: {self.state.name} → {target_state.name}. "
    361                 f"Allowed: {', '.join([each.name for each in self.allowed_transitions()]) or 'none'}"
    362339            )
    363340
     
    434411            raise ValueError(
    435412                f"Illegal state transition: {self.state.name} → PUBLISHED. "
    436                 f"Allowed: {', '.join([each.name for each in self.allowed_transitions()]) or 'none'}"
    437413            )
    438414
     
    451427    def obsolete(self):
    452428        """I mark myself as obsolete"""
    453         allowed = self.allowed_transitions()
    454429        if EntityState.OBSOLETE not in self.allowed_transitions():
    455430            raise ValueError(
    456431                f"Illegal state transition: {self.state.name} -> OBSOLETE. "
    457                 f"Allowed: {', '.join([each.name for each in self.allowed_transitions()]) or 'none'}"
    458432            )
    459433        if self.state != EntityState.OBSOLETE:
  • tests/conftest.py

    r9592936 rb24d72e  
    44from dataclasses import dataclass, field
    55from typing import List
    6 from flexoentity import FlexOID, FlexoEntity, EntityType, EntityState, Domain, DomainManager
     6from flexoentity import FlexOID, FlexoEntity, EntityType, EntityState, Domain
    77
    88@pytest.fixture
     
    1414    monkeypatch.setattr("flexoentity.id_factory.datetime", FixedDate)
    1515    return FixedDate
    16 
    17 @pytest.fixture(autouse=True)
    18 def reset_domain_manager():
    19     DomainManager.clear()   # You need to implement this
    20     yield
    21     DomainManager.clear()
    22 
    23 @pytest.fixture(autouse=True)
    24 def auto_domains():
    25     Domain.with_domain_id("GENERAL", fullname="General Domain")
    26     Domain.with_domain_id("TEST", fullname="Test Domain")
    2716
    2817@dataclass
Note: See TracChangeset for help on using the changeset viewer.