-
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-1708 backend id provider (#366)
### PR Context - this PR reduces code-duplication by moving the backend id provider to mex-common ### Added - port backend identity provider implementation from editor/extractors to common - https://github.com/robert-koch-institut/mex-extractors/blob/0.25.0/mex/extractors/identity.py#L11 - https://github.com/robert-koch-institut/mex-editor/blob/0.8.0/mex/editor/identity.py#L13 ### Changes - allow backend and graph as identity provider setting to simplify setting subclasses, even though graph is not implemented in mex-common - BREAKING: make backend api connector response models generic, to keep DRY
- Loading branch information
1 parent
4b17737
commit 4f66746
Showing
8 changed files
with
215 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from functools import cache | ||
|
||
from mex.common.backend_api.connector import BackendApiConnector | ||
from mex.common.backend_api.models import ItemsContainer | ||
from mex.common.identity.base import BaseProvider | ||
from mex.common.identity.models import Identity | ||
from mex.common.types import Identifier, MergedPrimarySourceIdentifier | ||
|
||
|
||
class BackendApiIdentityProvider(BaseProvider, BackendApiConnector): | ||
"""Identity provider that communicates with the backend HTTP API.""" | ||
|
||
@cache # noqa: B019 | ||
def assign( | ||
self, | ||
had_primary_source: MergedPrimarySourceIdentifier, | ||
identifier_in_primary_source: str, | ||
) -> Identity: | ||
"""Find an Identity in a database or assign a new one.""" | ||
response = self.request( | ||
"POST", | ||
"identity", | ||
{ | ||
"hadPrimarySource": had_primary_source, | ||
"identifierInPrimarySource": identifier_in_primary_source, | ||
}, | ||
) | ||
return Identity.model_validate(response) | ||
|
||
def fetch( | ||
self, | ||
*, | ||
had_primary_source: Identifier | None = None, | ||
identifier_in_primary_source: str | None = None, | ||
stable_target_id: Identifier | None = None, | ||
) -> list[Identity]: | ||
"""Find Identity instances matching the given filters. | ||
Either provide `stableTargetId` or `hadPrimarySource` | ||
and `identifierInPrimarySource` together to get a unique result. | ||
""" | ||
response = self.request( | ||
"GET", | ||
"identity", | ||
params={ | ||
key: str(value) | ||
for key, value in [ | ||
("hadPrimarySource", had_primary_source), | ||
("identifierInPrimarySource", identifier_in_primary_source), | ||
("stableTargetId", stable_target_id), | ||
] | ||
}, | ||
) | ||
return ItemsContainer[Identity].model_validate(response).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
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.