Skip to content

Commit 04113e7

Browse files
committed
MQTT: Resolve installation from inspection_id in SARA viz handler
1 parent de78a36 commit 04113e7

3 files changed

Lines changed: 37 additions & 17 deletions

File tree

backend/api.test/MQTT/TestMqttEvents.cs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,16 +526,43 @@ await TestSetupHelpers.WaitFor(async () =>
526526
public async Task TestMQTTSaraInspectionResult()
527527
{
528528
var installation = await DatabaseUtilities.NewInstallation();
529+
var plant = await DatabaseUtilities.NewPlant(installation.InstallationCode);
530+
var inspectionArea = await DatabaseUtilities.NewInspectionArea(
531+
installation.InstallationCode,
532+
plant.PlantCode
533+
);
534+
var robot = await DatabaseUtilities.NewRobot(
535+
RobotStatus.Busy,
536+
installation,
537+
inspectionArea.Id
538+
);
539+
var task = new TaskDefinition(
540+
new TaskQuery
541+
{
542+
TagId = "test",
543+
TargetPosition = new Position(),
544+
SensorType = SensorType.Image,
545+
AnalysisTypes = [AnalysisType.Fencilla],
546+
RobotPose = new Pose(11, 11, 11, 0, 0, 0, 1),
547+
},
548+
1
549+
).ToMissionRunTask();
550+
var missionRun = await DatabaseUtilities.NewMissionRun(
551+
installation.InstallationCode,
552+
robot,
553+
inspectionArea,
554+
writeToDatabase: true,
555+
missionStatus: MissionStatus.Ongoing,
556+
tasks: [task]
557+
);
558+
var isarInspectionId = missionRun.Tasks[0]!.Id;
529559

530560
var message = new SaraInspectionResultMessage
531561
{
532-
InspectionId = Guid.NewGuid().ToString(),
562+
InspectionId = isarInspectionId,
533563
WorkflowId = Guid.NewGuid(),
534564
AnalysisRunId = Guid.NewGuid(),
535565
AnalysisId = Guid.NewGuid(),
536-
StorageAccount = "testaccount",
537-
BlobContainer = installation.InstallationCode,
538-
BlobName = "testblob",
539566
};
540567
var messageString = JsonSerializer.Serialize(message);
541568
await MqttService.PublishMessageBasedOnTopic(

backend/api/EventHandlers/MqttEventHandler.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -876,16 +876,18 @@ SaraInspectionResultMessage inspectionResult
876876
InspectionId = inspectionResult.InspectionId,
877877
};
878878

879-
var installation = await InstallationService.ReadByInstallationCode(
880-
inspectionResult.BlobContainer,
879+
var missionRun = await MissionRunService.ReadByTaskId(
880+
inspectionResult.InspectionId,
881881
readOnly: true
882882
);
883883

884+
var installation = missionRun?.InspectionArea?.Installation;
885+
884886
if (installation == null)
885887
{
886888
_logger.LogError(
887-
"Installation with code {Code} not found when processing SARA inspection result update",
888-
inspectionResult.BlobContainer
889+
"Installation could not be found when processing SARA inspection result update with inspection ID {InspectionId}",
890+
inspectionResult.InspectionId
889891
);
890892
return;
891893
}

backend/api/MQTT/MessageModels/SaraInspectionResult.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@ public class SaraInspectionResultMessage : MqttMessage
1616

1717
[JsonPropertyName("analysis_id")]
1818
public required Guid AnalysisId { get; set; }
19-
20-
[JsonPropertyName("storageAccount")]
21-
public required string StorageAccount { get; set; }
22-
23-
[JsonPropertyName("blobContainer")]
24-
public required string BlobContainer { get; set; }
25-
26-
[JsonPropertyName("blobName")]
27-
public required string BlobName { get; set; }
2819
}
2920

3021
public class InspectionResultMessage

0 commit comments

Comments
 (0)