Skip to content

Commit

Permalink
fix: only add change files when extract request is not informative
Browse files Browse the repository at this point in the history
  • Loading branch information
jvandaal committed Jan 24, 2025
1 parent 83f0434 commit f32a5ca
Show file tree
Hide file tree
Showing 16 changed files with 140 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ await queue.Write(new Command(
new ExternalExtractRequestId(message.Body.ExternalRequestId),
new DownloadId(message.Body.DownloadId),
new ExtractDescription(extractDescription),
GeometryTranslator.Translate(message.Body.Contour));
GeometryTranslator.Translate(message.Body.Contour),
message.Body.IsInformative);

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace RoadRegistry.BackOffice.ZipArchiveWriters.ExtractHost;
using Be.Vlaanderen.Basisregisters.Shaperon;
using Extracts;
using Extracts.Dbase.GradeSeparatedJuntions;
using FeatureCompare;
using Microsoft.IO;

public class GradeSeparatedJunctionArchiveWriter : IZipArchiveWriter
Expand Down Expand Up @@ -33,7 +32,9 @@ public async Task WriteAsync(
request.Contour, cancellationToken);

const ExtractFileName extractFilename = ExtractFileName.RltOgkruising;
FeatureType[] featureTypes = [FeatureType.Extract, FeatureType.Change];
FeatureType[] featureTypes = request.IsInformative
? [FeatureType.Extract]
: [FeatureType.Extract, FeatureType.Change];

foreach (var featureType in featureTypes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public async Task WriteAsync(
var nodes = await zipArchiveDataProvider.GetRoadNodes(request.Contour, cancellationToken);

const ExtractFileName extractFilename = ExtractFileName.Wegknoop;
FeatureType[] featureTypes = [FeatureType.Extract, FeatureType.Change];
FeatureType[] featureTypes = request.IsInformative
? [FeatureType.Extract]
: [FeatureType.Extract, FeatureType.Change];

foreach (var featureType in featureTypes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace RoadRegistry.BackOffice.ZipArchiveWriters.ExtractHost;
using Be.Vlaanderen.Basisregisters.Shaperon;
using Extracts;
using Extracts.Dbase.RoadSegments;
using FeatureCompare;
using Microsoft.IO;

public class RoadSegmentEuropeanRoadAttributesToZipArchiveWriter : IZipArchiveWriter
Expand Down Expand Up @@ -35,7 +34,9 @@ public async Task WriteAsync(
cancellationToken);

const ExtractFileName extractFilename = ExtractFileName.AttEuropweg;
FeatureType[] featureTypes = [FeatureType.Extract, FeatureType.Change];
FeatureType[] featureTypes = request.IsInformative
? [FeatureType.Extract]
: [FeatureType.Extract, FeatureType.Change];

foreach (var featureType in featureTypes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace RoadRegistry.BackOffice.ZipArchiveWriters.ExtractHost;
using Be.Vlaanderen.Basisregisters.Shaperon;
using Extracts;
using Extracts.Dbase.RoadSegments;
using FeatureCompare;
using Microsoft.IO;

public class RoadSegmentLaneAttributesToZipArchiveWriter : IZipArchiveWriter
Expand All @@ -32,7 +31,9 @@ public async Task WriteAsync(ZipArchive archive, RoadNetworkExtractAssemblyReque
cancellationToken);

const ExtractFileName extractFilename = ExtractFileName.AttRijstroken;
FeatureType[] featureTypes = [FeatureType.Extract, FeatureType.Change];
FeatureType[] featureTypes = request.IsInformative
? [FeatureType.Extract]
: [FeatureType.Extract, FeatureType.Change];

foreach (var featureType in featureTypes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace RoadRegistry.BackOffice.ZipArchiveWriters.ExtractHost;
using Be.Vlaanderen.Basisregisters.Shaperon;
using Extracts;
using Extracts.Dbase.RoadSegments;
using FeatureCompare;
using Microsoft.IO;

public class RoadSegmentNationalRoadAttributesToZipArchiveWriter : IZipArchiveWriter
Expand Down Expand Up @@ -35,7 +34,9 @@ public async Task WriteAsync(
cancellationToken);

const ExtractFileName extractFilename = ExtractFileName.AttNationweg;
FeatureType[] featureTypes = [FeatureType.Extract, FeatureType.Change];
FeatureType[] featureTypes = request.IsInformative
? [FeatureType.Extract]
: [FeatureType.Extract, FeatureType.Change];

foreach (var featureType in featureTypes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace RoadRegistry.BackOffice.ZipArchiveWriters.ExtractHost;
using Be.Vlaanderen.Basisregisters.Shaperon;
using Extracts;
using Extracts.Dbase.RoadSegments;
using FeatureCompare;
using Microsoft.IO;

public class RoadSegmentNumberedRoadAttributesToZipArchiveWriter : IZipArchiveWriter
Expand Down Expand Up @@ -35,7 +34,9 @@ public async Task WriteAsync(
cancellationToken);

const ExtractFileName extractFilename = ExtractFileName.AttGenumweg;
FeatureType[] featureTypes = [FeatureType.Extract, FeatureType.Change];
FeatureType[] featureTypes = request.IsInformative
? [FeatureType.Extract]
: [FeatureType.Extract, FeatureType.Change];

foreach (var featureType in featureTypes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace RoadRegistry.BackOffice.ZipArchiveWriters.ExtractHost;
using Be.Vlaanderen.Basisregisters.Shaperon;
using Extracts;
using Extracts.Dbase.RoadSegments;
using FeatureCompare;
using Microsoft.IO;

public class RoadSegmentSurfaceAttributesToZipArchiveWriter : IZipArchiveWriter
Expand Down Expand Up @@ -34,7 +33,9 @@ public async Task WriteAsync(
cancellationToken);

const ExtractFileName extractFilename = ExtractFileName.AttWegverharding;
FeatureType[] featureTypes = [FeatureType.Extract, FeatureType.Change];
FeatureType[] featureTypes = request.IsInformative
? [FeatureType.Extract]
: [FeatureType.Extract, FeatureType.Change];

foreach (var featureType in featureTypes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace RoadRegistry.BackOffice.ZipArchiveWriters.ExtractHost;
using Be.Vlaanderen.Basisregisters.Shaperon;
using Extracts;
using Extracts.Dbase.RoadSegments;
using FeatureCompare;
using Microsoft.IO;

public class RoadSegmentWidthAttributesToZipArchiveWriter : IZipArchiveWriter
Expand Down Expand Up @@ -34,7 +33,9 @@ public async Task WriteAsync(
cancellationToken);

const ExtractFileName extractFilename = ExtractFileName.AttWegbreedte;
FeatureType[] featureTypes = [FeatureType.Extract, FeatureType.Change];
FeatureType[] featureTypes = request.IsInformative
? [FeatureType.Extract]
: [FeatureType.Extract, FeatureType.Change];

foreach (var featureType in featureTypes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace RoadRegistry.BackOffice.ZipArchiveWriters.ExtractHost;
using Extensions;
using Extracts;
using Extracts.Dbase.RoadSegments;
using FeatureCompare;
using Microsoft.IO;

public class RoadSegmentsToZipArchiveWriter : IZipArchiveWriter
Expand Down Expand Up @@ -43,7 +42,9 @@ public async Task WriteAsync(
request.Contour, cancellationToken);

const ExtractFileName extractFilename = ExtractFileName.Wegsegment;
FeatureType[] featureTypes = [FeatureType.Extract, FeatureType.Change];
FeatureType[] featureTypes = request.IsInformative
? [FeatureType.Extract]
: [FeatureType.Extract, FeatureType.Change];

foreach (var featureType in featureTypes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,25 @@ namespace RoadRegistry.BackOffice.Extracts;

public class RoadNetworkExtractAssemblyRequest
{
public RoadNetworkExtractAssemblyRequest(ExternalExtractRequestId requestId, DownloadId downloadId, ExtractDescription extractDescription, IPolygonal contour)
public RoadNetworkExtractAssemblyRequest(
ExternalExtractRequestId requestId,
DownloadId downloadId,
ExtractDescription extractDescription,
IPolygonal contour,
bool isInformative)
{
ExternalRequestId = requestId;
RequestId = ExtractRequestId.FromExternalRequestId(requestId);
DownloadId = downloadId;
ExtractDescription = extractDescription;
Contour = contour ?? throw new ArgumentNullException(nameof(contour));
IsInformative = isInformative;
}

public IPolygonal Contour { get; }
public DownloadId DownloadId { get; }
public ExternalExtractRequestId ExternalRequestId { get; }
public ExtractDescription ExtractDescription { get; }
public ExtractRequestId RequestId { get; }
}
public DownloadId DownloadId { get; }
public ExtractDescription ExtractDescription { get; }
public IPolygonal Contour { get; }
public bool IsInformative { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public IntegrationToZipArchiveWriterFixture(WKTReader wktReader, RecyclableMemor
new ExternalExtractRequestId("TEST"),
new DownloadId(),
new ExtractDescription("TEST"),
(IPolygonal)Result.Single());
(IPolygonal)Result.Single(),
isInformative: false);

public Task DisposeAsync()
{
Expand All @@ -52,4 +53,4 @@ public async Task InitializeAsync()
File.WriteAllBytes(Path.ChangeExtension(FileInfo.FullName, ".zip"), fileBytes);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public RoadNetworkExtractToZipArchiveWriterFixture(
new ExternalExtractRequestId("TEST"),
new DownloadId(),
new ExtractDescription("TEST"),
(IPolygonal)Result.Single());
(IPolygonal)Result.Single(),
isInformative: false);

public Task DisposeAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public RoadNodesToZipArchiveWriterFixture(WKTReader wktReader, RecyclableMemoryS
new ExternalExtractRequestId("TEST"),
new DownloadId(),
new ExtractDescription("TEST"),
(IPolygonal)Result.Single());
(IPolygonal)Result.Single(),
isInformative: false);

public Task DisposeAsync()
{
Expand All @@ -51,4 +52,4 @@ public async Task InitializeAsync()
File.WriteAllBytes(Path.ChangeExtension(FileInfo.FullName, ".zip"), fileBytes);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ private RoadNetworkExtractAssemblyRequest CreateRoadNetworkExtractAssemblyReques
externalRequestId,
fixture.DownloadId,
extractDescription,
fixture.Contour);
fixture.Contour,
isInformative: false);
}

private static void CustomizeRoadNetworkExtractAssemblyRequestFixture(IFixture fixture)
Expand All @@ -67,7 +68,8 @@ private static void CustomizeRoadNetworkExtractAssemblyRequestFixture(IFixture f
fixture.Create<ExternalExtractRequestId>(),
fixture.Create<DownloadId>(),
fixture.Create<ExtractDescription>(),
GeometryTranslator.Translate(geometry))));
GeometryTranslator.Translate(geometry),
isInformative: false)));
}

private static IEnumerable<(RecordNumber, TDbaseRecord)> ReadFromArchive<TDbaseRecord>(ZipArchive archive, string fileName) where TDbaseRecord : DbaseRecord, new()
Expand Down Expand Up @@ -178,7 +180,7 @@ public Task GeometryOrdinatesShouldBeOnlyXAndY()
new CoordinateZM(0, 1),
new CoordinateZM(0, 0)
}));
request = new RoadNetworkExtractAssemblyRequest(request.ExternalRequestId, request.DownloadId, request.ExtractDescription, contour);
request = new RoadNetworkExtractAssemblyRequest(request.ExternalRequestId, request.DownloadId, request.ExtractDescription, contour, isInformative: false);

Assert.IsType<CoordinateZM>(contour.Coordinate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public RoadNetworkExtractToZipArchiveWriterTests(
}

[Fact]
public async Task Test()
public async Task InformativeExtractRequest_ThenOnlyContainsExtractAndIntegrationFiles()
{
var fixture = new RoadNetworkTestData().ObjectProvider;
fixture.CustomizeNtsPolygon();
Expand All @@ -78,7 +78,91 @@ public async Task Test()
var stream = _memoryStreamManager.GetStream();

using var archive = new ZipArchive(stream, ZipArchiveMode.Update, true, Encoding.UTF8);
var request = fixture.Create<RoadNetworkExtractAssemblyRequest>();
var request = new RoadNetworkExtractAssemblyRequest(
fixture.Create<ExternalExtractRequestId>(),
fixture.Create<DownloadId>(),
fixture.Create<ExtractDescription>(),
fixture.Create<IPolygonal>(),
isInformative: true);
await zipArchiveWriter.WriteAsync(archive, request, _zipArchiveDataProvider.Object, CancellationToken.None);

var fileNames = archive.Entries.Select(x => x.FullName).ToList();

var expectedFileNames = new[] {
"Transactiezones.dbf",
"Transactiezones.shp",
"Transactiezones.shx",
"Transactiezones.cpg",
"Transactiezones.prj",
"eLstOrg.dbf",
"eWegknoop.dbf",
"eWegknoop.shp",
"eWegknoop.shx",
"eWegknoop.cpg",
"eWegknoop.prj",
"eWegsegment.dbf",
"eWegsegment.shp",
"eWegsegment.shx",
"eWegsegment.cpg",
"eWegsegment.prj",
"eAttRijstroken.dbf",
"eAttWegbreedte.dbf",
"eAttWegverharding.dbf",
"eAttNationweg.dbf",
"eAttEuropweg.dbf",
"eAttGenumweg.dbf",
"eRltOgkruising.dbf",
"iWegsegment.dbf",
"iWegsegment.shp",
"iWegsegment.shx",
"iWegsegment.cpg",
"iWegsegment.prj",
"iWegknoop.dbf",
"iWegknoop.shp",
"iWegknoop.shx",
"iWegknoop.cpg",
"iWegknoop.prj",
"eWegknoopLktType.dbf",
"eWegverhardLktType.dbf",
"eGenumwegLktRichting.dbf",
"eWegsegmentLktWegcat.dbf",
"eWegsegmentLktTgbep.dbf",
"eWegsegmentLktMethode.dbf",
"eWegsegmentLktMorf.dbf",
"eWegsegmentLktStatus.dbf",
"eOgkruisingLktType.dbf",
"eRijstrokenLktRichting.dbf"
};

fileNames.Should().HaveCount(expectedFileNames.Length);
foreach (var fileName in expectedFileNames)
{
fileNames.Should().Contain(fileName);
}
}

[Fact]
public async Task NotInformativeExtractRequest_ThenAlsoContainsChangeFiles()
{
var fixture = new RoadNetworkTestData().ObjectProvider;
fixture.CustomizeNtsPolygon();

var zipArchiveWriter = new RoadNetworkExtractToZipArchiveWriter(
_zipArchiveWriterOptions,
_streetNameCache,
_memoryStreamManager,
Encoding.UTF8,
NullLogger<RoadNetworkExtractToZipArchiveWriter>.Instance);

var stream = _memoryStreamManager.GetStream();

using var archive = new ZipArchive(stream, ZipArchiveMode.Update, true, Encoding.UTF8);
var request = new RoadNetworkExtractAssemblyRequest(
fixture.Create<ExternalExtractRequestId>(),
fixture.Create<DownloadId>(),
fixture.Create<ExtractDescription>(),
fixture.Create<IPolygonal>(),
isInformative: false);
await zipArchiveWriter.WriteAsync(archive, request, _zipArchiveDataProvider.Object, CancellationToken.None);

var fileNames = archive.Entries.Select(x => x.FullName).ToList();
Expand Down

0 comments on commit f32a5ca

Please sign in to comment.