Skip to content

Commit

Permalink
fix: try getting municipality geometry by new niscode first
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneD committed Oct 29, 2024
1 parent 9f4283b commit a5c1d3e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,21 @@ await idempotentCommandHandler.Dispatch(
return registerMunicipalityCommand.MunicipalityId;
}

private static async Task<MultiPolygon> BuildMunicipalityGeometry(ProposeMergerRequest municipality, IMunicipalityGeometryReader municipalityGeometryReader)
private static async Task<Geometry> BuildMunicipalityGeometry(ProposeMergerRequest municipality, IMunicipalityGeometryReader municipalityGeometryReader)
{
var geometryFactory = GeometryConfiguration.CreateGeometryFactory();

var municipalityGeometriesToMerge = await Task.WhenAll(municipality.MergerOf.Select(municipalityGeometryReader.GetGeometry));
var newMunicipalityGeometry = new MultiPolygon(
try
{
var newMunicipalityGeometry = await municipalityGeometryReader.GetGeometry(municipality.NisCode);
return newMunicipalityGeometry;
}
catch (InvalidPolygonException)
{ }

var municipalityGeometriesToMerge =
await Task.WhenAll(municipality.MergerOf.Select(municipalityGeometryReader.GetGeometry));
var newMunicipalityCombinedGeometry = new MultiPolygon(
municipalityGeometriesToMerge.SelectMany(geometry =>
{
return geometry switch
Expand All @@ -112,7 +121,8 @@ private static async Task<MultiPolygon> BuildMunicipalityGeometry(ProposeMergerR
{
SRID = geometryFactory.SRID
};
return newMunicipalityGeometry;

return newMunicipalityCombinedGeometry;
}

private static Language ToLanguage(Taal taal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading.Tasks;
using Autofac;
using Be.Vlaanderen.Basisregisters.GrAr.Legacy;
using Exceptions;
using FluentAssertions;
using FluentValidation;
using Moq;
Expand Down Expand Up @@ -82,6 +83,9 @@ public async Task GivenValidRequestWithNewDestinationMunicipality_ThenMunicipali
};

var municipalityGeometryReaderMock = new Mock<IMunicipalityGeometryReader>();
municipalityGeometryReaderMock
.Setup(x => x.GetGeometry("10000"))
.Throws(() => new InvalidPolygonException());
municipalityGeometryReaderMock
.Setup(x => x.GetGeometry("10001"))
.Returns(() => Task.FromResult(new WKTReader().Read("SRID=31370;POLYGON((0 0,0 1,1 1,1 0,0 0))")));
Expand All @@ -102,7 +106,7 @@ await _controller.Propose(
streamIds.Count.Should().Be(1);
var newMunicipalityId = streamIds.Single();

municipalityGeometryReaderMock.Invocations.Count.Should().Be(2);
municipalityGeometryReaderMock.Invocations.Count.Should().Be(3);

ImportContext.MunicipalityMergers.Count().Should().Be(2);
var merge1 = ImportContext.MunicipalityMergers.ToList()[0];
Expand Down

0 comments on commit a5c1d3e

Please sign in to comment.