diff --git a/cg/services/file_delivery/deliver_files_service/deliver_files_service_factory.py b/cg/services/file_delivery/deliver_files_service/deliver_files_service_factory.py index d57bc0464e..60f4192c7b 100644 --- a/cg/services/file_delivery/deliver_files_service/deliver_files_service_factory.py +++ b/cg/services/file_delivery/deliver_files_service/deliver_files_service_factory.py @@ -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, ) @@ -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) diff --git a/cg/services/file_delivery/deliver_files_service/exc.py b/cg/services/file_delivery/deliver_files_service/exc.py new file mode 100644 index 0000000000..2a64a4c0e4 --- /dev/null +++ b/cg/services/file_delivery/deliver_files_service/exc.py @@ -0,0 +1,7 @@ +from cg.exc import CgError + + +class DeliveryTypeNotSupported(CgError): + """Raised when a delivery type is not supported.""" + + pass