Skip to content

Commit 1a1703b

Browse files
committed
fix bug where workflow is empty in the workflow request message
1 parent 5047289 commit 1a1703b

File tree

8 files changed

+232
-14
lines changed

8 files changed

+232
-14
lines changed

src/Api/Storage/Payload.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// limitations under the License.
1111

1212
using Ardalis.GuardClauses;
13+
using Monai.Deploy.InformaticsGateway.Common;
1314
using System;
1415
using System.Collections.Generic;
1516
using System.Diagnostics;
@@ -61,13 +62,7 @@ public enum PayloadState
6162

6263
public int Count { get => _fileCount; }
6364

64-
public IEnumerable<string> Workflows
65-
{
66-
get
67-
{
68-
return Files.SelectMany(x => x.Workflows).Distinct();
69-
}
70-
}
65+
public ISet<string> Workflows { get; private set; }
7166

7267
public string CorrelationId { get; init; }
7368

@@ -87,6 +82,7 @@ public Payload(string key, string correlationId, uint timeout)
8782
State = PayloadState.Created;
8883
Files = new List<FileStorageInfo>();
8984
UploadedFiles = new List<BlockStorageInfo>();
85+
Workflows = new HashSet<string>();
9086
}
9187

9288
public void Add(FileStorageInfo value)
@@ -98,6 +94,15 @@ public void Add(FileStorageInfo value)
9894
_lastReceived.Start();
9995
_fileCount = Files.Count;
10096

97+
if (!value.Workflows.IsNullOrEmpty())
98+
{
99+
foreach (var workflow in value.Workflows)
100+
{
101+
102+
Workflows.Add(workflow);
103+
}
104+
}
105+
101106
if (Files.Count == 1)
102107
{
103108
DateTimeCreated = value.Received;

src/Database/Migrations/20220211175051_R1_Patch.Designer.cs

Lines changed: 170 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Microsoft.EntityFrameworkCore.Migrations;
2+
3+
#nullable disable
4+
5+
namespace Monai.Deploy.InformaticsGateway.Database.Migrations
6+
{
7+
public partial class R1_Patch : Migration
8+
{
9+
protected override void Up(MigrationBuilder migrationBuilder)
10+
{
11+
migrationBuilder.AddColumn<string>(
12+
name: "Workflows",
13+
table: "Payload",
14+
type: "TEXT",
15+
nullable: true);
16+
}
17+
18+
protected override void Down(MigrationBuilder migrationBuilder)
19+
{
20+
migrationBuilder.DropColumn(
21+
name: "Workflows",
22+
table: "Payload");
23+
}
24+
}
25+
}

src/Database/Migrations/InformaticsGatewayContextModelSnapshot.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
155155
b.Property<string>("UploadedFiles")
156156
.HasColumnType("TEXT");
157157

158+
b.Property<string>("Workflows")
159+
.HasColumnType("TEXT");
160+
158161
b.HasKey("Id");
159162

160163
b.ToTable("Payload");

src/Database/PayloadConfiguration.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public void Configure(EntityTypeBuilder<Payload> builder)
3333
(c1, c2) => c1.SequenceEqual(c2),
3434
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())),
3535
c => c.ToList());
36+
var workflowComparer = new ValueComparer<ISet<string>>(
37+
(c1, c2) => c1.SequenceEqual(c2),
38+
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())),
39+
c => c.ToHashSet());
3640

3741
var jsonSerializerSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
3842

@@ -52,6 +56,11 @@ public void Configure(EntityTypeBuilder<Payload> builder)
5256
v => JsonConvert.SerializeObject(v, jsonSerializerSettings),
5357
v => JsonConvert.DeserializeObject<IList<BlockStorageInfo>>(v, jsonSerializerSettings))
5458
.Metadata.SetValueComparer(blockStorageInfoComparer);
59+
builder.Property(j => j.Workflows)
60+
.HasConversion(
61+
v => JsonConvert.SerializeObject(v, jsonSerializerSettings),
62+
v => JsonConvert.DeserializeObject<ISet<string>>(v, jsonSerializerSettings))
63+
.Metadata.SetValueComparer(workflowComparer);
5564
}
5665
}
5766
}

src/InformaticsGateway/Services/Export/ScuExportService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ await Policy
115115
_configuration.Value.Export.Retries.RetryDelays,
116116
(exception, timeSpan, retryCount, context) =>
117117
{
118-
_logger.Log(LogLevel.Error, exception, $"Error exporting to DICOMweb destination. Waiting {timeSpan} before next retry. Retry attempt {retryCount}.");
118+
_logger.Log(LogLevel.Error, exception, $"Error exporting to DICOM destination. Waiting {timeSpan} before next retry. Retry attempt {retryCount}.");
119119
})
120120
.ExecuteAsync(async () =>
121121
{
@@ -221,4 +221,4 @@ private void HandleCStoreException(Exception ex, ExportRequestDataMessage export
221221
exportRequestData.SetFailed(errorMessage);
222222
}
223223
}
224-
}
224+
}

src/InformaticsGateway/Test/Services/Connectors/PayloadNotificationServiceTest.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,9 @@ public void PayloadNotificationService_ShalUploadFilesAndPublish()
259259
.Callback(() => _cancellationTokenSource.CancelAfter(500));
260260

261261
var payload = new Payload("test", Guid.NewGuid().ToString(), 100) { State = Payload.PayloadState.Upload };
262-
payload.Add(new DicomFileStorageInfo("correlation", "/root", "1", "source", _fileSystem.Object) { StudyInstanceUid = "study", SeriesInstanceUid = "series", SopInstanceUid = "sop" });
262+
var instance = new DicomFileStorageInfo("correlation", "/root", "1", "source", _fileSystem.Object) { StudyInstanceUid = "study", SeriesInstanceUid = "series", SopInstanceUid = "sop" };
263+
instance.SetWorkflows("workflow1", "workflow2");
264+
payload.Add(instance);
263265
var filePath = payload.Files[0].FilePath;
264266

265267
var uploadPath = Path.Combine(payload.Id.ToString(), payload.Files[0].UploadPath);
@@ -297,7 +299,11 @@ public void PayloadNotificationService_ShalUploadFilesAndPublish()
297299

298300
_instanceCleanupQueue.Verify(p => p.Queue(It.IsAny<FileStorageInfo>()), Times.Once());
299301

300-
_messageBrokerPublisherService.Verify(p => p.Publish(It.Is<string>(p => p.Equals(_options.Value.Messaging.Topics.WorkflowRequest)), It.Is<Message>(p => p.ConvertTo<WorkflowRequestMessage>().Payload.Count == 1)), Times.Once());
302+
_messageBrokerPublisherService.Verify(
303+
p => p.Publish(
304+
It.Is<string>(p => p.Equals(_options.Value.Messaging.Topics.WorkflowRequest)),
305+
It.Is<Message>(p => p.ConvertTo<WorkflowRequestMessage>().Payload.Count == 1 && p.ConvertTo<WorkflowRequestMessage>().Workflows.Count() == 2))
306+
, Times.Once());
301307
}
302308
}
303309
}

src/InformaticsGateway/Test/Services/Export/ScuExportServiceTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ public async Task UnreachableServer()
429429
{
430430
_scpLogger.Invocations.Clear();
431431
var sopInstanceUid = DicomUIDGenerator.GenerateDerivedFromUUID().UID;
432-
var destination = new DestinationApplicationEntity { AeTitle = DicomScpFixture.AETITLE, Name = DicomScpFixture.AETITLE, HostIp = "unknown", Port = _port };
432+
var destination = new DestinationApplicationEntity { AeTitle = DicomScpFixture.AETITLE, Name = DicomScpFixture.AETITLE, HostIp = "UNKNOWNHOST123456789", Port = _port };
433433
var service = new ScuExportService(_logger.Object, _serviceScopeFactory.Object, _configuration, _storageInfoProvider.Object, _dicomToolkit.Object);
434434

435435
_storageInfoProvider.Setup(p => p.HasSpaceAvailableForExport).Returns(true);
@@ -464,7 +464,7 @@ public async Task UnreachableServer()
464464

465465
DicomScpFixture.DicomStatus = DicomStatus.Success;
466466
await service.StartAsync(_cancellationTokenSource.Token);
467-
Assert.True(dataflowCompleted.WaitOne(5000));
467+
Assert.True(dataflowCompleted.WaitOne(8000));
468468
await StopAndVerify(service);
469469

470470
_messagePublisherService.Verify(
@@ -558,4 +558,4 @@ private async Task StopAndVerify(ScuExportService service)
558558
Thread.Sleep(500);
559559
}
560560
}
561-
}
561+
}

0 commit comments

Comments
 (0)