Skip to content

Commit

Permalink
Feature/mx 1070 model lists (#4)
Browse files Browse the repository at this point in the history
- expose Merged, Base and Extracted model classes in `mex.common.models`
- deprecating `MODEL_CLASSES`, `MODEL_CLASSES_BY_ENTITY_TYPE` constants
  • Loading branch information
cutoffthetop authored Jul 11, 2023
1 parent 7ebd779 commit f0acba4
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 62 deletions.
126 changes: 112 additions & 14 deletions mex/common/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,66 @@
from typing import Final

from mex.common.models.access_platform import ExtractedAccessPlatform
from mex.common.models.activity import ExtractedActivity
from mex.common.models.access_platform import (
BaseAccessPlatform,
ExtractedAccessPlatform,
MergedAccessPlatform,
)
from mex.common.models.activity import BaseActivity, ExtractedActivity, MergedActivity
from mex.common.models.base import BaseModel, MExModel
from mex.common.models.contact_point import ExtractedContactPoint
from mex.common.models.distribution import ExtractedDistribution
from mex.common.models.organization import ExtractedOrganization
from mex.common.models.organizational_unit import ExtractedOrganizationalUnit
from mex.common.models.person import ExtractedPerson
from mex.common.models.primary_source import ExtractedPrimarySource
from mex.common.models.resource import ExtractedResource
from mex.common.models.variable import ExtractedVariable
from mex.common.models.variable_group import ExtractedVariableGroup
from mex.common.models.contact_point import (
BaseContactPoint,
ExtractedContactPoint,
MergedContactPoint,
)
from mex.common.models.distribution import (
BaseDistribution,
ExtractedDistribution,
MergedDistribution,
)
from mex.common.models.extracted_data import BaseExtractedData, ExtractedData
from mex.common.models.merged_item import MergedItem
from mex.common.models.organization import (
BaseOrganization,
ExtractedOrganization,
MergedOrganization,
)
from mex.common.models.organizational_unit import (
BaseOrganizationalUnit,
ExtractedOrganizationalUnit,
MergedOrganizationalUnit,
)
from mex.common.models.person import BasePerson, ExtractedPerson, MergedPerson
from mex.common.models.primary_source import (
BasePrimarySource,
ExtractedPrimarySource,
MergedPrimarySource,
)
from mex.common.models.resource import BaseResource, ExtractedResource, MergedResource
from mex.common.models.variable import BaseVariable, ExtractedVariable, MergedVariable
from mex.common.models.variable_group import (
BaseVariableGroup,
ExtractedVariableGroup,
MergedVariableGroup,
)

__all__ = (
"BaseAccessPlatform",
"BaseActivity",
"BaseContactPoint",
"BaseDistribution",
"BaseExtractedData",
"BaseModel",
"BaseOrganization",
"BaseOrganizationalUnit",
"BasePerson",
"BasePrimarySource",
"BaseResource",
"BaseVariable",
"BaseVariableGroup",
"ExtractedAccessPlatform",
"ExtractedActivity",
"ExtractedContactPoint",
"ExtractedData",
"ExtractedDistribution",
"ExtractedOrganization",
"ExtractedOrganizationalUnit",
Expand All @@ -26,10 +69,43 @@
"ExtractedResource",
"ExtractedVariable",
"ExtractedVariableGroup",
"MergedAccessPlatform",
"MergedActivity",
"MergedContactPoint",
"MergedDistribution",
"MergedItem",
"MergedModel",
"MergedOrganization",
"MergedOrganizationalUnit",
"MergedPerson",
"MergedPrimarySource",
"MergedResource",
"MergedVariable",
"MergedVariableGroup",
"MExModel",
)

MODEL_CLASSES: Final[list[type[MExModel]]] = [
BASE_MODEL_CLASSES: Final[list[type[BaseModel]]] = [
BaseAccessPlatform,
BaseActivity,
BaseContactPoint,
BaseDistribution,
BaseExtractedData,
BaseModel,
BaseOrganization,
BaseOrganizationalUnit,
BasePerson,
BasePrimarySource,
BaseResource,
BaseVariable,
BaseVariableGroup,
]

BASE_MODEL_CLASSES_BY_NAME: Final[dict[str, type[BaseModel]]] = {
cls.__name__: cls for cls in BASE_MODEL_CLASSES
}

EXTRACTED_MODEL_CLASSES: Final[list[type[ExtractedData]]] = [
ExtractedAccessPlatform,
ExtractedActivity,
ExtractedContactPoint,
Expand All @@ -43,6 +119,28 @@
ExtractedVariableGroup,
]

MODEL_CLASSES_BY_ENTITY_TYPE: Final[dict[str, type[MExModel]]] = {
cls.get_entity_type(): cls for cls in MODEL_CLASSES
EXTRACTED_MODEL_CLASSES_BY_NAME: Final[dict[str, type[ExtractedData]]] = {
cls.__name__: cls for cls in EXTRACTED_MODEL_CLASSES
}

MERGED_MODEL_CLASSES: Final[list[type[MergedItem]]] = [
MergedAccessPlatform,
MergedActivity,
MergedContactPoint,
MergedDistribution,
MergedOrganization,
MergedOrganizationalUnit,
MergedPerson,
MergedPrimarySource,
MergedResource,
MergedVariable,
MergedVariableGroup,
]

MERGED_MODEL_CLASSES_BY_NAME: Final[dict[str, type[MergedItem]]] = {
cls.__name__: cls for cls in MERGED_MODEL_CLASSES
}

# bw-compat
MODEL_CLASSES = EXTRACTED_MODEL_CLASSES
MODEL_CLASSES_BY_ENTITY_TYPE = EXTRACTED_MODEL_CLASSES_BY_NAME
95 changes: 48 additions & 47 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "mex-common"
version = "0.9.0"
version = "0.9.1"
description = "RKI MEx common library."
authors = ["RKI MEx Team <mex@rki.de>"]
readme = "README.md"
Expand Down

0 comments on commit f0acba4

Please sign in to comment.