Lookup Service¶
lookup ¶
Parent-SDK lookup services for SHM workflows.
This module centralizes the parent SDK lookups required by SHM upload and orchestration flows while keeping transport concerns outside the workflows themselves.
Classes¶
ParentLocationsLookupClient ¶
ParentGeometryLookupClient ¶
Bases: Protocol
Protocol for parent SDK geometry lookups used by SHM services.
LookupRecord
dataclass
¶
Normalized lookup record returned by SHM services.
AssetLookupContext
dataclass
¶
Resolved lookup context for an SHM asset workflow.
ShmLookupError ¶
ProjectSiteLookupError ¶
Bases: ShmLookupError
Raised when a project site lookup cannot be resolved.
Source code in .venv/lib/python3.14/site-packages/owi/metadatabase/_utils/exceptions.py
AssetLocationLookupError ¶
Bases: ShmLookupError
Raised when an asset location lookup cannot be resolved.
Source code in .venv/lib/python3.14/site-packages/owi/metadatabase/_utils/exceptions.py
SubassembliesLookupError ¶
Bases: ShmLookupError
Raised when a subassembly lookup cannot be resolved.
Source code in .venv/lib/python3.14/site-packages/owi/metadatabase/_utils/exceptions.py
ModelDefinitionLookupError ¶
Bases: ShmLookupError
Raised when a SHM model definition cannot be derived from subassemblies.
Source code in .venv/lib/python3.14/site-packages/owi/metadatabase/_utils/exceptions.py
SignalUploadContextError ¶
Bases: ShmLookupError
Raised when parent lookup data cannot be translated into upload ids.
Source code in .venv/lib/python3.14/site-packages/owi/metadatabase/_utils/exceptions.py
ParentSDKLookupService ¶
Resolve parent-SDK lookup data for SHM workflows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
locations_client
|
ParentLocationsLookupClient
|
Parent SDK client that resolves project and asset location details. |
required |
geometry_client
|
ParentGeometryLookupClient
|
Parent SDK client that resolves geometry subassemblies. |
required |
Source code in src/owi/metadatabase/shm/lookup.py
Functions¶
get_projectsite ¶
Resolve a project site detail lookup.
Source code in src/owi/metadatabase/shm/lookup.py
get_assetlocation ¶
Resolve an asset location detail lookup.
Source code in src/owi/metadatabase/shm/lookup.py
get_subassemblies ¶
Resolve a subassembly lookup.
Source code in src/owi/metadatabase/shm/lookup.py
get_asset_context ¶
Resolve the lookup context needed for an SHM asset workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
projectsite
|
str | None
|
Parent SDK project site title. When omitted, the service derives it from the asset-location lookup data. |
required |
assetlocation
|
str
|
Parent SDK asset location title. |
required |
Returns:
| Type | Description |
|---|---|
AssetLookupContext
|
Typed lookup records plus the resolved model definition. |
Examples:
>>> from unittest.mock import Mock
>>> locations_client = Mock()
>>> geometry_client = Mock()
>>> locations_client.get_assetlocation_detail.return_value = {
... "data": pd.DataFrame([{"id": 11, "projectsite_name": "Project A"}]),
... "exists": True,
... "id": 11,
... }
>>> locations_client.get_projectsite_detail.return_value = {
... "data": pd.DataFrame([{"id": 10, "title": "Project A"}]),
... "exists": True,
... "id": 10,
... }
>>> geometry_client.get_subassemblies.return_value = {
... "data": pd.DataFrame([{"id": 40, "subassembly_type": "TP", "model_definition": "MD-01"}]),
... "exists": True,
... }
>>> geometry_client.get_modeldefinition_id.return_value = {"id": 99}
>>> service = ParentSDKLookupService(locations_client=locations_client, geometry_client=geometry_client)
>>> context = service.get_asset_context(projectsite=None, assetlocation="Asset-01")
>>> (context.site.record_id, context.asset.record_id, context.model_definition)
(10, 11, 99)
Source code in src/owi/metadatabase/shm/lookup.py
get_signal_upload_context ¶
Resolve the payload-builder context for SHM signal uploads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
projectsite
|
str | None
|
Parent SDK project site title. When omitted, the service derives it from the asset-location lookup data. |
required |
assetlocation
|
str
|
Parent SDK asset location title. |
required |
permission_group_ids
|
Sequence[int] | None
|
Visibility groups applied to created SHM records. |
None
|
Returns:
| Type | Description |
|---|---|
SignalUploadContext
|
Upload context compatible with legacy payload builders. |
Examples:
>>> from unittest.mock import Mock
>>> locations_client = Mock()
>>> geometry_client = Mock()
>>> locations_client.get_projectsite_detail.return_value = {
... "data": pd.DataFrame([{"id": 10, "title": "Project A"}]),
... "exists": True,
... "id": 10,
... }
>>> locations_client.get_assetlocation_detail.return_value = {
... "data": pd.DataFrame([{"id": 11, "title": "Asset-01"}]),
... "exists": True,
... "id": 11,
... }
>>> geometry_client.get_subassemblies.return_value = {
... "data": pd.DataFrame(
... [
... {"id": 40, "subassembly_type": "TP", "model_definition": "MD-01"},
... {"id": 41, "subassembly_type": "TW", "model_definition": "MD-01"},
... ]
... ),
... "exists": True,
... }
>>> service = ParentSDKLookupService(locations_client=locations_client, geometry_client=geometry_client)
>>> context = service.get_signal_upload_context("Project A", "Asset-01", permission_group_ids=[7])
>>> context.site_id, context.asset_location_id, context.subassembly_id_for("TP")
(10, 11, 40)
Source code in src/owi/metadatabase/shm/lookup.py
build_signal_upload_context
staticmethod
¶
Translate parent lookup records into upload payload ids.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
asset_context
|
AssetLookupContext
|
Normalized parent SDK lookup context. |
required |
permission_group_ids
|
Sequence[int] | None
|
Visibility groups applied to created SHM records. |
None
|
Returns:
| Type | Description |
|---|---|
SignalUploadContext
|
Upload context compatible with legacy payload builders. |
Raises:
| Type | Description |
|---|---|
SignalUploadContextError
|
If required parent lookup ids or subassembly columns are missing. |
Examples:
>>> asset_context = AssetLookupContext(
... site=LookupRecord(pd.DataFrame([{"id": 10}]), record_id=10),
... asset=LookupRecord(pd.DataFrame([{"id": 11}]), record_id=11),
... subassemblies=LookupRecord(
... pd.DataFrame(
... [
... {"id": 40, "subassembly_type": "TP", "model_definition": "MD-01"},
... {"id": 41, "subassembly_type": "TW", "model_definition": "MD-01"},
... ]
... )
... ),
... model_definition="MD-01",
... )
>>> upload_context = ParentSDKLookupService.build_signal_upload_context(asset_context, [3, 5])
>>> upload_context.permission_group_ids
[3, 5]
Source code in src/owi/metadatabase/shm/lookup.py
get_model_definition ¶
Resolve the model definition reference used by SHM payload builders.
The lookup prefers the transition-piece model definition present on
the subassembly rows and, when the parent geometry client exposes
get_modeldefinition_id(), upgrades a model-definition title into
the corresponding backend id.
Source code in src/owi/metadatabase/shm/lookup.py
get_transition_piece_model_definition
staticmethod
¶
Extract the transition-piece model definition from subassemblies.