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) 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 create() docstring for details

query(qry_params: QueryParams) List[U][source]

Queries the latest version of the entity based on QueryParams class from the ODA and returns the corresponding entity ID

Returns an empty list if no entities in the repository match the parameters.

Raises:
  • ValueError – if the qry_params are not supported

  • OSError – if an error occurs while querying the entity

read(entity_id: U) 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.)

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.