Model/applications/condition/factory.py
Khalim Conn-Kowlessar 735e83cef2 Relocate condition-data ingestion into the DDD layout 🟪
Behaviour-preserving lift-and-shift of the condition module out of legacy
backend/condition/ into domain/condition, infrastructure/condition,
infrastructure/postgres/condition_tables.py, repositories/condition,
applications/condition, and tests/condition. Imports rewritten to the DDD
paths; ConditionPostgres and the ORM models keep the legacy backend.app.db
Base/db_session bridges so the existing suite proves behaviour is unchanged
(SQLModel + session-DI conversion tracked as a follow-up in ADR-0064).

16 condition tests pass at the new location.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-13 14:51:25 +00:00

35 lines
1.3 KiB
Python

from typing import Optional
from applications.condition.condition_trigger_request import ConditionFileType
from domain.condition.mapping.lbwf.lbwf_mapper import LbwfMapper
from domain.condition.mapping.mapper import Mapper
from domain.condition.mapping.peabody.peabody_mapper import PeabodyMapper
from repositories.condition.uprn_lookup import UprnLookup
from infrastructure.condition.parsing.parser import Parser
from infrastructure.condition.parsing.lbwf_parser import LbwfParser
from infrastructure.condition.parsing.peabody_parser import PeabodyParser
def select_parser(
file_type: ConditionFileType, uprn_lookup: Optional[UprnLookup] = None
) -> Parser:
if file_type is ConditionFileType.LBWF:
return LbwfParser()
if file_type is ConditionFileType.Peabody:
if not uprn_lookup:
raise ValueError(
"Cannot instantiate Peabody Parser without UPRN lookup being provided"
)
return PeabodyParser(uprn_lookup=uprn_lookup)
raise ValueError("Unrecognised file type, unable to instantiate Parser")
def select_mapper(file_type: ConditionFileType) -> Mapper:
if file_type is ConditionFileType.LBWF:
return LbwfMapper()
if file_type is ConditionFileType.Peabody:
return PeabodyMapper()
raise ValueError("Unrecognised file type, unable to instantiate Mapper")