Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove default localization pose #2012

Merged
merged 4 commits into from
Feb 7, 2025
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
3 changes: 0 additions & 3 deletions backend/api.test/Controllers/AreaControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public async Task CheckThatAreaIsCorrectlyCreatedThroughEndpoint()
PlantCode = plant.PlantCode,
InspectionAreaName = inspectionArea.Name,
AreaName = "TestArea",
DefaultLocalizationPose = new Pose(),
};

var areaContent = new StringContent(
Expand Down Expand Up @@ -105,7 +104,6 @@ public async Task CheckThatAddingDuplicateAreaNameFails()
PlantCode = plant.PlantCode,
InspectionAreaName = inspectionArea.Name,
AreaName = area.Name,
DefaultLocalizationPose = new Pose(),
};

var areaContent = new StringContent(
Expand Down Expand Up @@ -145,7 +143,6 @@ public async Task CheckThatAddingNonDuplicateAreaNameIsSuccessful()
PlantCode = plant.PlantCode,
InspectionAreaName = inspectionArea.Name,
AreaName = "MyNameIsNotTestAreaIAmUnique",
DefaultLocalizationPose = new Pose(),
};
var areaContent = new StringContent(
JsonSerializer.Serialize(areaQuery),
Expand Down
55 changes: 0 additions & 55 deletions backend/api.test/Controllers/InspectionAreaControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,60 +152,5 @@ public async Task CheckThatMissionDefinitionIsCreatedInInspectionAreaWhenSchedul
)
);
}

[Fact]
public async Task CheckThatDefaultLocalizationPoseIsUpdatedOnInspectionArea()
{
// Arrange
var installation = await DatabaseUtilities.NewInstallation();
var plant = await DatabaseUtilities.NewPlant(installation.InstallationCode);
var inspectionArea = await DatabaseUtilities.NewInspectionArea(
installation.InstallationCode,
plant.PlantCode
);

string inspectionAreaId = inspectionArea.Id;

string url = $"/inspectionAreas/{inspectionAreaId}/update-default-localization-pose";
var query = new CreateDefaultLocalizationPose
{
Pose = new Pose
{
Position = new Position
{
X = 1,
Y = 2,
Z = 3,
},
Orientation = new Orientation
{
X = 0,
Y = 0,
Z = 0,
W = 1,
},
},
};
var content = new StringContent(
JsonSerializer.Serialize(query),
null,
"application/json"
);

// Act
var response = await Client.PutAsync(url, content);
var updatedInspectionArea =
await response.Content.ReadFromJsonAsync<InspectionAreaResponse>(SerializerOptions);

// Assert
Assert.Equal(
updatedInspectionArea!.DefaultLocalizationPose!.Position,
query.Pose.Position
);
Assert.Equal(
updatedInspectionArea!.DefaultLocalizationPose.Orientation,
query.Pose.Orientation
);
}
}
}
6 changes: 0 additions & 6 deletions backend/api.test/Database/DatabaseUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public class DatabaseUtilities

public DatabaseUtilities(FlotillaDbContext context)
{
var defaultLocalizationPoseService = new DefaultLocalizationPoseService(context);

_accessRoleService = new AccessRoleService(context, new HttpContextAccessor());
_installationService = new InstallationService(context, _accessRoleService);
_missionTaskService = new MissionTaskService(
Expand All @@ -43,7 +41,6 @@ public DatabaseUtilities(FlotillaDbContext context)
_plantService = new PlantService(context, _installationService, _accessRoleService);
_inspectionAreaService = new InspectionAreaService(
context,
defaultLocalizationPoseService,
_installationService,
_plantService,
_accessRoleService,
Expand All @@ -54,7 +51,6 @@ public DatabaseUtilities(FlotillaDbContext context)
_installationService,
_plantService,
_inspectionAreaService,
defaultLocalizationPoseService,
_accessRoleService
);
_userInfoService = new UserInfoService(
Expand Down Expand Up @@ -164,7 +160,6 @@ public async Task<InspectionArea> NewInspectionArea(
InstallationCode = installationCode,
PlantCode = plantCode,
Name = inspectionAreaName,
DefaultLocalizationPose = new CreateDefaultLocalizationPose() { Pose = new Pose() },
};

return await _inspectionAreaService.Create(createInspectionAreaQuery);
Expand All @@ -185,7 +180,6 @@ public async Task<Area> NewArea(
PlantCode = plantCode,
InspectionAreaName = inspectionAreaName,
AreaName = areaName,
DefaultLocalizationPose = new Pose(),
};

return await _areaService.Create(createAreaQuery);
Expand Down
3 changes: 0 additions & 3 deletions backend/api.test/Mocks/StidServiceMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class MockStidService(FlotillaDbContext context) : IStidService
.ThenInclude(p => p.Installation)
.Include(d => d.Plant)
.Include(i => i.Installation)
.Include(d => d.DefaultLocalizationPose)
.Where(area => area.Name.Contains(testAreaName))
.ToList()
.FirstOrDefault();
Expand Down Expand Up @@ -54,7 +53,6 @@ public class MockStidService(FlotillaDbContext context) : IStidService
Id = Guid.NewGuid().ToString(),
Plant = testPlant,
Installation = testPlant.Installation,
DefaultLocalizationPose = new DefaultLocalizationPose(),
Name = "StidServiceMockInspectionArea",
};

Expand All @@ -66,7 +64,6 @@ public class MockStidService(FlotillaDbContext context) : IStidService
Installation = testInspectionArea.Plant.Installation,
Name = testAreaName,
MapMetadata = new MapMetadata(),
DefaultLocalizationPose = new DefaultLocalizationPose(),
};

context.Add(testInstallation);
Expand Down
52 changes: 0 additions & 52 deletions backend/api/Controllers/AreaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace Api.Controllers
public class AreaController(
ILogger<AreaController> logger,
IAreaService areaService,
IDefaultLocalizationPoseService defaultLocalizationPoseService,
IMissionDefinitionService missionDefinitionService
) : ControllerBase
{
Expand Down Expand Up @@ -61,57 +60,6 @@ public async Task<ActionResult<AreaResponse>> Create([FromBody] CreateAreaQuery
}
}

/// <summary>
/// Updates default localization pose
/// </summary>
/// <remarks>
/// <para> This query updates the default localization pose for an inspection area </para>
/// </remarks>
[HttpPut]
[Authorize(Roles = Role.Admin)]
[Route("{areaId}/update-default-localization-pose")]
[ProducesResponseType(typeof(AreaResponse), StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<AreaResponse>> UpdateDefaultLocalizationPose(
[FromRoute] string areaId,
[FromBody] Pose newDefaultLocalizationPose
)
{
logger.LogInformation("Updating default localization pose on area '{areaId}'", areaId);
try
{
var area = await areaService.ReadById(areaId, readOnly: true);
if (area is null)
{
logger.LogInformation("A area with id '{areaId}' does not exist", areaId);
return NotFound("Area does not exists");
}

if (area.DefaultLocalizationPose != null)
{
area.DefaultLocalizationPose.Pose = newDefaultLocalizationPose;
_ = await defaultLocalizationPoseService.Update(area.DefaultLocalizationPose);
}
else
{
area.DefaultLocalizationPose = new DefaultLocalizationPose(
newDefaultLocalizationPose
);
area = await areaService.Update(area);
}

return Ok(new AreaResponse(area));
}
catch (Exception e)
{
logger.LogError(e, "Error while updating the default localization pose");
throw;
}
}

/// <summary>
/// Deletes the area with the specified id from the database.
/// </summary>
Expand Down
135 changes: 0 additions & 135 deletions backend/api/Controllers/InspectionAreaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ namespace Api.Controllers
[Route("inspectionAreas")]
public class InspectionAreaController(
ILogger<InspectionAreaController> logger,
IMapService mapService,
IInspectionAreaService inspectionAreaService,
IDefaultLocalizationPoseService defaultLocalizationPoseService,
IInstallationService installationService,
IPlantService plantService,
IMissionDefinitionService missionDefinitionService
Expand Down Expand Up @@ -225,68 +223,6 @@ await inspectionAreaService.ReadByInstallationAndPlantAndName(
}
}

/// <summary>
/// Updates default localization pose
/// </summary>
/// <remarks>
/// <para> This query updates the default localization pose for a inspection area </para>
/// </remarks>
[HttpPut]
[Authorize(Roles = Role.Admin)]
[Route("{inspectionAreaId}/update-default-localization-pose")]
[ProducesResponseType(typeof(InspectionAreaResponse), StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<InspectionAreaResponse>> UpdateDefaultLocalizationPose(
[FromRoute] string inspectionAreaId,
[FromBody] CreateDefaultLocalizationPose newDefaultLocalizationPose
)
{
logger.LogInformation(
"Updating default localization pose on inspection area '{inspectionAreaId}'",
inspectionAreaId
);
try
{
var inspectionArea = await inspectionAreaService.ReadById(
inspectionAreaId,
readOnly: true
);
if (inspectionArea is null)
{
logger.LogInformation(
"A inspection area with id '{inspectionAreaId}' does not exist",
inspectionAreaId
);
return NotFound("InspectionArea does not exists");
}

if (inspectionArea.DefaultLocalizationPose != null)
{
inspectionArea.DefaultLocalizationPose.Pose = newDefaultLocalizationPose.Pose;
_ = await defaultLocalizationPoseService.Update(
inspectionArea.DefaultLocalizationPose
);
}
else
{
inspectionArea.DefaultLocalizationPose = new DefaultLocalizationPose(
newDefaultLocalizationPose.Pose
);
inspectionArea = await inspectionAreaService.Update(inspectionArea);
}

return Ok(new InspectionAreaResponse(inspectionArea));
}
catch (Exception e)
{
logger.LogError(e, "Error while updating the default localization pose");
throw;
}
}

/// <summary>
/// Deletes the inspection area with the specified id from the database.
/// </summary>
Expand All @@ -307,76 +243,5 @@ [FromRoute] string id
return NotFound($"InspectionArea with id {id} not found");
return Ok(new InspectionAreaResponse(inspectionArea));
}

/// <summary>
/// Gets map metadata for localization poses belonging to inspection area with specified id
/// </summary>
[HttpGet]
[Authorize(Roles = Role.Any)]
[Route("{id}/map-metadata")]
[ProducesResponseType(typeof(MapMetadata), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<MapMetadata>> GetMapMetadata([FromRoute] string id)
{
var inspectionArea = await inspectionAreaService.ReadById(id, readOnly: true);
if (inspectionArea is null)
{
string errorMessage = $"InspectionArea not found for inspectionArea with ID {id}";
logger.LogError("{ErrorMessage}", errorMessage);
return NotFound(errorMessage);
}
if (inspectionArea.Installation == null)
{
string errorMessage = "Installation missing from inspection area";
logger.LogWarning(errorMessage);
return StatusCode(StatusCodes.Status500InternalServerError, errorMessage);
}

if (inspectionArea.DefaultLocalizationPose is null)
{
string errorMessage =
$"InspectionArea with id '{inspectionArea.Id}' does not have a default localization pose";
logger.LogInformation("{ErrorMessage}", errorMessage);
return NotFound(errorMessage);
}

MapMetadata? mapMetadata;
var positions = new List<Position>
{
inspectionArea.DefaultLocalizationPose.Pose.Position,
};
try
{
mapMetadata = await mapService.ChooseMapFromPositions(
positions,
inspectionArea.Installation.InstallationCode
);
}
catch (RequestFailedException e)
{
string errorMessage =
$"An error occurred while retrieving the map for inspection area {inspectionArea.Id}";
logger.LogError(e, "{ErrorMessage}", errorMessage);
return StatusCode(StatusCodes.Status502BadGateway, errorMessage);
}
catch (ArgumentOutOfRangeException e)
{
string errorMessage =
$"Could not find a suitable map for inspection area {inspectionArea.Id}";
logger.LogError(e, "{ErrorMessage}", errorMessage);
return NotFound(errorMessage);
}

if (mapMetadata == null)
{
return NotFound(
"A map which contained at least half of the points in this mission could not be found"
);
}
return Ok(mapMetadata);
}
}
}
3 changes: 0 additions & 3 deletions backend/api/Controllers/Models/AreaResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ public class AreaResponse

public MapMetadata MapMetadata { get; set; }

public Pose? DefaultLocalizationPose { get; set; }

[JsonConstructor]
#nullable disable
public AreaResponse() { }
Expand All @@ -36,7 +34,6 @@ public AreaResponse(Area area)
InstallationCode = area.Installation.InstallationCode;
AreaName = area.Name;
MapMetadata = area.MapMetadata;
DefaultLocalizationPose = area.DefaultLocalizationPose?.Pose;
}
}
}
2 changes: 0 additions & 2 deletions backend/api/Controllers/Models/CreateAreaQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ public struct CreateAreaQuery
public string PlantCode { get; set; }
public string InspectionAreaName { get; set; }
public string AreaName { get; set; }

public Pose? DefaultLocalizationPose { get; set; }
}
}
Loading