Skip to content

Commit

Permalink
add delivery type validation in factory
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrOertlin committed Sep 3, 2024
1 parent c5946a4 commit cd66e45
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from cg.services.file_delivery.deliver_files_service.deliver_files_service import (
DeliverFilesService,
)
from cg.services.file_delivery.deliver_files_service.exc import DeliveryTypeNotSupported
from cg.services.file_delivery.fetch_delivery_files_tags.fetch_delivery_file_tags_service import (
FetchDeliveryFileTagsService,
)
Expand Down Expand Up @@ -98,10 +99,24 @@ def _get_sample_file_formatter(
return SampleFileConcatenationFormatter(FastqConcatenationService())
return SampleFileFormatter()

@staticmethod
def _validate_delivery_type(delivery_type: DataDelivery):
"""Check if the delivery type is supported."""
if delivery_type in [
DataDelivery.FASTQ,
DataDelivery.ANALYSIS_FILES,
DataDelivery.FASTQ_ANALYSIS,
]:
return
raise DeliveryTypeNotSupported(
f"Delivery type {delivery_type} is not supported. Supported delivery types are {DataDelivery.FASTQ}, {DataDelivery.ANALYSIS_FILES}, {DataDelivery.FASTQ_ANALYSIS}."
)

def build_delivery_service(
self, workflow: Workflow, delivery_type: DataDelivery
) -> DeliverFilesService:
"""Build a delivery service based on the workflow and delivery type."""
self._validate_delivery_type(delivery_type)
file_fetcher: FetchDeliveryFilesService = self._get_file_fetcher(delivery_type)
sample_file_formatter: SampleFileFormatter | SampleFileConcatenationFormatter = (
self._get_sample_file_formatter(workflow)
Expand Down
7 changes: 7 additions & 0 deletions cg/services/file_delivery/deliver_files_service/exc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from cg.exc import CgError


class DeliveryTypeNotSupported(CgError):
"""Raised when a delivery type is not supported."""

pass

0 comments on commit cd66e45

Please sign in to comment.