diff --git a/backend/api.test/MQTT/TestMqttEvents.cs b/backend/api.test/MQTT/TestMqttEvents.cs index 6cab60fba..10225ed62 100644 --- a/backend/api.test/MQTT/TestMqttEvents.cs +++ b/backend/api.test/MQTT/TestMqttEvents.cs @@ -526,16 +526,43 @@ await TestSetupHelpers.WaitFor(async () => public async Task TestMQTTSaraInspectionResult() { var installation = await DatabaseUtilities.NewInstallation(); + var plant = await DatabaseUtilities.NewPlant(installation.InstallationCode); + var inspectionArea = await DatabaseUtilities.NewInspectionArea( + installation.InstallationCode, + plant.PlantCode + ); + var robot = await DatabaseUtilities.NewRobot( + RobotStatus.Busy, + installation, + inspectionArea.Id + ); + var task = new TaskDefinition( + new TaskQuery + { + TagId = "test", + TargetPosition = new Position(), + SensorType = SensorType.Image, + AnalysisTypes = [AnalysisType.Fencilla], + RobotPose = new Pose(11, 11, 11, 0, 0, 0, 1), + }, + 1 + ).ToMissionRunTask(); + var missionRun = await DatabaseUtilities.NewMissionRun( + installation.InstallationCode, + robot, + inspectionArea, + writeToDatabase: true, + missionStatus: MissionStatus.Ongoing, + tasks: [task] + ); + var isarInspectionId = missionRun.Tasks[0]!.Id; var message = new SaraInspectionResultMessage { - InspectionId = Guid.NewGuid().ToString(), + InspectionId = isarInspectionId, WorkflowId = Guid.NewGuid(), AnalysisRunId = Guid.NewGuid(), AnalysisId = Guid.NewGuid(), - StorageAccount = "testaccount", - BlobContainer = installation.InstallationCode, - BlobName = "testblob", }; var messageString = JsonSerializer.Serialize(message); await MqttService.PublishMessageBasedOnTopic( @@ -546,14 +573,16 @@ await MqttService.PublishMessageBasedOnTopic( await TestSetupHelpers.WaitFor(async () => { var latestMessages = Factory.MockSignalRService.LatestMessages; - if (latestMessages.Count != 1) - return false; - var m = (dynamic)latestMessages[0]; - if (m.Label != "Inspection Visulization Ready") - return false; - var result = (InspectionResultMessage)m.Message; - - return result.InspectionId == message.InspectionId; + foreach (var raw in latestMessages) + { + var m = (dynamic)raw; + if (m.Label != "Inspection Visulization Ready") + continue; + var result = (InspectionResultMessage)m.Message; + if (result.InspectionId == message.InspectionId) + return true; + } + return false; }); } diff --git a/backend/api/EventHandlers/MqttEventHandler.cs b/backend/api/EventHandlers/MqttEventHandler.cs index 890a4ed12..d1ea76cb3 100644 --- a/backend/api/EventHandlers/MqttEventHandler.cs +++ b/backend/api/EventHandlers/MqttEventHandler.cs @@ -876,16 +876,18 @@ SaraInspectionResultMessage inspectionResult InspectionId = inspectionResult.InspectionId, }; - var installation = await InstallationService.ReadByInstallationCode( - inspectionResult.BlobContainer, + var missionRun = await MissionRunService.ReadByTaskId( + inspectionResult.InspectionId, readOnly: true ); + var installation = missionRun?.InspectionArea?.Installation; + if (installation == null) { _logger.LogError( - "Installation with code {Code} not found when processing SARA inspection result update", - inspectionResult.BlobContainer + "Installation could not be found when processing SARA inspection result update with inspection ID {InspectionId}", + inspectionResult.InspectionId ); return; } diff --git a/backend/api/MQTT/MessageModels/SaraInspectionResult.cs b/backend/api/MQTT/MessageModels/SaraInspectionResult.cs index a531cd27b..3f13adf48 100644 --- a/backend/api/MQTT/MessageModels/SaraInspectionResult.cs +++ b/backend/api/MQTT/MessageModels/SaraInspectionResult.cs @@ -16,15 +16,6 @@ public class SaraInspectionResultMessage : MqttMessage [JsonPropertyName("analysis_id")] public required Guid AnalysisId { get; set; } - - [JsonPropertyName("storageAccount")] - public required string StorageAccount { get; set; } - - [JsonPropertyName("blobContainer")] - public required string BlobContainer { get; set; } - - [JsonPropertyName("blobName")] - public required string BlobName { get; set; } } public class InspectionResultMessage