diff --git a/src/Shared/Shared/Utilities/DicomTagUtilities.cs b/src/Shared/Shared/Utilities/DicomTagUtilities.cs index e8f4a8ab3..8a2efce5e 100644 --- a/src/Shared/Shared/Utilities/DicomTagUtilities.cs +++ b/src/Shared/Shared/Utilities/DicomTagUtilities.cs @@ -14,6 +14,7 @@ * limitations under the License. */ +using System.Text.RegularExpressions; using FellowOakDicom; namespace Monai.Deploy.WorkflowManager.Shared.Utilities @@ -22,7 +23,7 @@ public static class DicomTagUtilities { public static DicomTag GetDicomTagByName(string tag) { - return DicomDictionary.Default[tag]; + return DicomDictionary.Default[tag] ?? DicomDictionary.Default[Regex.Replace(tag, @"\s+", "", RegexOptions.None, TimeSpan.FromSeconds(1))]; } public static (bool valid, IList invalidTags) DicomTagsValid(IEnumerable dicomTags) diff --git a/src/WorkflowManager/WorkflowManager/Validators/WorkflowValidator.cs b/src/WorkflowManager/WorkflowManager/Validators/WorkflowValidator.cs index 95a3d453e..4b4bc51db 100644 --- a/src/WorkflowManager/WorkflowManager/Validators/WorkflowValidator.cs +++ b/src/WorkflowManager/WorkflowManager/Validators/WorkflowValidator.cs @@ -457,7 +457,7 @@ private void ValidateEmailTask(TaskObject currentTask) if (emailsSpecified) { var emails = currentTask.Args[RecipientEmails] ?? string.Empty; - var formattedEmails = emails.Split(',').Where(e => !string.IsNullOrWhiteSpace(e.Trim())); + var formattedEmails = emails.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); if (!formattedEmails.Any()) { @@ -498,7 +498,7 @@ private void ValidateEmailTask(TaskObject currentTask) if (rolesSpecified) { var roles = currentTask.Args[RecipientRoles] ?? string.Empty; - var formattedRoles = roles.Split(',').Where(r => !string.IsNullOrWhiteSpace(r.Trim())); + var formattedRoles = roles.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); if (!formattedRoles.Any()) { @@ -514,7 +514,7 @@ private void ValidateEmailTask(TaskObject currentTask) } var metadataValues = currentTask.Args[MetadataValues] ?? string.Empty; - var formattedMetadataValues = metadataValues.Split(',').Where(m => !string.IsNullOrWhiteSpace(m.Trim())); + var formattedMetadataValues = metadataValues.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); if (!formattedMetadataValues.Any()) { @@ -522,7 +522,7 @@ private void ValidateEmailTask(TaskObject currentTask) return; } - var disallowedTags = _options.Value.DicomTagsDisallowed.Split(',').Select(t => t.Trim()); + var disallowedTags = _options.Value.DicomTagsDisallowed.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); var intersect = formattedMetadataValues.Intersect(disallowedTags); if (intersect.Any()) diff --git a/tests/UnitTests/WorkflowManager.Tests/Validators/WorkflowValidatorTests.cs b/tests/UnitTests/WorkflowManager.Tests/Validators/WorkflowValidatorTests.cs index 6bded1702..c5666e50a 100644 --- a/tests/UnitTests/WorkflowManager.Tests/Validators/WorkflowValidatorTests.cs +++ b/tests/UnitTests/WorkflowManager.Tests/Validators/WorkflowValidatorTests.cs @@ -15,6 +15,7 @@ */ using System; +using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -722,6 +723,100 @@ public async Task ValidateWorkflow_ValidatesEmptyWorkflow_ReturnsErrorsAndHasCor Assert.Contains(error4, errors); } + //"metadata_values": "Study Instance UID, Series Instance UID" + [Fact] + public async Task ValidateWorkflow_ValidateWorkflow_WithPluginArgs_ReturnsNoErrors() + { + var workflow = new Workflow + { + Name = "Workflowname1", + Description = "Workflowdesc1", + Version = "1", + InformaticsGateway = new InformaticsGateway + { + AeTitle = "aetitle", + ExportDestinations = new string[] { "oneDestination", "twoDestination", "threeDestination" } + }, + Tasks = new TaskObject[] + { + new TaskObject + { + Id = "rootTask", + Type = "router", + Description = "TestDesc", + TaskDestinations = new TaskDestination[] + { + new TaskDestination + { + Name = "EmailTask" + } + }, + ExportDestinations = new ExportDestination[] + { + new ExportDestination { Name = "oneDestination" }, + new ExportDestination { Name = "twoDestination" }, + }, + Artifacts = new ArtifactMap + { + Output = new Artifact[] + { + new Artifact + { + Name = "non_unique_artifact", + Mandatory = true, + Value = "Example Value" + } + } + } + }, + + #region SuccessfulTasksPath + + new TaskObject + { + + Id = "EmailTask", + Type = "email", + Description = "Email plugin Task 1", + Artifacts = new ArtifactMap{ Input = new Artifact[] { + new Artifact + { + Name = "ExampleArtifact", + Value = "{{ context.value.EmailTask_InvalidEmailsArg.artifact.test }}" + }, + } }, + Args = new Dictionary{ + { "metadata_values", "Study Instance UID, Series Instance UID"}, + { "workflow_name", "Workflow Name"}, + { "recipient_emails", "neil.south@blah.com"} + }, + TaskDestinations = new TaskDestination[] { + new TaskDestination + { + Name = "taskdesc2" + } + } + }, + new TaskObject + { + Id = "taskdesc2", + Type = "router", + Description = "TestDesc", + TaskDestinations = Array.Empty() + } + #endregion SuccessfulTasksPath + } + }; + + _workflowService.Setup(w => w.GetByNameAsync(It.IsAny())) + .ReturnsAsync(null, TimeSpan.FromSeconds(.1)); + + var errors = await _workflowValidator.ValidateWorkflow(workflow); + + Assert.True(errors.Count == 0); + + } + [Fact] public async Task ValidateWorkflow_ValidateWorkflow_ReturnsNoErrors() {