Data Transfer Objects (DTOs)¶
Application Layer - DTOs Package.
This package contains Data Transfer Objects (DTOs) used for transferring data between different layers of the application while maintaining loose coupling.
Modules¶
- Upload Result DTO: Result of file upload operations
- Validation Result DTO: Result of data validation operations
- Merged Data DTO: Merged data from multiple databases
- Processing Progress DTO: Progress tracking information
Package Overview¶
Data Transfer Objects (DTOs) Module.
This module contains immutable data transfer objects that encapsulate data crossing layer boundaries. DTOs prevent tight coupling between layers and provide clear contracts for data exchange.
Classes:
| Name | Description |
|---|---|
UploadResultDTO | Encapsulates upload operation results with validation status |
ValidationResultDTO | Contains validation results with detailed error messages |
MergedDataDTO | Represents merged data results from database integration |
ProcessingProgressDTO | Encapsulates processing progress information |
Notes
All DTOs are immutable frozen dataclasses to ensure data integrity across layer boundaries. They contain only data, no business logic.
UploadResultDTO¶
UploadResultDTO dataclass ¶
UploadResultDTO(success: bool, dataset: Optional[Dataset], filename: str, sample_count: int, ko_count: int, message: str, errors: Optional[list[str]] = None)
Immutable DTO for upload operation results.
Encapsulates all relevant information from a file upload operation, including success status, parsed dataset, and metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
success | bool | Whether the upload operation succeeded | required |
dataset | Optional[Dataset] | The parsed dataset entity (None if upload failed) | required |
filename | str | Name of the uploaded file | required |
sample_count | int | Number of samples parsed | required |
ko_count | int | Total number of KOs across all samples | required |
message | str | User-friendly message about the upload result | required |
errors | Optional[list[str]] | List of validation or parsing errors (None if no errors) | None |
Attributes:
| Name | Type | Description |
|---|---|---|
success | bool | Upload success status |
dataset | Optional[Dataset] | Parsed dataset or None |
filename | str | Uploaded filename |
sample_count | int | Sample count |
ko_count | int | KO count |
message | str | Result message |
errors | Optional[list[str]] | Error messages if any |
Notes
- This DTO is immutable (frozen) to ensure data integrity
- All validation should occur before DTO creation
Functions¶
__post_init__ ¶
Validate DTO consistency after initialization.
Raises:
| Type | Description |
|---|---|
ValueError | If success=True but dataset is None, or if counts are negative |
Notes
This method is called automatically by dataclass after init. It ensures logical consistency of the DTO state.
Source code in src/application/dto/upload_result_dto.py
has_errors ¶
Check if upload had any errors.
Returns:
| Type | Description |
|---|---|
bool | True if errors list is not empty, False otherwise |
MergedDataDTO¶
MergedDataDTO dataclass ¶
MergedDataDTO(biorempp_data: DataFrame, hadeg_data: Optional[DataFrame], toxcsm_data: Optional[DataFrame], match_count: int, total_records: int, cache_key: str, processing_time_seconds: float = 0.0)
Immutable DTO for database merge operation results.
Encapsulates merged data from BioRemPP, HADEG, and ToxCSM databases along with metadata about the merge operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
biorempp_data | DataFrame | Data merged with BioRemPP database | required |
hadeg_data | Optional[DataFrame] | Data merged with HADEG database (None if not merged) | required |
toxcsm_data | Optional[DataFrame] | Data merged with ToxCSM database (None if not merged) | required |
match_count | int | Number of successful matches across all databases | required |
total_records | int | Total number of input records processed | required |
cache_key | str | Cache key for storing/retrieving this merge result | required |
processing_time_seconds | float | Time taken for merge operation in seconds | 0.0 |
Attributes:
| Name | Type | Description |
|---|---|---|
biorempp_data | DataFrame | BioRemPP merged data |
hadeg_data | Optional[DataFrame] | HADEG merged data |
toxcsm_data | Optional[DataFrame] | ToxCSM merged data |
match_count | int | Match count |
total_records | int | Total records |
cache_key | str | Cache key |
processing_time_seconds | float | Processing time |
Notes
- This DTO is immutable (frozen)
- DataFrames should be copied before modification to maintain immutability
Functions¶
__post_init__ ¶
Validate DTO consistency.
Raises:
| Type | Description |
|---|---|
ValueError | If counts are negative or match_count > total_records |
TypeError | If biorempp_data is not a DataFrame |
Source code in src/application/dto/merged_data_dto.py
match_rate ¶
Calculate match rate percentage.
Returns:
| Type | Description |
|---|---|
float | Percentage of records matched (0.0 to 100.0) |
Source code in src/application/dto/merged_data_dto.py
has_hadeg_data ¶
Check if HADEG data is available.
Returns:
| Type | Description |
|---|---|
bool | True if HADEG data exists |
has_toxcsm_data ¶
Check if ToxCSM data is available.
Returns:
| Type | Description |
|---|---|
bool | True if ToxCSM data exists |
ProcessingProgressDTO¶
ProcessingProgressDTO dataclass ¶
ProcessingProgressDTO(current_stage: str, stage_number: int, total_stages: int, progress_percentage: float, message: str = '', estimated_time_remaining: Optional[float] = None, error: Optional[str] = None)
Deprecated Immutable DTO for processing progress information.
Functions¶
__post_init__ ¶
Validate DTO consistency.
Raises:
| Type | Description |
|---|---|
ValueError | If stage numbers invalid or percentage out of range |
Source code in src/application/dto/processing_progress_dto.py
is_complete ¶
Check if processing is complete.
Returns:
| Type | Description |
|---|---|
bool | True if progress is 100% |
has_error ¶
Check if processing has error.
Returns:
| Type | Description |
|---|---|
bool | True if error exists |
is_final_stage ¶
Check if currently on final stage.
Returns:
| Type | Description |
|---|---|
bool | True if on last stage |
ValidationResultDTO¶
ValidationResultDTO dataclass ¶
ValidationResultDTO(is_valid: bool, errors: Optional[list[str]], warnings: Optional[list[str]], validated_items: int, message: str = '')
Immutable DTO for validation operation results.
Encapsulates validation outcomes including success status, error messages, warnings, and metadata about validated items.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
is_valid | bool | Whether validation passed (no errors) | required |
errors | Optional[list[str]] | List of validation error messages (None if no errors) | required |
warnings | Optional[list[str]] | List of validation warnings (None if no warnings) | required |
validated_items | int | Number of items validated | required |
message | str | Summary message about validation result | "" |
Attributes:
| Name | Type | Description |
|---|---|---|
is_valid | bool | Validation success status |
errors | Optional[list[str]] | Error messages |
warnings | Optional[list[str]] | Warning messages |
validated_items | int | Count of validated items |
message | str | Summary message |
Notes
- This DTO is immutable (frozen) to ensure data integrity
- Errors prevent processing, warnings allow processing but flag issues
Functions¶
__post_init__ ¶
Validate DTO consistency.
Raises:
| Type | Description |
|---|---|
ValueError | If is_valid=False but no errors, or validated_items is negative |
Source code in src/application/dto/validation_result_dto.py
has_errors ¶
Check if validation has errors.
Returns:
| Type | Description |
|---|---|
bool | True if errors exist |
has_warnings ¶
Check if validation has warnings.
Returns:
| Type | Description |
|---|---|
bool | True if warnings exist |
error_count ¶
Get count of errors.
Returns:
| Type | Description |
|---|---|
int | Number of errors |
warning_count ¶
Get count of warnings.
Returns:
| Type | Description |
|---|---|
int | Number of warnings |