FileSystemRepository module (ska_db_oda.infrastructure.filesystem.repository)

This module contains implementations of the AbstractRepository class, using the filesystem as the data store.

class ska_db_oda.infrastructure.filesystem.repository.FilesystemBridge(filesystem_mapping: FilesystemMapping, base_working_dir: str | PathLike = PosixPath('/var/lib/oda'))[source]

Implementation of the Repository bridge which persists entities to a filesystem.

Entities will be stored under the following filesystem structure: /<base_working_dir>/<entity_type_dir/<entity_id>/<version>.json For example, by default version 1 of an SBDefinition with sbd_id sbi-mvp01-20200325-00001 will be stored at: /var/lib/oda/sbd/sbi-mvp01-20200325-00001/1.json

create(entity: T, is_entity_update: bool = False) T[source]

Implementation of the RepositoryBridge method.

To mimic the real database, entities are added to a list of pending transactions and only written to the filesystem when the unit of work is committed.

Parameters:

is_entity_update – True if called from any put API sbd, sbi or eb else False

See create() docstring for details

query(qry_params: QueryParams, is_status_history: bool | None = None) List[T][source]
Parameters:

is_status_history – True if the query is for status history else False

read(entity_id: U, version: U | None = None, is_status_history: bool | None = None) T[source]

Gets the latest version of the entity with the given entity_id.

As this method will always be accessed in the context of a UnitOfWork, the pending transactions also need to be checked for a version to return. (Similar to with a database implementation where an entity that was added to a transaction but not committed would still be accessible inside the transaction.)

read_relationship(entity_id: U, parent_entity: U, associated_entity: U) T[source]

Gets the latest version of the associated entity with the given parent entity entity_id. This is used for join relationships. :param entity_id: entity id for search. :param parent_entity: primary entity for join relationship. :param associated_entity: secondary entity for join relationship. Return list of entity data based on relationship.

update(entity: T) T[source]

Implementation of the RepositoryBridge method.

To mimic the real database, entities are added to a list of pending transactions and only written to the filesystem when the unit of work is committed.

See update() docstring for details

class ska_db_oda.infrastructure.filesystem.repository.QueryFilterFactory[source]

Factory class that returns a list of Python functions equivalent to a user query. Each function processes an entity, returning True if the entity passes the query test.

static filter_between_dates(query: DateQuery)[source]

Returns a function that returns True if a date is between a given range.

static match_editor(query: UserQuery)[source]

Returns a function that returns True if a document editor matches a (sub)string.