Models / Mapping

AttributeMapping

class teksi_hooks.models.mapping.AttributeMapping(canonical_class_id, canonical_attr_id, foreign_key=None, values=<factory>, value_list=None)[source]

Map one source-model attribute to one canonical target attribute.

Declarative attribute mappings intentionally support one canonical target. A source attribute requiring multiple canonical effects must use a function mapping instead.

Parameters:

Fields

canonical_class_id

Type: str

Canonical class identifier containing the target attribute.

canonical_attr_id

Type: str

Canonical attribute identifier receiving the mapped source value.

foreign_key

Type: ForeignKeyMapping | None

Optional reference metadata used when the canonical target attribute stores a foreign-key reference.

values

Type: Mapping[str, ValueMapping]

Optional static value mappings keyed by source-model value.

value_list

Type: ValueListMapping | None

Optional database-backed value-list translation. The source value is matched using the configured mapping attribute and translated to the configured canonical value attribute.

ClassMapping

class teksi_hooks.models.mapping.ClassMapping(canonical_class_id=None, identity=None, identities=<factory>, attributes=<factory>, relations=<factory>, localisations=<factory>, function=None)[source]

Map one source-model class to the canonical internal model.

A class may use either a class-level function mapping or declarative attribute mappings. Function-backed mappings return a complete JSONB effect document.

Parameters:
property is_function_backed: bool

Return whether the class uses a database projection function.

property is_attribute_backed: bool

Return whether the class declares attribute mappings.

source_identifier(language)[source]

Return the exact source-model class identifier for one language.

Parameters:

language (str)

Return type:

str | None

Fields

canonical_class_id

Type: str | None

Optional primary canonical class identifier represented by the source class. This may be omitted for function-backed or extension-only mappings.

identity

Type: CanonicalIdentityMapping | None

Optional primary identity override for the class. Missing source or canonical identity attributes are inherited from the model defaults during mapping resolution.

identities

Type: Mapping[str, CanonicalIdentityMapping | None]

Identity mappings keyed by canonical target class. A null mapping declares the target class while inheriting the complete model-default identity. A partial mapping may override the canonical or source identity attribute.

attributes

Type: Mapping[str, AttributeMapping]

Declarative attribute mappings keyed by source runtime attribute identifier. For ili2pg imports this is the actual SQLAlchemy or ili2pg column name, which may differ from the original INTERLIS attribute name.

relations

Type: Mapping[str, RelationMapping]

Class-specific canonical relation mappings keyed by stable canonical relation identifier. These mappings override model-default relations with the same identifier.

localisations

Type: Mapping[str, str]

Exact source-model class identifiers keyed by source language. Values are executable model identifiers rather than translated display labels.

function

Type: FunctionMapping | None

Optional database-backed class projection function. The function receives configured source-row values and returns the complete canonical JSONB effect document.

ForeignKeyMapping

class teksi_hooks.models.mapping.ForeignKeyMapping(referenced_class_id, referenced_attribute_id='obj_id')[source]

Describe the canonical object referenced by a mapped attribute.

This is used when the mapped canonical attribute stores a reference rather than a literal value.

Parameters:
  • referenced_class_id (str)

  • referenced_attribute_id (str)

Fields

referenced_class_id

Type: str

Canonical identifier of the referenced class. Corresponds to a class or table in the internal semantic model.

referenced_attribute_id

Type: str

Canonical identifier of the referenced attribute. Defaults to the canonical object identifier obj_id.

FunctionMapping

class teksi_hooks.models.mapping.FunctionMapping(schema, name, parameters=<factory>)[source]

Describe a database-backed mapping function.

Function mappings handle source classes whose canonical effects cannot be represented by one-to-one attribute mappings.

The configured function receives values from the source row and returns a complete canonical JSONB effect document. The result is authoritative and must not be supplemented with declarative attribute mappings.

Parameters:
  • schema (str)

  • name (str)

  • parameters (Mapping[str, str])

Fields

schema

Type: str

Database schema containing the mapping function. Example: tww_app.

name

Type: str

Database function name implementing the mapping. Example: fct_agxx_gepknoten_mapping_jsonb.

parameters

Type: Mapping[str, str]

Function parameter mappings keyed by database function parameter name. Values identify source-row expressions or source-model attributes. The special value $row passes the complete source row.

MappingDefaults

class teksi_hooks.models.mapping.MappingDefaults(identity=<factory>, identities=<factory>, attributes=<factory>, relations=<factory>, inherit_from=None)[source]

Define mappings inherited by classes in one source model.

Parameters:

Fields

identity

Type: CanonicalIdentityMapping

Default source-to-canonical identity mapping. Class-level target identities may override either attribute.

identities

Type: Mapping[str, CanonicalIdentityMapping]

Default identity mappings keyed by canonical target class. An identity describes how effects address a target row and does not independently require that row to exist.

attributes

Type: Mapping[str, AttributeMapping]

Default attribute mappings keyed by source-model runtime attribute identifier. A default mapping applies to a class only when that source class defines the source attribute.

relations

Type: Mapping[str, RelationMapping]

Default canonical relation mappings keyed by stable canonical relation identifier.

inherit_from

Type: str | None

Optional source-model mapping identifier inherited by this model. Inherited defaults are resolved before local overrides. Mapping inheritance must be acyclic.

ModelMapping

class teksi_hooks.models.mapping.ModelMapping(defaults=<factory>, classes=<factory>, is_ssot=False, languages=<factory>)[source]

Describe how one source model maps to the canonical internal model.

Source class, attribute and relation identifiers are scoped to this model and may be localized. Canonical class, attribute, relation and value identifiers remain independent of the source-model language.

Parameters:

Fields

defaults

Type: MappingDefaults

Default identities, attributes and relations inherited by classes in this source model.

classes

Type: Mapping[str, ClassMapping]

Class mappings keyed by source-model class identifier or stable mapping identifier, according to the selected source-model mapping contract.

is_ssot

Type: bool

Whether this model mapping describes a canonical single-source-of-truth model.

languages

Type: frozenset[str]

Source languages explicitly supported by this model mapping. An unavailable requested language must not be silently replaced by another language.

ModelMappings

class teksi_hooks.models.mapping.ModelMappings(models=<factory>)[source]

Contain explicit mappings for all configured source models.

Parameters:

models (Mapping[str, ModelMapping])

Fields

models

Type: Mapping[str, ModelMapping]

Model mappings keyed by stable source-model mapping identifier. Example identifiers include agxx, sia405_abwasser, dss and vsa_kek.

RelationContext

class teksi_hooks.models.mapping.RelationContext(relation, class_mapping)[source]

Provide runtime context for one mapped relation.

The context links a concrete SQLAlchemy ORM relation with the resolved semantic class mapping used by the diff and validation pipeline.

Parameters:

Fields

relation

Type: type

SQLAlchemy ORM relation generated for the source model.

class_mapping

Type: ClassMapping

Resolved mapping for the source-model class represented by the ORM relation.

RelationMapping

class teksi_hooks.models.mapping.RelationMapping(referenced_class_id, referenced_attribute_id='obj_id', localisations=<factory>)[source]

Map a canonical relation to a localized source-model relation.

Canonical relation and target identifiers remain independent of the source-model language. Localized identifiers are exact executable source-model element identifiers and are not display labels.

Parameters:
  • referenced_class_id (str)

  • referenced_attribute_id (str)

  • localisations (Mapping[str, str])

source_identifier(language)[source]

Return the exact source-model identifier for one language.

Parameters:

language (str)

Return type:

str | None

Fields

referenced_class_id

Type: str

Canonical identifier of the class referenced by the relation. Example: organisation.

referenced_attribute_id

Type: str

Canonical identifier of the referenced target attribute. Defaults to obj_id.

localisations

Type: Mapping[str, str]

Exact source-model relation identifiers keyed by source language. Example: {‘de’: ‘DatenbewirtschafterRef’}.

ValueListMapping

class teksi_hooks.models.mapping.ValueListMapping(relation, mapping_attribute, value_attribute='code')[source]

Describe a database-backed source-to-canonical value translation.

Parameters:
  • relation (str)

  • mapping_attribute (str)

  • value_attribute (str)

Fields

relation

Type: str

Qualified database relation used for value translation. Example: tww_vl.measure_category_import_rel_agxx.

mapping_attribute

Type: str

Relation attribute matched against the submitted source-model value. Example: value_de.

value_attribute

Type: str

Relation attribute containing the resulting canonical value. Defaults to code.

ValueMapping

class teksi_hooks.models.mapping.ValueMapping(canonical_value_id, value)[source]

Map one source-model value to a canonical internal value.

Parameters:
  • canonical_value_id (int)

  • value (str)

Fields

canonical_value_id

Type: int

Canonical value identifier. Corresponds to a value-list code or database value identifier.

value

Type: str

Source-model value mapped to the canonical value. For a single-source-of-truth model, this may be the canonical English value associated with the canonical code.