Repository module (ska_db_oda.repository)
Repository package for ODA database access, organized by database schema.
Schemas: - project: Projects and SB Definitions - execution: SB Instances and Execution Blocks - proposal: Proposals, Panels, Reviews, Decisions, and Access - common: Cross-schema operations
- class ska_db_oda.repository.AbstractRepository(conn)[source]
Define the interface for users to add and retrieve entities from the ODA.
It is expected to be extended as SBDefinitionRepository, SBInstanceRepository, etc.
- add(entity, user=None)[source]
Store the entity in the ODA.
- Raises:
ODAError – if an error occurs while persisting the entity
- Return type:
TypeVar(T)- Returns:
the entity as it exists in the ODA, eg with updated metadata
- get(entity_id)[source]
Retrieve the latest version of the entity with the given id from the ODA.
- Parameters:
entity_id (
TypeVar(U)) – entity_id of the entity.- Raises:
ODANotFound – if the entity_id is not found in the database
ODAError – if an error occurs while retrieving the entity
- Return type:
TypeVar(T)
- get_relationship(entity_id, parent_entity, associated_entity)[source]
Retrieve the entity data associated with the given parent entity ID from the ODA.
- Raises:
ODANotFound – if the sbd_id is not found in the repository
ODAError – if an error occurs while retrieving the SBD
- Parameters:
entity_id (
TypeVar(U)) – entity id to be search.parent_entity (
TypeVar(U)) – primary entity name to be join.associated_entity (
TypeVar(U)) – secondary entity name to be join.
- Return type:
TypeVar(T)
- query(qry_param)[source]
Query the latest version of the entity based on QueryParams class from the ODA.
Returns the corresponding entities. Returns an empty list if no entities in the repository match the parameters.
- Raises:
ValueError – if the qry_params are not supported
ODAError – if an error occurs while querying the entity
- Return type:
list[TypeVar(T)]
- class ska_db_oda.repository.EntityRelationshipRepository(conn)[source]
Abstraction over persistent storage of Relational Entities.
- class ska_db_oda.repository.ExecutionBlockRepository(conn)[source]
Abstraction over persistent storage of OSOExecutionBlocks.
- class ska_db_oda.repository.PanelDecisionRepository(conn)[source]
Abstraction over persistent storage of PanelDecisions.
- class ska_db_oda.repository.PanelRepository(conn)[source]
Abstraction over persistent storage of PM Panels.
- class ska_db_oda.repository.PanelReviewRepository(conn)[source]
Abstraction over persistent storage of PanelReviews.
- class ska_db_oda.repository.ProjectRepository(conn)[source]
Abstraction over persistent storage of Projects.
The add() method cascades to save any obs_blocks on the Project. The get() method resolves children by joining with observing_blocks and sb_definitions tables to return the full Project with obs_blocks containing their sbd_ids.
- add(entity, user=None)[source]
Store the Project and any obs_blocks in the ODA.
First upserts the Project, then upserts each ObservingBlock from entity.obs_blocks with the project’s prj_id as the foreign key. :type entity:
Project:param entity: The Project to store :type user:Optional[str] :param user: The user performing the operation :raises ODAError: if an error occurs while persisting :rtype:Project:return: The Project with resolved obs_blocks from the database
- add_observing_blocks(prj_id, observing_blocks, user=None)[source]
Store ObservingBlocks in the ODA with a reference to the prj_id.
NOTE: The relationship between SBD -> OB is stored in the sb_definitions table. This method will ignore any sbd_ids passed in the observing_blocks rather than update relationships. To add an SBDefinition to an ObservingBlock, use the SBDefinitionRepository.add method, including the ob_ref in the SBDefinition. :type observing_blocks:
list[ObservingBlock] :param observing_blocks: The ObservingBlocks that should be stored in the Project :type user:Optional[str] :param user: The user performing the operation :raises ODAError: if an error occurs while persisting :rtype:Project:return: The full Project with resolved obs_blocks from the database
- delete_observing_block(prj_id, ob_id)[source]
Delete an ObservingBlock and all its child SBDefinitions.
This operation will cascade delete all SBDefinitions that belong to the ObservingBlock. However, it will fail if any of those SBDefinitions have SBInstances referencing them.
- Parameters:
prj_id (
str) – The Project ID that owns the ObservingBlockob_id (
str) – The ObservingBlock ID to delete
- Raises:
ODANotFound – If the ObservingBlock is not found
ODAIntegrityError – If the OB doesn’t belong to the project, or if any SBDefinitions have SBInstances referencing them
- Return type:
None
- get(entity_id)[source]
Retrieve the Project with resolved obs_blocks and sbd_ids.
Fetches the project and resolves all child observing_blocks, populating observing_block with its list of sbd_ids from the sb_definitions table. :type entity_id:
str:param entity_id: The project ID (prj_id) :raises ODANotFound: if the project is not found :rtype:Project:return: Project with fully resolved obs_blocks containing sbd_ids
- class ska_db_oda.repository.ProposalAccessRepository(conn)[source]
Abstraction over persistent storage of Proposal Access.
- class ska_db_oda.repository.ProposalRepository(conn)[source]
Abstraction over persistent storage of Proposals.
- class ska_db_oda.repository.SBDefinitionRepository(conn)[source]
Abstraction over persistent storage of SBDefinitions.
Extends AbstractVersionedRepository to support retrieving specific historical versions of SBDefinitions via the get_version() method.
- delete(sbd_id)[source]
Delete an SBDefinition by its identifier.
This operation will fail if any SBInstances reference this SBDefinition.
- Parameters:
sbd_id (
str) – The SBDefinition ID to delete- Raises:
ODANotFound – If the sbd_id is not found in the database
ODAIntegrityError – If SBInstances reference this SBDefinition
- Return type:
None
- class ska_db_oda.repository.SBInstanceRepository(conn)[source]
Abstraction over persistent storage of SBInstances.
- class ska_db_oda.repository.StatusRepository(connection)[source]
Status repository for managing entity status tracking and history.
- get_activity_dashboard_data(qry_params)[source]
Retrieve hierarchical project data for activity dashboard.
This method queries projects with filters, retrieves related SB definitions, instances, and execution blocks, maps internal status values to public labels, and returns raw query data (transformation happens in REST layer).
- Parameters:
qry_params (
QueryParams) – QueryParams object containing filter criteria (purpose, user, dates, etc.)- Return type:
tuple- Returns:
Tuple of (projects, sbds, sbis, ebs) lists with mapped status labels. Returns empty lists if no projects match the filters.
- get_current_status(entity_id)[source]
Retrieve current status for an entity.
- Parameters:
entity_id (
str) – SKUID of the entity- Return type:
Status- Returns:
Current status of the entity
- Raises:
ODANotFound – If entity has no current status
- get_status_history(qry_params)[source]
Query status history using repository pattern.
- Parameters:
qry_params (
QueryParams) – QueryParams object (must be StatusHistoryQuery)- Return type:
list[Status]- Returns:
List of status entities matching the query
- Raises:
QueryParameterError – If qry_params is not a StatusHistoryQuery
- mark_project_draft(project_id, updated_by)[source]
Flag all of the SBDs belonging to this project as NEW (Draft).
This marks SBDs directly because it’s the inverse/undo of mark_project_ready()
- Param:
project_id: SKUID for the project.
- Param:
updated_by: User ID of someone performing the update.
- Raises:
ODAError – If something goes wrong.
- Return type:
None
- mark_project_ready(project_id, updated_by)[source]
Flag all of the SBDs belonging to this project as APPROVED.
We mark the SBDs rather than the project directly so that if any new SBDs are created later, they won’t inherit an APPROVED status from their grandparent project. The status will bubble up and make the derived status of project APPROVED.
- Param:
project_id: SKUID for the project.
- Param:
updated_by: User ID of someone performing the update.
- Raises:
ODAError – If something goes wrong.
- Return type:
None
- update_status(entity_id, status, updated_by)[source]
Update status for an entity using raw SQL query with entity type mapping.
- Parameters:
entity_id (
str) – SKUID of the entity to updatestatus (
str) – New status value (public label)updated_by (
str) – Username of the user updating the status
- Return type:
Status- Returns:
Updated status entity
- Raises:
ODAError – If status update fails
KeyError – If status is not a valid public label