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

fix: try getting municipality geometry by new niscode first #645

Merged
merged 1 commit into from
Oct 29, 2024
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
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
Loading