maleo-metadata-client 0.0.6__tar.gz → 0.0.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of maleo-metadata-client might be problematic. Click here for more details.
- {maleo_metadata_client-0.0.6 → maleo_metadata_client-0.0.8}/PKG-INFO +8 -8
- {maleo_metadata_client-0.0.6 → maleo_metadata_client-0.0.8}/maleo_metadata_client.egg-info/PKG-INFO +8 -8
- {maleo_metadata_client-0.0.6 → maleo_metadata_client-0.0.8}/maleo_metadata_client.egg-info/SOURCES.txt +8 -1
- {maleo_metadata_client-0.0.6 → maleo_metadata_client-0.0.8}/maleo_metadata_client.egg-info/requires.txt +7 -7
- {maleo_metadata_client-0.0.6 → maleo_metadata_client-0.0.8}/pyproject.toml +8 -8
- maleo_metadata_client-0.0.8/src/manager.py +78 -0
- {maleo_metadata_client-0.0.6 → maleo_metadata_client-0.0.8}/src/services/blood_type.py +8 -26
- maleo_metadata_client-0.0.8/src/services/gender.py +304 -0
- maleo_metadata_client-0.0.8/src/services/medical_role.py +354 -0
- maleo_metadata_client-0.0.8/src/services/medical_service.py +306 -0
- maleo_metadata_client-0.0.8/src/services/organization_type.py +310 -0
- maleo_metadata_client-0.0.8/src/services/service.py +304 -0
- maleo_metadata_client-0.0.8/src/services/system_role.py +304 -0
- maleo_metadata_client-0.0.8/src/services/user_type.py +302 -0
- maleo_metadata_client-0.0.6/src/manager.py +0 -15
- {maleo_metadata_client-0.0.6 → maleo_metadata_client-0.0.8}/LICENSE +0 -0
- {maleo_metadata_client-0.0.6 → maleo_metadata_client-0.0.8}/README.md +0 -0
- {maleo_metadata_client-0.0.6 → maleo_metadata_client-0.0.8}/maleo_metadata_client.egg-info/dependency_links.txt +0 -0
- {maleo_metadata_client-0.0.6 → maleo_metadata_client-0.0.8}/maleo_metadata_client.egg-info/top_level.txt +0 -0
- {maleo_metadata_client-0.0.6 → maleo_metadata_client-0.0.8}/setup.cfg +0 -0
- {maleo_metadata_client-0.0.6 → maleo_metadata_client-0.0.8}/src/__init__.py +0 -0
- {maleo_metadata_client-0.0.6 → maleo_metadata_client-0.0.8}/src/services/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: maleo-metadata-client
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.8
|
|
4
4
|
Summary: MaleoMetadata client package
|
|
5
5
|
Author-email: Agra Bima Yuda <agra@nexmedis.com>
|
|
6
6
|
License: MIT
|
|
@@ -51,15 +51,15 @@ Requires-Dist: idna>=3.10
|
|
|
51
51
|
Requires-Dist: importlib_metadata>=8.7.0
|
|
52
52
|
Requires-Dist: iniconfig>=2.1.0
|
|
53
53
|
Requires-Dist: maleo-crypto>=0.0.28
|
|
54
|
-
Requires-Dist: maleo-database>=0.1.
|
|
54
|
+
Requires-Dist: maleo-database>=0.1.42
|
|
55
55
|
Requires-Dist: maleo-enums>=0.0.28
|
|
56
|
-
Requires-Dist: maleo-google>=0.
|
|
57
|
-
Requires-Dist: maleo-infra>=0.1.
|
|
56
|
+
Requires-Dist: maleo-google>=0.1.12
|
|
57
|
+
Requires-Dist: maleo-infra>=0.1.42
|
|
58
58
|
Requires-Dist: maleo-logging>=0.0.28
|
|
59
|
-
Requires-Dist: maleo-managers>=0.0.
|
|
60
|
-
Requires-Dist: maleo-metadata>=0.3.
|
|
61
|
-
Requires-Dist: maleo-middlewares>=0.
|
|
62
|
-
Requires-Dist: maleo-schemas>=0.1.
|
|
59
|
+
Requires-Dist: maleo-managers>=0.0.92
|
|
60
|
+
Requires-Dist: maleo-metadata>=0.3.32
|
|
61
|
+
Requires-Dist: maleo-middlewares>=0.1.12
|
|
62
|
+
Requires-Dist: maleo-schemas>=0.1.42
|
|
63
63
|
Requires-Dist: maleo-types>=0.0.8
|
|
64
64
|
Requires-Dist: maleo-utils>=0.0.28
|
|
65
65
|
Requires-Dist: motor>=3.7.1
|
{maleo_metadata_client-0.0.6 → maleo_metadata_client-0.0.8}/maleo_metadata_client.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: maleo-metadata-client
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.8
|
|
4
4
|
Summary: MaleoMetadata client package
|
|
5
5
|
Author-email: Agra Bima Yuda <agra@nexmedis.com>
|
|
6
6
|
License: MIT
|
|
@@ -51,15 +51,15 @@ Requires-Dist: idna>=3.10
|
|
|
51
51
|
Requires-Dist: importlib_metadata>=8.7.0
|
|
52
52
|
Requires-Dist: iniconfig>=2.1.0
|
|
53
53
|
Requires-Dist: maleo-crypto>=0.0.28
|
|
54
|
-
Requires-Dist: maleo-database>=0.1.
|
|
54
|
+
Requires-Dist: maleo-database>=0.1.42
|
|
55
55
|
Requires-Dist: maleo-enums>=0.0.28
|
|
56
|
-
Requires-Dist: maleo-google>=0.
|
|
57
|
-
Requires-Dist: maleo-infra>=0.1.
|
|
56
|
+
Requires-Dist: maleo-google>=0.1.12
|
|
57
|
+
Requires-Dist: maleo-infra>=0.1.42
|
|
58
58
|
Requires-Dist: maleo-logging>=0.0.28
|
|
59
|
-
Requires-Dist: maleo-managers>=0.0.
|
|
60
|
-
Requires-Dist: maleo-metadata>=0.3.
|
|
61
|
-
Requires-Dist: maleo-middlewares>=0.
|
|
62
|
-
Requires-Dist: maleo-schemas>=0.1.
|
|
59
|
+
Requires-Dist: maleo-managers>=0.0.92
|
|
60
|
+
Requires-Dist: maleo-metadata>=0.3.32
|
|
61
|
+
Requires-Dist: maleo-middlewares>=0.1.12
|
|
62
|
+
Requires-Dist: maleo-schemas>=0.1.42
|
|
63
63
|
Requires-Dist: maleo-types>=0.0.8
|
|
64
64
|
Requires-Dist: maleo-utils>=0.0.28
|
|
65
65
|
Requires-Dist: motor>=3.7.1
|
|
@@ -9,4 +9,11 @@ maleo_metadata_client.egg-info/top_level.txt
|
|
|
9
9
|
src/__init__.py
|
|
10
10
|
src/manager.py
|
|
11
11
|
src/services/__init__.py
|
|
12
|
-
src/services/blood_type.py
|
|
12
|
+
src/services/blood_type.py
|
|
13
|
+
src/services/gender.py
|
|
14
|
+
src/services/medical_role.py
|
|
15
|
+
src/services/medical_service.py
|
|
16
|
+
src/services/organization_type.py
|
|
17
|
+
src/services/service.py
|
|
18
|
+
src/services/system_role.py
|
|
19
|
+
src/services/user_type.py
|
|
@@ -42,15 +42,15 @@ idna>=3.10
|
|
|
42
42
|
importlib_metadata>=8.7.0
|
|
43
43
|
iniconfig>=2.1.0
|
|
44
44
|
maleo-crypto>=0.0.28
|
|
45
|
-
maleo-database>=0.1.
|
|
45
|
+
maleo-database>=0.1.42
|
|
46
46
|
maleo-enums>=0.0.28
|
|
47
|
-
maleo-google>=0.
|
|
48
|
-
maleo-infra>=0.1.
|
|
47
|
+
maleo-google>=0.1.12
|
|
48
|
+
maleo-infra>=0.1.42
|
|
49
49
|
maleo-logging>=0.0.28
|
|
50
|
-
maleo-managers>=0.0.
|
|
51
|
-
maleo-metadata>=0.3.
|
|
52
|
-
maleo-middlewares>=0.
|
|
53
|
-
maleo-schemas>=0.1.
|
|
50
|
+
maleo-managers>=0.0.92
|
|
51
|
+
maleo-metadata>=0.3.32
|
|
52
|
+
maleo-middlewares>=0.1.12
|
|
53
|
+
maleo-schemas>=0.1.42
|
|
54
54
|
maleo-types>=0.0.8
|
|
55
55
|
maleo-utils>=0.0.28
|
|
56
56
|
motor>=3.7.1
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "maleo-metadata-client" # PyPI package name
|
|
7
|
-
version = "0.0.
|
|
7
|
+
version = "0.0.8"
|
|
8
8
|
description = "MaleoMetadata client package"
|
|
9
9
|
authors = [
|
|
10
10
|
{ name = "Agra Bima Yuda", email = "agra@nexmedis.com" }
|
|
@@ -57,15 +57,15 @@ dependencies = [
|
|
|
57
57
|
"importlib_metadata>=8.7.0",
|
|
58
58
|
"iniconfig>=2.1.0",
|
|
59
59
|
"maleo-crypto>=0.0.28",
|
|
60
|
-
"maleo-database>=0.1.
|
|
60
|
+
"maleo-database>=0.1.42",
|
|
61
61
|
"maleo-enums>=0.0.28",
|
|
62
|
-
"maleo-google>=0.
|
|
63
|
-
"maleo-infra>=0.1.
|
|
62
|
+
"maleo-google>=0.1.12",
|
|
63
|
+
"maleo-infra>=0.1.42",
|
|
64
64
|
"maleo-logging>=0.0.28",
|
|
65
|
-
"maleo-managers>=0.0.
|
|
66
|
-
"maleo-metadata>=0.3.
|
|
67
|
-
"maleo-middlewares>=0.
|
|
68
|
-
"maleo-schemas>=0.1.
|
|
65
|
+
"maleo-managers>=0.0.92",
|
|
66
|
+
"maleo-metadata>=0.3.32",
|
|
67
|
+
"maleo-middlewares>=0.1.12",
|
|
68
|
+
"maleo-schemas>=0.1.42",
|
|
69
69
|
"maleo-types>=0.0.8",
|
|
70
70
|
"maleo-utils>=0.0.28",
|
|
71
71
|
"motor>=3.7.1",
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
from maleo.managers.client.maleo import MaleoClientManager
|
|
2
|
+
from maleo.managers.client.maleo.config import MaleoMetadataClientConfig
|
|
3
|
+
from .services.blood_type import BloodTypeClientService
|
|
4
|
+
from .services.gender import GenderClientService
|
|
5
|
+
from .services.medical_role import MedicalRoleClientService
|
|
6
|
+
from .services.medical_service import MedicalServiceClientService
|
|
7
|
+
from .services.organization_type import OrganizationTypeClientService
|
|
8
|
+
from .services.service import ServiceClientService
|
|
9
|
+
from .services.system_role import SystemRoleClientService
|
|
10
|
+
from .services.user_type import UserTypeClientService
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class MaleoMetadataClientManager(MaleoClientManager[MaleoMetadataClientConfig]):
|
|
14
|
+
def initalize_services(self):
|
|
15
|
+
self.blood_type = BloodTypeClientService(
|
|
16
|
+
application_context=self._application_context,
|
|
17
|
+
config=self._config,
|
|
18
|
+
logger=self._logger,
|
|
19
|
+
http_client_manager=self._http_client_manager,
|
|
20
|
+
private_key=self._private_key,
|
|
21
|
+
redis=self._redis,
|
|
22
|
+
)
|
|
23
|
+
self.gender = GenderClientService(
|
|
24
|
+
application_context=self._application_context,
|
|
25
|
+
config=self._config,
|
|
26
|
+
logger=self._logger,
|
|
27
|
+
http_client_manager=self._http_client_manager,
|
|
28
|
+
private_key=self._private_key,
|
|
29
|
+
redis=self._redis,
|
|
30
|
+
)
|
|
31
|
+
self.medical_role = MedicalRoleClientService(
|
|
32
|
+
application_context=self._application_context,
|
|
33
|
+
config=self._config,
|
|
34
|
+
logger=self._logger,
|
|
35
|
+
http_client_manager=self._http_client_manager,
|
|
36
|
+
private_key=self._private_key,
|
|
37
|
+
redis=self._redis,
|
|
38
|
+
)
|
|
39
|
+
self.medical_service = MedicalServiceClientService(
|
|
40
|
+
application_context=self._application_context,
|
|
41
|
+
config=self._config,
|
|
42
|
+
logger=self._logger,
|
|
43
|
+
http_client_manager=self._http_client_manager,
|
|
44
|
+
private_key=self._private_key,
|
|
45
|
+
redis=self._redis,
|
|
46
|
+
)
|
|
47
|
+
self.organization_type = OrganizationTypeClientService(
|
|
48
|
+
application_context=self._application_context,
|
|
49
|
+
config=self._config,
|
|
50
|
+
logger=self._logger,
|
|
51
|
+
http_client_manager=self._http_client_manager,
|
|
52
|
+
private_key=self._private_key,
|
|
53
|
+
redis=self._redis,
|
|
54
|
+
)
|
|
55
|
+
self.service = ServiceClientService(
|
|
56
|
+
application_context=self._application_context,
|
|
57
|
+
config=self._config,
|
|
58
|
+
logger=self._logger,
|
|
59
|
+
http_client_manager=self._http_client_manager,
|
|
60
|
+
private_key=self._private_key,
|
|
61
|
+
redis=self._redis,
|
|
62
|
+
)
|
|
63
|
+
self.system_role = SystemRoleClientService(
|
|
64
|
+
application_context=self._application_context,
|
|
65
|
+
config=self._config,
|
|
66
|
+
logger=self._logger,
|
|
67
|
+
http_client_manager=self._http_client_manager,
|
|
68
|
+
private_key=self._private_key,
|
|
69
|
+
redis=self._redis,
|
|
70
|
+
)
|
|
71
|
+
self.user_type = UserTypeClientService(
|
|
72
|
+
application_context=self._application_context,
|
|
73
|
+
config=self._config,
|
|
74
|
+
logger=self._logger,
|
|
75
|
+
http_client_manager=self._http_client_manager,
|
|
76
|
+
private_key=self._private_key,
|
|
77
|
+
redis=self._redis,
|
|
78
|
+
)
|
|
@@ -17,12 +17,10 @@ from maleo.metadata.schemas.blood_type import (
|
|
|
17
17
|
StandardBloodTypeSchema,
|
|
18
18
|
FullBloodTypeSchema,
|
|
19
19
|
)
|
|
20
|
-
from maleo.metadata.enums.blood_type import Granularity
|
|
20
|
+
from maleo.metadata.enums.blood_type import Granularity, IdentifierType
|
|
21
21
|
from maleo.metadata.utils.blood_type import get_schema_model
|
|
22
22
|
from maleo.schemas.connection import ConnectionContext
|
|
23
23
|
from maleo.schemas.exception.factory import Factory as MaleoExceptionFactory
|
|
24
|
-
from maleo.schemas.mixins.filter import convert as convert_filter
|
|
25
|
-
from maleo.schemas.mixins.sort import convert as convert_sort
|
|
26
24
|
from maleo.schemas.operation.action.resource import ReadResourceOperationAction
|
|
27
25
|
from maleo.schemas.operation.enums import OperationType, Target
|
|
28
26
|
from maleo.schemas.operation.mixins import Timestamp
|
|
@@ -226,30 +224,14 @@ class BloodTypeClientService(MaleoClientService[MaleoMetadataClientConfig]):
|
|
|
226
224
|
auth = None
|
|
227
225
|
|
|
228
226
|
if isinstance(parameters, ReadMultipleParameter):
|
|
229
|
-
url = f"{self._config.url}/v1/{self.resource.identifiers[
|
|
230
|
-
parameters.date_filters
|
|
231
|
-
params = parameters.model_dump(
|
|
232
|
-
mode="json",
|
|
233
|
-
include={
|
|
234
|
-
"ids",
|
|
235
|
-
"uuids",
|
|
236
|
-
"statuses",
|
|
237
|
-
"keys",
|
|
238
|
-
"names",
|
|
239
|
-
"search",
|
|
240
|
-
"page",
|
|
241
|
-
"limit",
|
|
242
|
-
"granularity",
|
|
243
|
-
"use_cache",
|
|
244
|
-
},
|
|
245
|
-
)
|
|
246
|
-
params["filters"] = convert_filter(parameters.date_filters)
|
|
247
|
-
params["sorts"] = convert_sort(parameters.sort_columns)
|
|
227
|
+
url = f"{self._config.url}/v1/{self.resource.identifiers[-1].slug}/"
|
|
248
228
|
elif isinstance(parameters, ReadSingleParameter):
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
229
|
+
if parameters.identifier is IdentifierType.ID:
|
|
230
|
+
url = f"{self._config.url}/v1/{self.resource.identifiers[-1].slug}/{parameters.value}"
|
|
231
|
+
else:
|
|
232
|
+
url = f"{self._config.url}/v1/{self.resource.identifiers[-1].slug}/{parameters.identifier}/{parameters.value}"
|
|
233
|
+
|
|
234
|
+
params = parameters.to_query_params()
|
|
253
235
|
|
|
254
236
|
response = await http_client.get(
|
|
255
237
|
url, params=params, headers=headers, auth=auth
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from copy import deepcopy
|
|
3
|
+
from datetime import datetime, timezone
|
|
4
|
+
from typing import Literal, Union, overload
|
|
5
|
+
from uuid import UUID
|
|
6
|
+
from maleo.database.enums import Connection
|
|
7
|
+
from maleo.database.utils import build_cache_key
|
|
8
|
+
from maleo.enums.cardinality import Cardinality
|
|
9
|
+
from maleo.enums.connection import Header
|
|
10
|
+
from maleo.logging.enums import Level
|
|
11
|
+
from maleo.managers.client.maleo.config import MaleoMetadataClientConfig
|
|
12
|
+
from maleo.managers.client.maleo import MaleoClientService
|
|
13
|
+
from maleo.metadata.constants.gender import GENDER_RESOURCE
|
|
14
|
+
from maleo.metadata.schemas.gender import (
|
|
15
|
+
ReadMultipleParameter,
|
|
16
|
+
ReadSingleParameter,
|
|
17
|
+
StandardGenderSchema,
|
|
18
|
+
FullGenderSchema,
|
|
19
|
+
)
|
|
20
|
+
from maleo.metadata.enums.gender import Granularity, IdentifierType
|
|
21
|
+
from maleo.metadata.utils.gender import get_schema_model
|
|
22
|
+
from maleo.schemas.connection import ConnectionContext
|
|
23
|
+
from maleo.schemas.exception.factory import Factory as MaleoExceptionFactory
|
|
24
|
+
from maleo.schemas.operation.action.resource import ReadResourceOperationAction
|
|
25
|
+
from maleo.schemas.operation.enums import OperationType, Target
|
|
26
|
+
from maleo.schemas.operation.mixins import Timestamp
|
|
27
|
+
from maleo.schemas.operation.resource import (
|
|
28
|
+
ReadMultipleResourceOperation,
|
|
29
|
+
ReadSingleResourceOperation,
|
|
30
|
+
)
|
|
31
|
+
from maleo.schemas.pagination import StrictPagination
|
|
32
|
+
from maleo.schemas.response import (
|
|
33
|
+
MultipleDataResponse,
|
|
34
|
+
ReadMultipleDataResponse,
|
|
35
|
+
SingleDataResponse,
|
|
36
|
+
ReadSingleDataResponse,
|
|
37
|
+
)
|
|
38
|
+
from maleo.schemas.security.authorization import (
|
|
39
|
+
OptionalAnyAuthorization,
|
|
40
|
+
AnyAuthorization,
|
|
41
|
+
Factory as AuthorizationFactory,
|
|
42
|
+
)
|
|
43
|
+
from maleo.schemas.security.impersonation import OptionalImpersonation
|
|
44
|
+
from maleo.types.dict import OptionalStringToStringDict
|
|
45
|
+
from maleo.utils.merger import merge_dicts
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class GenderClientService(MaleoClientService[MaleoMetadataClientConfig]):
|
|
49
|
+
resource = GENDER_RESOURCE
|
|
50
|
+
|
|
51
|
+
@overload
|
|
52
|
+
async def read(
|
|
53
|
+
self,
|
|
54
|
+
cardinality: Literal[Cardinality.MULTIPLE],
|
|
55
|
+
granularity: Literal[Granularity.STANDARD],
|
|
56
|
+
*,
|
|
57
|
+
operation_id: UUID,
|
|
58
|
+
resource_operation_action: ReadResourceOperationAction,
|
|
59
|
+
connection_context: ConnectionContext,
|
|
60
|
+
authorization: AnyAuthorization,
|
|
61
|
+
impersonation: OptionalImpersonation = None,
|
|
62
|
+
parameters: ReadMultipleParameter,
|
|
63
|
+
headers: OptionalStringToStringDict = None,
|
|
64
|
+
) -> ReadMultipleDataResponse[StandardGenderSchema, StrictPagination, None]: ...
|
|
65
|
+
@overload
|
|
66
|
+
async def read(
|
|
67
|
+
self,
|
|
68
|
+
cardinality: Literal[Cardinality.MULTIPLE],
|
|
69
|
+
granularity: Literal[Granularity.FULL],
|
|
70
|
+
*,
|
|
71
|
+
operation_id: UUID,
|
|
72
|
+
resource_operation_action: ReadResourceOperationAction,
|
|
73
|
+
connection_context: ConnectionContext,
|
|
74
|
+
authorization: AnyAuthorization,
|
|
75
|
+
impersonation: OptionalImpersonation = None,
|
|
76
|
+
parameters: ReadMultipleParameter,
|
|
77
|
+
headers: OptionalStringToStringDict = None,
|
|
78
|
+
) -> ReadMultipleDataResponse[FullGenderSchema, StrictPagination, None]: ...
|
|
79
|
+
@overload
|
|
80
|
+
async def read(
|
|
81
|
+
self,
|
|
82
|
+
cardinality: Literal[Cardinality.SINGLE],
|
|
83
|
+
granularity: Literal[Granularity.STANDARD],
|
|
84
|
+
*,
|
|
85
|
+
operation_id: UUID,
|
|
86
|
+
resource_operation_action: ReadResourceOperationAction,
|
|
87
|
+
connection_context: ConnectionContext,
|
|
88
|
+
authorization: AnyAuthorization,
|
|
89
|
+
impersonation: OptionalImpersonation = None,
|
|
90
|
+
parameters: ReadSingleParameter,
|
|
91
|
+
headers: OptionalStringToStringDict = None,
|
|
92
|
+
) -> ReadSingleDataResponse[StandardGenderSchema, None]: ...
|
|
93
|
+
@overload
|
|
94
|
+
async def read(
|
|
95
|
+
self,
|
|
96
|
+
cardinality: Literal[Cardinality.SINGLE],
|
|
97
|
+
granularity: Literal[Granularity.FULL],
|
|
98
|
+
*,
|
|
99
|
+
operation_id: UUID,
|
|
100
|
+
resource_operation_action: ReadResourceOperationAction,
|
|
101
|
+
connection_context: ConnectionContext,
|
|
102
|
+
authorization: AnyAuthorization,
|
|
103
|
+
impersonation: OptionalImpersonation = None,
|
|
104
|
+
parameters: ReadSingleParameter,
|
|
105
|
+
headers: OptionalStringToStringDict = None,
|
|
106
|
+
) -> ReadSingleDataResponse[FullGenderSchema, None]: ...
|
|
107
|
+
async def read(
|
|
108
|
+
self,
|
|
109
|
+
cardinality: Cardinality,
|
|
110
|
+
granularity: Granularity,
|
|
111
|
+
*,
|
|
112
|
+
operation_id: UUID,
|
|
113
|
+
resource_operation_action: ReadResourceOperationAction,
|
|
114
|
+
connection_context: ConnectionContext,
|
|
115
|
+
authorization: OptionalAnyAuthorization = None,
|
|
116
|
+
impersonation: OptionalImpersonation = None,
|
|
117
|
+
parameters: Union[ReadMultipleParameter, ReadSingleParameter],
|
|
118
|
+
headers: OptionalStringToStringDict = None,
|
|
119
|
+
) -> Union[
|
|
120
|
+
ReadMultipleDataResponse[StandardGenderSchema, StrictPagination, None],
|
|
121
|
+
ReadMultipleDataResponse[FullGenderSchema, StrictPagination, None],
|
|
122
|
+
ReadSingleDataResponse[StandardGenderSchema, None],
|
|
123
|
+
ReadSingleDataResponse[FullGenderSchema, None],
|
|
124
|
+
]:
|
|
125
|
+
redis_client = self._redis.manager.client.get(Connection.ASYNC)
|
|
126
|
+
data_model_cls = get_schema_model(granularity)
|
|
127
|
+
|
|
128
|
+
executed_at = datetime.now(tz=timezone.utc)
|
|
129
|
+
|
|
130
|
+
# Define arguments being used in this function
|
|
131
|
+
positional_arguments = [cardinality, granularity]
|
|
132
|
+
keyword_arguments = {
|
|
133
|
+
"authorization": (
|
|
134
|
+
authorization.model_dump(mode="json")
|
|
135
|
+
if authorization is not None
|
|
136
|
+
else None
|
|
137
|
+
),
|
|
138
|
+
"parameters": parameters.model_dump(mode="json"),
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
# Define full function string
|
|
142
|
+
ext = f"({json.dumps(positional_arguments)}|{json.dumps(keyword_arguments)})"
|
|
143
|
+
|
|
144
|
+
# Define full cache_key
|
|
145
|
+
cache_key = build_cache_key(ext, namespace=self._namespace)
|
|
146
|
+
|
|
147
|
+
if parameters.use_cache:
|
|
148
|
+
# Initialize cache operation context
|
|
149
|
+
operation_context = deepcopy(self._operation_context)
|
|
150
|
+
operation_context.target.type = Target.CACHE
|
|
151
|
+
|
|
152
|
+
redis_response_str = await redis_client.get(cache_key)
|
|
153
|
+
|
|
154
|
+
if redis_response_str is not None:
|
|
155
|
+
operation_timestamp = Timestamp.completed_now(executed_at)
|
|
156
|
+
if cardinality is Cardinality.MULTIPLE:
|
|
157
|
+
response = ReadMultipleDataResponse[
|
|
158
|
+
data_model_cls, StrictPagination, None
|
|
159
|
+
].model_validate_json(redis_response_str)
|
|
160
|
+
ReadMultipleResourceOperation[
|
|
161
|
+
data_model_cls, StrictPagination, None
|
|
162
|
+
](
|
|
163
|
+
application_context=self._application_context,
|
|
164
|
+
id=operation_id,
|
|
165
|
+
context=operation_context,
|
|
166
|
+
action=resource_operation_action,
|
|
167
|
+
resource=self.resource,
|
|
168
|
+
timestamp=operation_timestamp,
|
|
169
|
+
summary=f"Successfully retrieved {cardinality} {granularity} genders from cache",
|
|
170
|
+
connection_context=connection_context,
|
|
171
|
+
authentication=None,
|
|
172
|
+
authorization=authorization,
|
|
173
|
+
impersonation=impersonation,
|
|
174
|
+
response=response,
|
|
175
|
+
).log(
|
|
176
|
+
self._logger, Level.INFO
|
|
177
|
+
)
|
|
178
|
+
elif cardinality is Cardinality.SINGLE:
|
|
179
|
+
response = ReadSingleDataResponse[
|
|
180
|
+
data_model_cls, None
|
|
181
|
+
].model_validate_json(redis_response_str)
|
|
182
|
+
ReadSingleResourceOperation[data_model_cls, None](
|
|
183
|
+
application_context=self._application_context,
|
|
184
|
+
id=operation_id,
|
|
185
|
+
context=operation_context,
|
|
186
|
+
action=resource_operation_action,
|
|
187
|
+
resource=self.resource,
|
|
188
|
+
timestamp=operation_timestamp,
|
|
189
|
+
summary=f"Successfully retrieved {cardinality} {granularity} gender from cache",
|
|
190
|
+
connection_context=connection_context,
|
|
191
|
+
authentication=None,
|
|
192
|
+
authorization=authorization,
|
|
193
|
+
impersonation=impersonation,
|
|
194
|
+
response=response,
|
|
195
|
+
).log(self._logger, Level.INFO)
|
|
196
|
+
|
|
197
|
+
return response # type: ignore
|
|
198
|
+
|
|
199
|
+
operation_context = deepcopy(self._operation_context)
|
|
200
|
+
operation_context.target.type = Target.MICROSERVICE
|
|
201
|
+
|
|
202
|
+
async with self._http_client_manager.get() as http_client:
|
|
203
|
+
base_headers = {
|
|
204
|
+
Header.CONTENT_TYPE.value: "application/json",
|
|
205
|
+
Header.X_OPERATION_ID.value: str(operation_id),
|
|
206
|
+
}
|
|
207
|
+
if impersonation is not None:
|
|
208
|
+
base_headers[Header.X_USER_ID.value] = str(impersonation.user_id)
|
|
209
|
+
if impersonation.organization_id is not None:
|
|
210
|
+
base_headers[Header.X_ORGANIZATION_ID.value] = str(
|
|
211
|
+
impersonation.organization_id
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
if headers is not None:
|
|
215
|
+
headers = merge_dicts(base_headers, headers)
|
|
216
|
+
else:
|
|
217
|
+
headers = base_headers
|
|
218
|
+
|
|
219
|
+
if authorization is not None:
|
|
220
|
+
auth = AuthorizationFactory.httpx_auth(
|
|
221
|
+
scheme=authorization.scheme, authorization=authorization.credentials
|
|
222
|
+
)
|
|
223
|
+
else:
|
|
224
|
+
auth = None
|
|
225
|
+
|
|
226
|
+
if isinstance(parameters, ReadMultipleParameter):
|
|
227
|
+
url = f"{self._config.url}/v1/{self.resource.identifiers[-1].slug}/"
|
|
228
|
+
elif isinstance(parameters, ReadSingleParameter):
|
|
229
|
+
if parameters.identifier is IdentifierType.ID:
|
|
230
|
+
url = f"{self._config.url}/v1/{self.resource.identifiers[-1].slug}/{parameters.value}"
|
|
231
|
+
else:
|
|
232
|
+
url = f"{self._config.url}/v1/{self.resource.identifiers[-1].slug}/{parameters.identifier}/{parameters.value}"
|
|
233
|
+
|
|
234
|
+
params = parameters.to_query_params()
|
|
235
|
+
|
|
236
|
+
response = await http_client.get(
|
|
237
|
+
url, params=params, headers=headers, auth=auth
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
operation_timestamp = Timestamp.completed_now(executed_at)
|
|
241
|
+
|
|
242
|
+
if response.is_error:
|
|
243
|
+
raise MaleoExceptionFactory.from_httpx(
|
|
244
|
+
response,
|
|
245
|
+
operation_type=OperationType.REQUEST,
|
|
246
|
+
application_context=self._application_context,
|
|
247
|
+
operation_id=operation_id,
|
|
248
|
+
operation_context=operation_context,
|
|
249
|
+
operation_action=resource_operation_action,
|
|
250
|
+
operation_timestamp=operation_timestamp,
|
|
251
|
+
connection_context=connection_context,
|
|
252
|
+
authentication=None,
|
|
253
|
+
authorization=authorization,
|
|
254
|
+
impersonation=impersonation,
|
|
255
|
+
logger=self._logger,
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
if isinstance(parameters, ReadMultipleParameter):
|
|
259
|
+
validated_response = MultipleDataResponse[
|
|
260
|
+
data_model_cls, StrictPagination, None
|
|
261
|
+
].model_validate(response.json())
|
|
262
|
+
service_response = ReadMultipleDataResponse[
|
|
263
|
+
data_model_cls, StrictPagination, None
|
|
264
|
+
].new(
|
|
265
|
+
data=validated_response.data,
|
|
266
|
+
pagination=validated_response.pagination,
|
|
267
|
+
)
|
|
268
|
+
ReadMultipleResourceOperation[data_model_cls, StrictPagination, None](
|
|
269
|
+
application_context=self._application_context,
|
|
270
|
+
id=operation_id,
|
|
271
|
+
context=operation_context,
|
|
272
|
+
action=resource_operation_action,
|
|
273
|
+
resource=GENDER_RESOURCE,
|
|
274
|
+
timestamp=operation_timestamp,
|
|
275
|
+
summary=f"Successfully retrieved multiple {granularity} genders from microservice",
|
|
276
|
+
connection_context=connection_context,
|
|
277
|
+
authentication=None,
|
|
278
|
+
authorization=authorization,
|
|
279
|
+
impersonation=impersonation,
|
|
280
|
+
response=service_response,
|
|
281
|
+
).log(self._logger, Level.INFO)
|
|
282
|
+
elif isinstance(parameters, ReadSingleParameter):
|
|
283
|
+
validated_response = SingleDataResponse[
|
|
284
|
+
data_model_cls, None
|
|
285
|
+
].model_validate(response.json())
|
|
286
|
+
service_response = ReadSingleDataResponse[data_model_cls, None].new(
|
|
287
|
+
data=validated_response.data,
|
|
288
|
+
)
|
|
289
|
+
ReadSingleResourceOperation[data_model_cls, None](
|
|
290
|
+
application_context=self._application_context,
|
|
291
|
+
id=operation_id,
|
|
292
|
+
context=operation_context,
|
|
293
|
+
action=resource_operation_action,
|
|
294
|
+
resource=GENDER_RESOURCE,
|
|
295
|
+
timestamp=operation_timestamp,
|
|
296
|
+
summary=f"Successfully retrieved single {granularity} gender from microservice",
|
|
297
|
+
connection_context=connection_context,
|
|
298
|
+
authentication=None,
|
|
299
|
+
authorization=authorization,
|
|
300
|
+
impersonation=impersonation,
|
|
301
|
+
response=service_response,
|
|
302
|
+
).log(self._logger, Level.INFO)
|
|
303
|
+
|
|
304
|
+
return service_response # type: ignore
|