|
| 1 | +/* |
| 2 | + * Copyright 2021-2023 MONAI Consortium |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +using System.ComponentModel.DataAnnotations; |
| 18 | +using System.Text.Json.Serialization; |
| 19 | +using Ardalis.GuardClauses; |
| 20 | +using Newtonsoft.Json; |
| 21 | +using Newtonsoft.Json.Converters; |
| 22 | +namespace Monai.Deploy.Messaging.Events |
| 23 | +{ |
| 24 | + public class ExternalAppRequestEvent |
| 25 | + { |
| 26 | + /// <summary> |
| 27 | + /// Gets or sets the workflow instanceID generated by the Workflow Manager. |
| 28 | + /// </summary> |
| 29 | + [JsonProperty(PropertyName = "workflow_instance_id")] |
| 30 | + [JsonPropertyName("workflow_instance_id")] |
| 31 | + [Required] |
| 32 | + public string WorkflowInstanceId { get; set; } = default!; |
| 33 | + |
| 34 | + /// <summary> |
| 35 | + /// Gets or sets the export task ID generated by the Workflow Manager. |
| 36 | + /// </summary> |
| 37 | + [JsonProperty(PropertyName = "export_task_id")] |
| 38 | + [JsonPropertyName("export_task_id")] |
| 39 | + [Required] |
| 40 | + public string ExportTaskId { get; set; } = default!; |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// Gets or set the correlation ID. |
| 44 | + /// For DIMSE, the correlation ID is the UUID associated with the first DICOM association received. |
| 45 | + /// For ACR, use the Transaction ID in the original request. |
| 46 | + /// </summary> |
| 47 | + [JsonProperty(PropertyName = "correlation_id")] |
| 48 | + [JsonPropertyName("correlation_id")] |
| 49 | + [Required] |
| 50 | + public string CorrelationId { get; set; } = default!; |
| 51 | + |
| 52 | + /// <summary> |
| 53 | + /// Gets or sets the delivery tag or acknowledge token for the task. |
| 54 | + /// </summary> |
| 55 | + [JsonProperty(PropertyName = "delivery_tag")] |
| 56 | + [JsonPropertyName("delivery_tag")] |
| 57 | + public string DeliveryTag { get; set; } = default!; |
| 58 | + |
| 59 | + /// <summary> |
| 60 | + /// Gets or sets the message ID set by the message broker. |
| 61 | + /// </summary> |
| 62 | + [JsonProperty(PropertyName = "message_id")] |
| 63 | + [JsonPropertyName("message_id")] |
| 64 | + public string MessageId { get; set; } = default!; |
| 65 | + |
| 66 | + /// <summary> |
| 67 | + /// Gets or sets the state of the export task. |
| 68 | + /// </summary> |
| 69 | + [JsonProperty(PropertyName = "status")] |
| 70 | + [JsonPropertyName("status")] |
| 71 | + [Newtonsoft.Json.JsonConverter(typeof(StringEnumConverter))] |
| 72 | + [System.Text.Json.Serialization.JsonConverter(typeof(JsonStringEnumConverter))] |
| 73 | + [Required] |
| 74 | + public ExportStatus Status { get; set; } |
| 75 | + |
| 76 | + /// <summary> |
| 77 | + /// Gets or sets error messages, if any, when exporting. |
| 78 | + /// </summary> |
| 79 | + [JsonProperty(PropertyName = "message")] |
| 80 | + [JsonPropertyName("message")] |
| 81 | + public string Message { get; set; } = default!; |
| 82 | + |
| 83 | + /// <summary> |
| 84 | + /// Gets or sets a list of files to be exported. |
| 85 | + /// </summary> |
| 86 | + [JsonProperty(PropertyName = "files")] |
| 87 | + [JsonPropertyName("files")] |
| 88 | + [Required, MinLength(1)] |
| 89 | + public IEnumerable<string> Files { get; set; } = default!; |
| 90 | + |
| 91 | + /// <summary> |
| 92 | + /// Gets or sets files exported with its status |
| 93 | + /// </summary> |
| 94 | + [JsonProperty(PropertyName = "file_statuses")] |
| 95 | + [JsonPropertyName("file_statuses")] |
| 96 | + public Dictionary<string, FileExportStatus> FileStatuses { get; set; } |
| 97 | + |
| 98 | + /// <summary> |
| 99 | + /// Gets or sets error messages related to this export task. |
| 100 | + /// </summary> |
| 101 | + [JsonProperty(PropertyName = "error_messages")] |
| 102 | + [JsonPropertyName("error_messages")] |
| 103 | + public List<string> ErrorMessages { get; private set; } = new List<string>(); |
| 104 | + |
| 105 | + /// <summary> |
| 106 | + /// A list of data output plug-in type names to be executed by the export services. |
| 107 | + /// Each string must be a fully-qualified type name. |
| 108 | + /// E.g. <code>MyCompnay.MyProject.MyNamepsace.MyPlugin, MyCompnay.MyProject.MyNamepsace</code> where |
| 109 | + /// <code>MyCompnay.MyProject.MyNamepsace</code> is the name of the assembly (DLL). |
| 110 | + /// </summary> |
| 111 | + [JsonProperty(PropertyName = "plug_in_assemblies")] |
| 112 | + [JsonPropertyName("plug_in_assemblies")] |
| 113 | + public List<string> PluginAssemblies { get; private set; } = new List<string>(); |
| 114 | + |
| 115 | + /// <summary> |
| 116 | + /// the targets to export too |
| 117 | + /// </summary> |
| 118 | + public List<DataOrigin> Targets { get; set; } = new List<DataOrigin>(); |
| 119 | + |
| 120 | + [JsonProperty(PropertyName = "destination_folder")] |
| 121 | + [JsonPropertyName("destination_folder")] |
| 122 | + public string? DestinationFolder { get; set; } |
| 123 | + |
| 124 | + [Newtonsoft.Json.JsonConstructor] |
| 125 | + [System.Text.Json.Serialization.JsonConstructor] |
| 126 | + public ExternalAppRequestEvent() |
| 127 | + { |
| 128 | + Status = ExportStatus.Unknown; |
| 129 | + FileStatuses = new Dictionary<string, FileExportStatus>(); |
| 130 | + } |
| 131 | + |
| 132 | + public ExternalAppRequestEvent(ExportRequestEvent exportRequest, ExportStatus exportStatus, Dictionary<string, FileExportStatus> fileStatuses) |
| 133 | + { |
| 134 | + Guard.Against.Null(exportRequest, nameof(exportRequest)); |
| 135 | + Guard.Against.Null(exportStatus, nameof(exportStatus)); |
| 136 | + Guard.Against.Null(fileStatuses, nameof(fileStatuses)); |
| 137 | + |
| 138 | + WorkflowInstanceId = exportRequest.WorkflowInstanceId; |
| 139 | + ExportTaskId = exportRequest.ExportTaskId; |
| 140 | + Message = string.Join(System.Environment.NewLine, exportRequest.ErrorMessages); |
| 141 | + Status = exportStatus; |
| 142 | + FileStatuses = fileStatuses; |
| 143 | + } |
| 144 | + } |
| 145 | +} |
0 commit comments