From 9e318f22797cad9e93d8e0d35cc80b181ab33445 Mon Sep 17 00:00:00 2001 From: Ruairidh MacLeod Date: Mon, 7 Oct 2024 14:25:21 +0100 Subject: [PATCH] remove opaque ObjectFactory nonsense in favour of ProjectPathResolverFactory --- data/microserviceConfigs/default.yaml | 2 +- docs/config.yaml | 2 +- .../CohortExtractor/CohortExtractorHost.cs | 3 +-- .../ProjectPathResolverFactory.cs | 17 +++++++++++++++++ .../NoSuffixProjectPathResolverTests.cs | 8 -------- tests/SmiServices.UnitTests/default.yaml | 2 +- 6 files changed, 21 insertions(+), 13 deletions(-) create mode 100644 src/SmiServices/Microservices/CohortExtractor/ProjectPathResolvers/ProjectPathResolverFactory.cs diff --git a/data/microserviceConfigs/default.yaml b/data/microserviceConfigs/default.yaml index 71b653c78..78e8417c1 100644 --- a/data/microserviceConfigs/default.yaml +++ b/data/microserviceConfigs/default.yaml @@ -77,7 +77,7 @@ CohortExtractorOptions: AuditorType: "SmiServices.Microservices.CohortExtractor.Audit.NullAuditExtractions" RequestFulfillerType: "SmiServices.Microservices.CohortExtractor.RequestFulfillers.FromCataloguesExtractionRequestFulfiller" - ProjectPathResolverType: "SmiServices.Microservices.CohortExtractor.ProjectPathResolvers.StudySeriesSOPProjectPathResolver" + ProjectPathResolverType: "StudySeriesSOPProjectPathResolver" ExtractAnonRoutingKey: anon ExtractIdentRoutingKey: ident # Writes (Producer) to this exchange diff --git a/docs/config.yaml b/docs/config.yaml index 0a0c6aebd..d1712412c 100644 --- a/docs/config.yaml +++ b/docs/config.yaml @@ -77,7 +77,7 @@ CohortExtractorOptions: AuditorType: "Microservices.CohortExtractor.Audit.NullAuditExtractions" RequestFulfillerType: "Microservices.CohortExtractor.Execution.RequestFulfillers.FromCataloguesExtractionRequestFulfiller" - ProjectPathResolverType: "Microservices.CohortExtractor.Execution.ProjectPathResolvers.StudySeriesSOPProjectPathResolver" + ProjectPathResolverType: "StudySeriesSOPProjectPathResolver" ExtractAnonRoutingKey: anon ExtractIdentRoutingKey: ident # Writes (Producer) to this exchange diff --git a/src/SmiServices/Microservices/CohortExtractor/CohortExtractorHost.cs b/src/SmiServices/Microservices/CohortExtractor/CohortExtractorHost.cs index b4b1ae248..38b53cf39 100644 --- a/src/SmiServices/Microservices/CohortExtractor/CohortExtractorHost.cs +++ b/src/SmiServices/Microservices/CohortExtractor/CohortExtractorHost.cs @@ -162,8 +162,7 @@ private void InitializeExtractionSources(IRDMPPlatformRepositoryServiceLocator r _pathResolver = string.IsNullOrWhiteSpace(_consumerOptions.ProjectPathResolverType) ? new StudySeriesSOPProjectPathResolver(_fileSystem) - : ObjectFactory.CreateInstance( - _consumerOptions.ProjectPathResolverType, typeof(IProjectPathResolver).Assembly, repositoryLocator); + : ProjectPathResolverFactory.Create(_consumerOptions.ProjectPathResolverType, _fileSystem); } } } diff --git a/src/SmiServices/Microservices/CohortExtractor/ProjectPathResolvers/ProjectPathResolverFactory.cs b/src/SmiServices/Microservices/CohortExtractor/ProjectPathResolvers/ProjectPathResolverFactory.cs new file mode 100644 index 000000000..77510bd33 --- /dev/null +++ b/src/SmiServices/Microservices/CohortExtractor/ProjectPathResolvers/ProjectPathResolverFactory.cs @@ -0,0 +1,17 @@ +using System; +using System.IO.Abstractions; + +namespace SmiServices.Microservices.CohortExtractor.ProjectPathResolvers; +internal class ProjectPathResolverFactory +{ + public static IProjectPathResolver Create(string projectPathResolverType, IFileSystem fileSystem) + { + return projectPathResolverType switch + { + "StudySeriesSOPProjectPathResolver" => new StudySeriesSOPProjectPathResolver(fileSystem), + "NoSuffixProjectPathResolver" => new NoSuffixProjectPathResolver(fileSystem), + "StudySeriesOriginalFilenameProjectPathResolver" => new StudySeriesOriginalFilenameProjectPathResolver(fileSystem), + _ => throw new NotImplementedException($"No case for IProjectPathResolver type '{projectPathResolverType}'"), + }; + } +} diff --git a/tests/SmiServices.UnitTests/Microservices/CohortExtractor/NoSuffixProjectPathResolverTests.cs b/tests/SmiServices.UnitTests/Microservices/CohortExtractor/NoSuffixProjectPathResolverTests.cs index 3e2d57446..272f2f65f 100644 --- a/tests/SmiServices.UnitTests/Microservices/CohortExtractor/NoSuffixProjectPathResolverTests.cs +++ b/tests/SmiServices.UnitTests/Microservices/CohortExtractor/NoSuffixProjectPathResolverTests.cs @@ -1,5 +1,4 @@ using NUnit.Framework; -using SmiServices.Common.Helpers; using SmiServices.Common.Messages.Extraction; using SmiServices.Microservices.CohortExtractor.ProjectPathResolvers; using SmiServices.Microservices.CohortExtractor.RequestFulfillers; @@ -73,12 +72,5 @@ public void GetOutputPath_Extensions(string expectedOutput, string inputFile) Assert.That(actualPath, Is.EqualTo(expectedPath)); } - - [Test] - public void CanBeConstructedByReflection() - { - var instance = new MicroserviceObjectFactory().CreateInstance("SmiServices.Microservices.CohortExtractor.ProjectPathResolvers.NoSuffixProjectPathResolver", typeof(IProjectPathResolver).Assembly, _fileSystem); - Assert.That(instance, Is.InstanceOf()); - } } } diff --git a/tests/SmiServices.UnitTests/default.yaml b/tests/SmiServices.UnitTests/default.yaml index 71b653c78..78e8417c1 100644 --- a/tests/SmiServices.UnitTests/default.yaml +++ b/tests/SmiServices.UnitTests/default.yaml @@ -77,7 +77,7 @@ CohortExtractorOptions: AuditorType: "SmiServices.Microservices.CohortExtractor.Audit.NullAuditExtractions" RequestFulfillerType: "SmiServices.Microservices.CohortExtractor.RequestFulfillers.FromCataloguesExtractionRequestFulfiller" - ProjectPathResolverType: "SmiServices.Microservices.CohortExtractor.ProjectPathResolvers.StudySeriesSOPProjectPathResolver" + ProjectPathResolverType: "StudySeriesSOPProjectPathResolver" ExtractAnonRoutingKey: anon ExtractIdentRoutingKey: ident # Writes (Producer) to this exchange