Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 41 additions & 12 deletions backend/api.test/MQTT/TestMqttEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
});
}

Expand Down
10 changes: 6 additions & 4 deletions backend/api/EventHandlers/MqttEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 0 additions & 9 deletions backend/api/MQTT/MessageModels/SaraInspectionResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading