Skip to content

Commit

Permalink
Merge pull request #833 from Project-MONAI/AC-2258
Browse files Browse the repository at this point in the history
fixing email validation
  • Loading branch information
neildsouth authored Jun 7, 2023
2 parents 4db093d + dc10561 commit e3daeb7
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/Shared/Shared/Utilities/DicomTagUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

using System.Text.RegularExpressions;
using FellowOakDicom;

namespace Monai.Deploy.WorkflowManager.Shared.Utilities
Expand All @@ -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<string> invalidTags) DicomTagsValid(IEnumerable<string> dicomTags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down Expand Up @@ -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())
{
Expand All @@ -514,15 +514,15 @@ 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())
{
Errors.Add($"Argument '{MetadataValues}' for task {currentTask.Id} must be a comma seperated list of DICOM metadata tag names.");
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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
Expand Down Expand Up @@ -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<string, string>{
{ "metadata_values", "Study Instance UID, Series Instance UID"},
{ "workflow_name", "Workflow Name"},
{ "recipient_emails", "[email protected]"}
},
TaskDestinations = new TaskDestination[] {
new TaskDestination
{
Name = "taskdesc2"
}
}
},
new TaskObject
{
Id = "taskdesc2",
Type = "router",
Description = "TestDesc",
TaskDestinations = Array.Empty<TaskDestination>()
}
#endregion SuccessfulTasksPath
}
};

_workflowService.Setup(w => w.GetByNameAsync(It.IsAny<string>()))
.ReturnsAsync(null, TimeSpan.FromSeconds(.1));

var errors = await _workflowValidator.ValidateWorkflow(workflow);

Assert.True(errors.Count == 0);

}

[Fact]
public async Task ValidateWorkflow_ValidateWorkflow_ReturnsNoErrors()
{
Expand Down

0 comments on commit e3daeb7

Please sign in to comment.