-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/mx-1649 prepare preventive and subtractive rule editing (#330)
### PR Context - some fixes and additions for robert-koch-institut/mex-editor#192 - `mex/common/fields.py` is a port of [`mex/backend/fields.py`](https://github.com/robert-koch-institut/mex-backend/blob/0.22.0/mex/backend/fields.py) - because it is needed by the editor too - prevent pydantic 2.10, because it broke tests: #341 ### Added - add vocabulary and temporal unions and lookups to `mex.common.types` - add `mex.common.fields` with field type by class name lookups ### Changes - set default empty rules to all of the rule-set models - pin pydantic to sub 2.10 (for now) because of breaking changes ### Fixed - switch HTTP method for preview endpoint to `POST` - add optional values to variadic values for distribution models - make `endpointDescription` optional for variadic access platform models --------- Signed-off-by: Nicolas Drebenstedt <[email protected]>
- Loading branch information
1 parent
8b837e3
commit b1bb746
Showing
28 changed files
with
433 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
from mex.common.models import ( | ||
ADDITIVE_MODEL_CLASSES_BY_NAME, | ||
EXTRACTED_MODEL_CLASSES_BY_NAME, | ||
MERGED_MODEL_CLASSES_BY_NAME, | ||
PREVENTIVE_MODEL_CLASSES_BY_NAME, | ||
SUBTRACTIVE_MODEL_CLASSES_BY_NAME, | ||
) | ||
from mex.common.types import ( | ||
MERGED_IDENTIFIER_CLASSES, | ||
TEMPORAL_ENTITIES, | ||
VOCABULARY_ENUMS, | ||
Email, | ||
Link, | ||
LiteralStringType, | ||
Text, | ||
) | ||
from mex.common.utils import contains_only_types, group_fields_by_class_name | ||
|
||
# all models classes | ||
ALL_MODEL_CLASSES_BY_NAME = { | ||
**ADDITIVE_MODEL_CLASSES_BY_NAME, | ||
**EXTRACTED_MODEL_CLASSES_BY_NAME, | ||
**MERGED_MODEL_CLASSES_BY_NAME, | ||
**PREVENTIVE_MODEL_CLASSES_BY_NAME, | ||
**SUBTRACTIVE_MODEL_CLASSES_BY_NAME, | ||
} | ||
|
||
# fields that are immutable and can only be set once | ||
FROZEN_FIELDS_BY_CLASS_NAME = group_fields_by_class_name( | ||
ALL_MODEL_CLASSES_BY_NAME, | ||
lambda field_info: field_info.frozen is True, | ||
) | ||
|
||
# static fields that are set once on class-level to a literal type | ||
LITERAL_FIELDS_BY_CLASS_NAME = group_fields_by_class_name( | ||
ALL_MODEL_CLASSES_BY_NAME, | ||
lambda field_info: isinstance(field_info.annotation, LiteralStringType), | ||
) | ||
|
||
# fields typed as merged identifiers containing references to merged items | ||
REFERENCE_FIELDS_BY_CLASS_NAME = group_fields_by_class_name( | ||
ALL_MODEL_CLASSES_BY_NAME, | ||
lambda field_info: contains_only_types(field_info, *MERGED_IDENTIFIER_CLASSES), | ||
) | ||
|
||
# nested fields that contain `Text` objects | ||
TEXT_FIELDS_BY_CLASS_NAME = group_fields_by_class_name( | ||
ALL_MODEL_CLASSES_BY_NAME, | ||
lambda field_info: contains_only_types(field_info, Text), | ||
) | ||
|
||
# nested fields that contain `Link` objects | ||
LINK_FIELDS_BY_CLASS_NAME = group_fields_by_class_name( | ||
ALL_MODEL_CLASSES_BY_NAME, | ||
lambda field_info: contains_only_types(field_info, Link), | ||
) | ||
|
||
# fields annotated as `Email` type | ||
EMAIL_FIELDS_BY_CLASS_NAME = group_fields_by_class_name( | ||
ALL_MODEL_CLASSES_BY_NAME, | ||
lambda field_info: contains_only_types(field_info, Email), | ||
) | ||
|
||
# fields annotated as `int` type | ||
INTEGER_FIELDS_BY_CLASS_NAME = group_fields_by_class_name( | ||
ALL_MODEL_CLASSES_BY_NAME, | ||
lambda field_info: contains_only_types(field_info, int), | ||
) | ||
|
||
# fields annotated as `str` type | ||
STRING_FIELDS_BY_CLASS_NAME = group_fields_by_class_name( | ||
ALL_MODEL_CLASSES_BY_NAME, | ||
lambda field_info: contains_only_types(field_info, str), | ||
) | ||
|
||
# fields annotated as any temporal type | ||
TEMPORAL_FIELDS_BY_CLASS_NAME = group_fields_by_class_name( | ||
ALL_MODEL_CLASSES_BY_NAME, | ||
lambda field_info: contains_only_types(field_info, *TEMPORAL_ENTITIES), | ||
) | ||
|
||
# fields annotated as any vocabulary enum | ||
VOCABULARY_FIELDS_BY_CLASS_NAME = group_fields_by_class_name( | ||
ALL_MODEL_CLASSES_BY_NAME, | ||
lambda field_info: contains_only_types(field_info, *VOCABULARY_ENUMS), | ||
) | ||
|
||
# fields with changeable values that are not nested objects or merged item references | ||
MUTABLE_FIELDS_BY_CLASS_NAME = { | ||
name: sorted( | ||
{ | ||
field_name | ||
for field_name in cls.get_all_fields() | ||
if field_name | ||
not in ( | ||
*FROZEN_FIELDS_BY_CLASS_NAME[name], | ||
*REFERENCE_FIELDS_BY_CLASS_NAME[name], | ||
*TEXT_FIELDS_BY_CLASS_NAME[name], | ||
*LINK_FIELDS_BY_CLASS_NAME[name], | ||
) | ||
} | ||
) | ||
for name, cls in ALL_MODEL_CLASSES_BY_NAME.items() | ||
} | ||
|
||
# fields with mergeable values that are neither literal nor frozen | ||
MERGEABLE_FIELDS_BY_CLASS_NAME = { | ||
name: sorted( | ||
{ | ||
field_name | ||
for field_name in cls.model_fields | ||
if field_name | ||
not in ( | ||
*FROZEN_FIELDS_BY_CLASS_NAME[name], | ||
*LITERAL_FIELDS_BY_CLASS_NAME[name], | ||
) | ||
} | ||
) | ||
for name, cls in ALL_MODEL_CLASSES_BY_NAME.items() | ||
} | ||
|
||
# fields with values that should be set once but are neither literal nor references | ||
FINAL_FIELDS_BY_CLASS_NAME = { | ||
name: sorted( | ||
{ | ||
field_name | ||
for field_name in cls.get_all_fields() | ||
if field_name in FROZEN_FIELDS_BY_CLASS_NAME[name] | ||
and field_name | ||
not in ( | ||
*LITERAL_FIELDS_BY_CLASS_NAME[name], | ||
*REFERENCE_FIELDS_BY_CLASS_NAME[name], | ||
) | ||
} | ||
) | ||
for name, cls in ALL_MODEL_CLASSES_BY_NAME.items() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
__all__ = ( | ||
"BaseProvider", | ||
"get_provider", | ||
"Identity", | ||
"get_provider", | ||
"register_provider", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.