Skip to content

Core Models

Models used by core_engine

Models for parametersied pipeline execution - also used by API service

SubmissionInfo

Bases: AuditRecord

Submission metadata

Source code in src/dve/core_engine/models.py
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
class SubmissionInfo(AuditRecord):
    """Submission metadata"""

    dataset_id: str
    """The dataset that the submission relates to."""
    file_name: str
    """The name of the submitted file."""
    file_extension: str
    """The extension of the file received."""
    submission_method: Optional[str] = None  # type: ignore
    """The method that the file was submitted"""
    submitting_org: Optional[str] = None  # type: ignore
    """The organisation who submitted the file."""
    reporting_period_start: Optional[str] = None  # type: ignore
    """The start of the reporting period the submission relates to."""
    reporting_period_end: Optional[str] = None  # type: ignore
    """The end of the reporting period the submission relates to."""
    file_size: Optional[int] = None  # type: ignore
    """The size (in bytes) of the file received."""
    datetime_received: Optional[dt.datetime] = None  # type: ignore
    """The datetime the file was received."""

    @field_validator("file_extension")
    def _ensure_just_file_stem(
        cls, extension: str, info: ValidationInfo  # pylint: disable=W0613
    ):  # pylint: disable=no-self-argument
        return extension.rsplit(".", 1)[-1]

    @property
    def file_name_with_ext(self):
        """Return file name with extension."""
        if self.file_extension:
            return f"{self.file_name}.{self.file_extension}"
        return self.file_name

    @classmethod
    def from_metadata_file(cls, submission_id: str, metadata_uri: Location):
        """Create a submission metadata instance from DVE metadata file."""
        metadata_uri = resolve_location(metadata_uri)
        with open_stream(metadata_uri, "r", "utf-8") as stream:
            try:
                metadata_dict: dict[str, Any] = json.load(stream)
            except json.JSONDecodeError as exc:
                raise ValueError(f"File found at {metadata_uri!r} is not valid JSON") from exc

        if isinstance(metadata_dict, list):
            raise ValueError(f"File found at {metadata_uri!r} is not a JSON mapping")

        if not metadata_dict.get("file_name"):
            metadata_dict["file_name"] = get_file_stem(metadata_uri)

        return cls(submission_id=submission_id, **metadata_dict)

    def __eq__(self, other: object) -> bool:
        if not isinstance(other, SubmissionInfo):
            raise NotImplementedError("Unable to determine equality if not a SubmissionInfo object")
        _exclude = ["date_updated", "time_updated"]
        return {k: v for k, v in self.model_dump().items() if k not in _exclude} == {
            k: v for k, v in other.model_dump().items() if k not in _exclude
        }

dataset_id instance-attribute

The dataset that the submission relates to.

datetime_received = None class-attribute instance-attribute

The datetime the file was received.

file_extension instance-attribute

The extension of the file received.

file_name instance-attribute

The name of the submitted file.

file_name_with_ext property

Return file name with extension.

file_size = None class-attribute instance-attribute

The size (in bytes) of the file received.

reporting_period_end = None class-attribute instance-attribute

The end of the reporting period the submission relates to.

reporting_period_start = None class-attribute instance-attribute

The start of the reporting period the submission relates to.

submission_method = None class-attribute instance-attribute

The method that the file was submitted

submitting_org = None class-attribute instance-attribute

The organisation who submitted the file.

from_metadata_file(submission_id, metadata_uri) classmethod

Create a submission metadata instance from DVE metadata file.

Source code in src/dve/core_engine/models.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
@classmethod
def from_metadata_file(cls, submission_id: str, metadata_uri: Location):
    """Create a submission metadata instance from DVE metadata file."""
    metadata_uri = resolve_location(metadata_uri)
    with open_stream(metadata_uri, "r", "utf-8") as stream:
        try:
            metadata_dict: dict[str, Any] = json.load(stream)
        except json.JSONDecodeError as exc:
            raise ValueError(f"File found at {metadata_uri!r} is not valid JSON") from exc

    if isinstance(metadata_dict, list):
        raise ValueError(f"File found at {metadata_uri!r} is not a JSON mapping")

    if not metadata_dict.get("file_name"):
        metadata_dict["file_name"] = get_file_stem(metadata_uri)

    return cls(submission_id=submission_id, **metadata_dict)