diff --git a/src/RoadRegistry.BackOffice.Abstractions/EndpointRequestHandler.cs b/src/RoadRegistry.BackOffice.Abstractions/EndpointRequestHandler.cs index c754ba7f0..6fb8b3af6 100644 --- a/src/RoadRegistry.BackOffice.Abstractions/EndpointRequestHandler.cs +++ b/src/RoadRegistry.BackOffice.Abstractions/EndpointRequestHandler.cs @@ -29,7 +29,7 @@ public override async Task Handle(TRequest request, CancellationToken Dispatch = async (command, token) => await HandleInitializer(command, token); Queue = async (command, token) => await HandleInitializer(command, token); - var response = await HandleAsync(request, cancellationToken); + var response = await InnerHandleAsync(request, cancellationToken); return response; async Task HandleInitializer(Command command, CancellationToken token) diff --git a/src/RoadRegistry.BackOffice.Abstractions/RequestHandler.cs b/src/RoadRegistry.BackOffice.Abstractions/RequestHandler.cs index 3073b22ee..d673ab86d 100644 --- a/src/RoadRegistry.BackOffice.Abstractions/RequestHandler.cs +++ b/src/RoadRegistry.BackOffice.Abstractions/RequestHandler.cs @@ -15,9 +15,9 @@ protected RequestHandler(ILogger logger) public virtual async Task Handle(TRequest request, CancellationToken cancellationToken) { - var response = await HandleAsync(request, cancellationToken); + var response = await InnerHandleAsync(request, cancellationToken); return response; } - public abstract Task HandleAsync(TRequest request, CancellationToken cancellationToken); + protected abstract Task InnerHandleAsync(TRequest request, CancellationToken cancellationToken); } diff --git a/src/RoadRegistry.BackOffice.Handlers/Downloads/DownloadEditorRequestHandler.cs b/src/RoadRegistry.BackOffice.Handlers/Downloads/DownloadEditorRequestHandler.cs index 997468eff..7c61e415d 100644 --- a/src/RoadRegistry.BackOffice.Handlers/Downloads/DownloadEditorRequestHandler.cs +++ b/src/RoadRegistry.BackOffice.Handlers/Downloads/DownloadEditorRequestHandler.cs @@ -38,7 +38,7 @@ public DownloadEditorRequestHandler( _cache = cache; } - public override async Task HandleAsync(DownloadEditorRequest request, CancellationToken cancellationToken) + protected override async Task InnerHandleAsync(DownloadEditorRequest request, CancellationToken cancellationToken) { var info = await _context.RoadNetworkInfo.SingleOrDefaultAsync(cancellationToken); diff --git a/src/RoadRegistry.BackOffice.Handlers/Downloads/DownloadProductRequestHandler.cs b/src/RoadRegistry.BackOffice.Handlers/Downloads/DownloadProductRequestHandler.cs index 77c5f3505..ab77644e8 100644 --- a/src/RoadRegistry.BackOffice.Handlers/Downloads/DownloadProductRequestHandler.cs +++ b/src/RoadRegistry.BackOffice.Handlers/Downloads/DownloadProductRequestHandler.cs @@ -40,7 +40,7 @@ public DownloadProductRequestHandler( _cache = cache; } - public override async Task HandleAsync(DownloadProductRequest request, CancellationToken cancellationToken) + protected override async Task InnerHandleAsync(DownloadProductRequest request, CancellationToken cancellationToken) { var info = await _context.RoadNetworkInfo.SingleOrDefaultAsync(cancellationToken); if (info is null || !info.CompletedImport) diff --git a/src/RoadRegistry.BackOffice.Handlers/Extracts/CloseRoadNetworkExtractRequestHandler.cs b/src/RoadRegistry.BackOffice.Handlers/Extracts/CloseRoadNetworkExtractRequestHandler.cs index eebbc7d78..fef05179e 100644 --- a/src/RoadRegistry.BackOffice.Handlers/Extracts/CloseRoadNetworkExtractRequestHandler.cs +++ b/src/RoadRegistry.BackOffice.Handlers/Extracts/CloseRoadNetworkExtractRequestHandler.cs @@ -21,7 +21,7 @@ public CloseRoadNetworkExtractRequestHandler( _editorContext = editorContext; } - public override async Task HandleAsync(CloseRoadNetworkExtractRequest request, CancellationToken cancellationToken) + protected override async Task InnerHandleAsync(CloseRoadNetworkExtractRequest request, CancellationToken cancellationToken) { var extractRequest = await _editorContext.ExtractRequests.FindAsync(request.DownloadId.ToGuid(), cancellationToken: cancellationToken); if (extractRequest is null) diff --git a/src/RoadRegistry.BackOffice.Handlers/Extracts/DownloadExtractByContourRequestHandler.cs b/src/RoadRegistry.BackOffice.Handlers/Extracts/DownloadExtractByContourRequestHandler.cs index 18d5a7626..bf5643058 100644 --- a/src/RoadRegistry.BackOffice.Handlers/Extracts/DownloadExtractByContourRequestHandler.cs +++ b/src/RoadRegistry.BackOffice.Handlers/Extracts/DownloadExtractByContourRequestHandler.cs @@ -21,7 +21,7 @@ public DownloadExtractByContourRequestHandler( _reader = reader ?? throw new ArgumentNullException(nameof(reader)); } - public override async Task HandleRequestAsync(DownloadExtractByContourRequest request, DownloadId downloadId, string randomExternalRequestId, CancellationToken cancellationToken) + protected override async Task HandleRequestAsync(DownloadExtractByContourRequest request, DownloadId downloadId, string randomExternalRequestId, CancellationToken cancellationToken) { var geometry = _reader.Read(request.Contour).ToMultiPolygon(); diff --git a/src/RoadRegistry.BackOffice.Handlers/Extracts/DownloadExtractByFileRequestHandler.cs b/src/RoadRegistry.BackOffice.Handlers/Extracts/DownloadExtractByFileRequestHandler.cs index 2550f9c83..37917ec91 100644 --- a/src/RoadRegistry.BackOffice.Handlers/Extracts/DownloadExtractByFileRequestHandler.cs +++ b/src/RoadRegistry.BackOffice.Handlers/Extracts/DownloadExtractByFileRequestHandler.cs @@ -19,7 +19,7 @@ public DownloadExtractByFileRequestHandler( _translator = translator; } - public override async Task HandleRequestAsync(DownloadExtractByFileRequest request, DownloadId downloadId, string randomExternalRequestId, CancellationToken cancellationToken) + protected override async Task HandleRequestAsync(DownloadExtractByFileRequest request, DownloadId downloadId, string randomExternalRequestId, CancellationToken cancellationToken) { var contour = _translator.Translate(request.ShpFile, request.Buffer); diff --git a/src/RoadRegistry.BackOffice.Handlers/Extracts/DownloadExtractByNisCodeRequestHandler.cs b/src/RoadRegistry.BackOffice.Handlers/Extracts/DownloadExtractByNisCodeRequestHandler.cs index 8e5d107e4..fa108ade2 100644 --- a/src/RoadRegistry.BackOffice.Handlers/Extracts/DownloadExtractByNisCodeRequestHandler.cs +++ b/src/RoadRegistry.BackOffice.Handlers/Extracts/DownloadExtractByNisCodeRequestHandler.cs @@ -18,7 +18,7 @@ public DownloadExtractByNisCodeRequestHandler( { } - public override async Task HandleRequestAsync(DownloadExtractByNisCodeRequest request, DownloadId downloadId, string randomExternalRequestId, CancellationToken cancellationToken) + protected override async Task HandleRequestAsync(DownloadExtractByNisCodeRequest request, DownloadId downloadId, string randomExternalRequestId, CancellationToken cancellationToken) { var municipalityGeometry = await _context.MunicipalityGeometries.SingleOrDefaultAsync(x => x.NisCode == request.NisCode, cancellationToken) ?? throw new DownloadExtractByNisCodeNotFoundException("Could not find details about the supplied NIS code"); diff --git a/src/RoadRegistry.BackOffice.Handlers/Extracts/DownloadExtractRequestHandler.cs b/src/RoadRegistry.BackOffice.Handlers/Extracts/DownloadExtractRequestHandler.cs index 3711bba2c..31c3fd663 100644 --- a/src/RoadRegistry.BackOffice.Handlers/Extracts/DownloadExtractRequestHandler.cs +++ b/src/RoadRegistry.BackOffice.Handlers/Extracts/DownloadExtractRequestHandler.cs @@ -21,7 +21,7 @@ public DownloadExtractRequestHandler( _reader = reader ?? throw new ArgumentNullException(nameof(reader)); } - public override async Task HandleRequestAsync(DownloadExtractRequest request, DownloadId downloadId, string randomExternalRequestId, CancellationToken cancellationToken) + protected override async Task HandleRequestAsync(DownloadExtractRequest request, DownloadId downloadId, string randomExternalRequestId, CancellationToken cancellationToken) { var message = new RequestRoadNetworkExtract { diff --git a/src/RoadRegistry.BackOffice.Handlers/Extracts/DownloadFileContentRequestHandler.cs b/src/RoadRegistry.BackOffice.Handlers/Extracts/DownloadFileContentRequestHandler.cs index eb91289f5..4c8be6be8 100644 --- a/src/RoadRegistry.BackOffice.Handlers/Extracts/DownloadFileContentRequestHandler.cs +++ b/src/RoadRegistry.BackOffice.Handlers/Extracts/DownloadFileContentRequestHandler.cs @@ -28,7 +28,7 @@ public DownloadFileContentRequestHandler( _client = client ?? throw new ArgumentNullException(nameof(client)); } - public override async Task HandleAsync(DownloadFileContentRequest request, CancellationToken cancellationToken) + protected override async Task InnerHandleAsync(DownloadFileContentRequest request, CancellationToken cancellationToken) { if (request.DownloadId is null) { diff --git a/src/RoadRegistry.BackOffice.Handlers/Extracts/ExtractDetailsRequestHandler.cs b/src/RoadRegistry.BackOffice.Handlers/Extracts/ExtractDetailsRequestHandler.cs index 8ccbe4673..f27a10f89 100644 --- a/src/RoadRegistry.BackOffice.Handlers/Extracts/ExtractDetailsRequestHandler.cs +++ b/src/RoadRegistry.BackOffice.Handlers/Extracts/ExtractDetailsRequestHandler.cs @@ -21,7 +21,7 @@ public ExtractDetailsRequestHandler( { } - public override async Task HandleAsync(ExtractDetailsRequest request, CancellationToken cancellationToken) + protected override async Task InnerHandleAsync(ExtractDetailsRequest request, CancellationToken cancellationToken) { var record = await Context.ExtractRequests.FindAsync(new object[] { request.DownloadId.ToGuid() }, cancellationToken); diff --git a/src/RoadRegistry.BackOffice.Handlers/Extracts/ExtractRequestHandler.cs b/src/RoadRegistry.BackOffice.Handlers/Extracts/ExtractRequestHandler.cs index e66e3535a..219dc1d0f 100644 --- a/src/RoadRegistry.BackOffice.Handlers/Extracts/ExtractRequestHandler.cs +++ b/src/RoadRegistry.BackOffice.Handlers/Extracts/ExtractRequestHandler.cs @@ -2,7 +2,6 @@ namespace RoadRegistry.BackOffice.Handlers.Extracts; using Abstractions; using Editor.Schema; -using Editor.Schema.Extracts; using Framework; using Microsoft.Extensions.Logging; @@ -20,7 +19,7 @@ protected ExtractRequestHandler( _context = context ?? throw new ArgumentNullException(nameof(context)); } - public override async Task HandleAsync(TRequest request, CancellationToken cancellationToken) + protected override async Task InnerHandleAsync(TRequest request, CancellationToken cancellationToken) { var downloadId = new DownloadId(Guid.NewGuid()); var randomExternalRequestId = Guid.NewGuid().ToString("N"); @@ -28,5 +27,5 @@ public override async Task HandleAsync(TRequest request, Cancellation return await HandleRequestAsync(request, downloadId, randomExternalRequestId, cancellationToken); } - public abstract Task HandleRequestAsync(TRequest request, DownloadId downloadId, string randomExternalRequestId, CancellationToken cancellationToken); + protected abstract Task HandleRequestAsync(TRequest request, DownloadId downloadId, string randomExternalRequestId, CancellationToken cancellationToken); } diff --git a/src/RoadRegistry.BackOffice.Handlers/Extracts/GetOverlappingTransactionZonesByContourRequestHandler.cs b/src/RoadRegistry.BackOffice.Handlers/Extracts/GetOverlappingTransactionZonesByContourRequestHandler.cs index 37c4386b0..af63995c4 100644 --- a/src/RoadRegistry.BackOffice.Handlers/Extracts/GetOverlappingTransactionZonesByContourRequestHandler.cs +++ b/src/RoadRegistry.BackOffice.Handlers/Extracts/GetOverlappingTransactionZonesByContourRequestHandler.cs @@ -21,7 +21,7 @@ public GetOverlappingTransactionZonesByContourRequestHandler( _context = context; } - public override async Task HandleAsync(GetOverlappingTransactionZonesByContourRequest request, CancellationToken cancellationToken) + protected override async Task InnerHandleAsync(GetOverlappingTransactionZonesByContourRequest request, CancellationToken cancellationToken) { var geometry = new WKTReader().Read(request.Contour); diff --git a/src/RoadRegistry.BackOffice.Handlers/Extracts/GetOverlappingTransactionZonesByNisCodeRequestHandler.cs b/src/RoadRegistry.BackOffice.Handlers/Extracts/GetOverlappingTransactionZonesByNisCodeRequestHandler.cs index 4b284ae44..9efcbc132 100644 --- a/src/RoadRegistry.BackOffice.Handlers/Extracts/GetOverlappingTransactionZonesByNisCodeRequestHandler.cs +++ b/src/RoadRegistry.BackOffice.Handlers/Extracts/GetOverlappingTransactionZonesByNisCodeRequestHandler.cs @@ -23,7 +23,7 @@ public GetOverlappingTransactionZonesByNisCodeRequestHandler( private record ExtractRequestIntersection(ExtractRequestRecord ExtractRequest, Geometry Intersection); - public override async Task HandleAsync(GetOverlappingTransactionZonesByNisCodeRequest request, CancellationToken cancellationToken) + protected override async Task InnerHandleAsync(GetOverlappingTransactionZonesByNisCodeRequest request, CancellationToken cancellationToken) { var extractRequestsQuery = _context.ExtractRequests.Where(x => !x.IsInformative); diff --git a/src/RoadRegistry.BackOffice.Handlers/Extracts/GetOverlappingTransactionZonesGeoJsonRequestHandler.cs b/src/RoadRegistry.BackOffice.Handlers/Extracts/GetOverlappingTransactionZonesGeoJsonRequestHandler.cs index a7e7b3e8c..ab4ebd252 100644 --- a/src/RoadRegistry.BackOffice.Handlers/Extracts/GetOverlappingTransactionZonesGeoJsonRequestHandler.cs +++ b/src/RoadRegistry.BackOffice.Handlers/Extracts/GetOverlappingTransactionZonesGeoJsonRequestHandler.cs @@ -22,7 +22,7 @@ public GetOverlappingTransactionZonesGeoJsonRequestHandler( _context = context; } - public override async Task HandleAsync(GetOverlappingTransactionZonesGeoJsonRequest request, CancellationToken cancellationToken) + protected override async Task InnerHandleAsync(GetOverlappingTransactionZonesGeoJsonRequest request, CancellationToken cancellationToken) { var availableOverlaps = await ( from overlap in _context.ExtractRequestOverlaps diff --git a/src/RoadRegistry.BackOffice.Handlers/Extracts/GetTransactionZonesGeoJsonRequestHandler.cs b/src/RoadRegistry.BackOffice.Handlers/Extracts/GetTransactionZonesGeoJsonRequestHandler.cs index b905fcac1..1bccf3178 100644 --- a/src/RoadRegistry.BackOffice.Handlers/Extracts/GetTransactionZonesGeoJsonRequestHandler.cs +++ b/src/RoadRegistry.BackOffice.Handlers/Extracts/GetTransactionZonesGeoJsonRequestHandler.cs @@ -22,12 +22,12 @@ public GetTransactionZonesGeoJsonRequestHandler( _context = context; } - public override async Task HandleAsync(GetTransactionZonesGeoJsonRequest request, CancellationToken cancellationToken) + protected override async Task InnerHandleAsync(GetTransactionZonesGeoJsonRequest request, CancellationToken cancellationToken) { var transactionZones = await _context.ExtractRequests .Where(x => !x.IsInformative) .ToListAsync(cancellationToken); - + return new GetTransactionZonesGeoJsonResponse { FeatureCollection = new FeatureCollection(transactionZones diff --git a/src/RoadRegistry.BackOffice.Handlers/Extracts/UploadExtractRequestHandler.cs b/src/RoadRegistry.BackOffice.Handlers/Extracts/UploadExtractRequestHandler.cs index 43cc69bcb..a28512893 100644 --- a/src/RoadRegistry.BackOffice.Handlers/Extracts/UploadExtractRequestHandler.cs +++ b/src/RoadRegistry.BackOffice.Handlers/Extracts/UploadExtractRequestHandler.cs @@ -44,7 +44,7 @@ public UploadExtractRequestHandler( _context = context ?? throw new EditorContextNotFoundException(nameof(context)); } - public override async Task HandleAsync(UploadExtractRequest request, CancellationToken cancellationToken) + protected override async Task InnerHandleAsync(UploadExtractRequest request, CancellationToken cancellationToken) { if (!ContentType.TryParse(request.Archive.ContentType, out var parsedContentType) || !SupportedContentTypes.Contains(parsedContentType)) { @@ -61,20 +61,21 @@ public override async Task HandleAsync(UploadExtractReque throw new InvalidGuidValidationException(nameof(request.DownloadId)); } - var extractRequest = await _context.ExtractRequests.FindAsync(new object[] { downloadId.ToGuid() }, cancellationToken); - if (extractRequest is null) + var download = await _context.ExtractDownloads.FindAsync(new object[] { downloadId.ToGuid() }, cancellationToken); + if (download is null) { throw new ExtractDownloadNotFoundException(downloadId); } - if (extractRequest.IsInformative) + + var previousUpload = await _context.ExtractUploads.IncludeLocalSingleOrDefaultAsync(x => x.RequestId == download.RequestId, cancellationToken); + if (previousUpload is not null) { - throw new ExtractRequestMarkedInformativeException(downloadId); + throw new CanNotUploadRoadNetworkExtractChangesArchiveForSameDownloadMoreThanOnceException(); } - var download = await _context.ExtractDownloads.FindAsync(new object[] { downloadId.ToGuid() }, cancellationToken); - if (download is null) + if (download.IsInformative) { - throw new ExtractDownloadNotFoundException(downloadId); + throw new ExtractRequestMarkedInformativeException(downloadId); } await using var readStream = await request.Archive.ReadStream.CopyToNewMemoryStream(cancellationToken); diff --git a/src/RoadRegistry.BackOffice.Handlers/Extracts/UploadStatusRequestHandler.cs b/src/RoadRegistry.BackOffice.Handlers/Extracts/UploadStatusRequestHandler.cs index 1290c7f3d..5630dbda0 100644 --- a/src/RoadRegistry.BackOffice.Handlers/Extracts/UploadStatusRequestHandler.cs +++ b/src/RoadRegistry.BackOffice.Handlers/Extracts/UploadStatusRequestHandler.cs @@ -21,7 +21,7 @@ public UploadStatusRequestHandler( { } - public override async Task HandleAsync(UploadStatusRequest request, CancellationToken cancellationToken) + protected override async Task InnerHandleAsync(UploadStatusRequest request, CancellationToken cancellationToken) { if (!Guid.TryParseExact(request.UploadId, "N", out var parsedUploadId)) { diff --git a/src/RoadRegistry.BackOffice.Handlers/Information/ValidateWktContourRequestHandler.cs b/src/RoadRegistry.BackOffice.Handlers/Information/ValidateWktContourRequestHandler.cs index 0e641e52f..357ad2322 100644 --- a/src/RoadRegistry.BackOffice.Handlers/Information/ValidateWktContourRequestHandler.cs +++ b/src/RoadRegistry.BackOffice.Handlers/Information/ValidateWktContourRequestHandler.cs @@ -27,7 +27,7 @@ public ValidateWktContourRequestHandler( _reader = reader ?? throw new ArgumentNullException(nameof(reader)); } - public override Task HandleAsync(ValidateWktContourRequest request, CancellationToken cancellationToken) + protected override Task InnerHandleAsync(ValidateWktContourRequest request, CancellationToken cancellationToken) { var geometry = _reader.Read(request.Contour); diff --git a/src/RoadRegistry.BackOffice.Handlers/Organizations/GetOrganizationsRequestHandler.cs b/src/RoadRegistry.BackOffice.Handlers/Organizations/GetOrganizationsRequestHandler.cs index 3da787154..6b0dafc27 100644 --- a/src/RoadRegistry.BackOffice.Handlers/Organizations/GetOrganizationsRequestHandler.cs +++ b/src/RoadRegistry.BackOffice.Handlers/Organizations/GetOrganizationsRequestHandler.cs @@ -27,7 +27,7 @@ public GetOrganizationsRequestHandler(CommandHandlerDispatcher dispatcher, _fileEncoding = fileEncoding; } - public override async Task HandleAsync(GetOrganizationsRequest request, CancellationToken cancellationToken) + protected override async Task InnerHandleAsync(GetOrganizationsRequest request, CancellationToken cancellationToken) { var organizationRecordReader = new OrganizationDbaseRecordReader(_manager, _fileEncoding); @@ -38,7 +38,7 @@ await _editorContext.Organizations ) .Select(organization => organizationRecordReader.Read(organization.DbaseRecord, organization.DbaseSchemaVersion)) .ToList(); - + return new GetOrganizationsResponse(organizations); } } diff --git a/src/RoadRegistry.BackOffice.Handlers/RoadSegments/RoadSegmentDetailRequestHandler.cs b/src/RoadRegistry.BackOffice.Handlers/RoadSegments/RoadSegmentDetailRequestHandler.cs index d34abe223..59e9e9654 100644 --- a/src/RoadRegistry.BackOffice.Handlers/RoadSegments/RoadSegmentDetailRequestHandler.cs +++ b/src/RoadRegistry.BackOffice.Handlers/RoadSegments/RoadSegmentDetailRequestHandler.cs @@ -34,7 +34,7 @@ public RoadSegmentDetailRequestHandler(CommandHandlerDispatcher dispatcher, _streetNameCache = streetNameCache; } - public override async Task HandleAsync(RoadSegmentDetailRequest request, CancellationToken cancellationToken) + protected override async Task InnerHandleAsync(RoadSegmentDetailRequest request, CancellationToken cancellationToken) { var roadSegment = await _editorContext.RoadSegments .IgnoreQueryFilters() @@ -68,7 +68,7 @@ string GetStreetName(int? id) .ToListAsync(cancellationToken: cancellationToken)) .Select(x => new RoadSegmentSurfaceAttributeDbaseRecord().FromBytes(x.DbaseRecord, _manager, _fileEncoding)) .ToList(); - + var widths = (await _editorContext.RoadSegmentWidthAttributes .Where(x => x.RoadSegmentId == roadSegment.Id) .ToListAsync(cancellationToken: cancellationToken)) diff --git a/src/RoadRegistry.BackOffice.Handlers/Uploads/DownloadExtractRequestHandler.cs b/src/RoadRegistry.BackOffice.Handlers/Uploads/DownloadExtractRequestHandler.cs index 925058dfc..0da764915 100644 --- a/src/RoadRegistry.BackOffice.Handlers/Uploads/DownloadExtractRequestHandler.cs +++ b/src/RoadRegistry.BackOffice.Handlers/Uploads/DownloadExtractRequestHandler.cs @@ -30,7 +30,7 @@ public DownloadExtractRequestHandler( _client = client ?? throw new BlobClientNotFoundException(nameof(client)); } - public override async Task HandleAsync(DownloadExtractRequest request, CancellationToken cancellationToken) + protected override async Task InnerHandleAsync(DownloadExtractRequest request, CancellationToken cancellationToken) { if (!ArchiveId.Accepts(request.Identifier)) throw new ValidationException(new[] diff --git a/src/RoadRegistry.BackOffice.Handlers/Uploads/UploadExtractRequestHandler.cs b/src/RoadRegistry.BackOffice.Handlers/Uploads/UploadExtractRequestHandler.cs index 5e039eb14..52c061202 100644 --- a/src/RoadRegistry.BackOffice.Handlers/Uploads/UploadExtractRequestHandler.cs +++ b/src/RoadRegistry.BackOffice.Handlers/Uploads/UploadExtractRequestHandler.cs @@ -54,7 +54,7 @@ public UploadExtractRequestHandler( _beforeFeatureCompareZipArchiveCleaner = beforeFeatureCompareZipArchiveCleaner.ThrowIfNull(); } - public override async Task HandleAsync(UploadExtractRequest request, CancellationToken cancellationToken) + protected override async Task InnerHandleAsync(UploadExtractRequest request, CancellationToken cancellationToken) { if (!ContentType.TryParse(request.Archive.ContentType, out var parsed) || !SupportedContentTypes.Contains(parsed)) { diff --git a/src/RoadRegistry.BackOffice/Extracts/CanNotUploadRoadNetworkExtractChangesArchiveForSameDownloadMoreThanOnceException.cs b/src/RoadRegistry.BackOffice/Extracts/CanNotUploadRoadNetworkExtractChangesArchiveForSameDownloadMoreThanOnceException.cs index 6fefdfa02..a7903c214 100644 --- a/src/RoadRegistry.BackOffice/Extracts/CanNotUploadRoadNetworkExtractChangesArchiveForSameDownloadMoreThanOnceException.cs +++ b/src/RoadRegistry.BackOffice/Extracts/CanNotUploadRoadNetworkExtractChangesArchiveForSameDownloadMoreThanOnceException.cs @@ -6,22 +6,13 @@ namespace RoadRegistry.BackOffice.Extracts; [Serializable] public class CanNotUploadRoadNetworkExtractChangesArchiveForSameDownloadMoreThanOnceException : Exception { - public CanNotUploadRoadNetworkExtractChangesArchiveForSameDownloadMoreThanOnceException(ExternalExtractRequestId externalRequestId, ExtractRequestId requestId, DownloadId downloadId, UploadId uploadId) + public CanNotUploadRoadNetworkExtractChangesArchiveForSameDownloadMoreThanOnceException() : base("Can not upload a road network extract changes archive for the same download more than once.") { - ExternalRequestId = externalRequestId; - RequestId = requestId; - DownloadId = downloadId; - UploadId = uploadId; } protected CanNotUploadRoadNetworkExtractChangesArchiveForSameDownloadMoreThanOnceException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext) { } - - public DownloadId DownloadId { get; } - public ExternalExtractRequestId ExternalRequestId { get; } - public ExtractRequestId RequestId { get; } - public UploadId UploadId { get; } -} \ No newline at end of file +} diff --git a/src/RoadRegistry.BackOffice/Extracts/RoadNetworkExtract.cs b/src/RoadRegistry.BackOffice/Extracts/RoadNetworkExtract.cs index 075cfffee..cb12aa33a 100644 --- a/src/RoadRegistry.BackOffice/Extracts/RoadNetworkExtract.cs +++ b/src/RoadRegistry.BackOffice/Extracts/RoadNetworkExtract.cs @@ -155,8 +155,7 @@ public RoadNetworkExtractUpload Upload(DownloadId downloadId, UploadId uploadId, _externalExtractRequestId, Id, downloadId, _requestedDownloads[^1], uploadId); if (_knownUploads.Count == 1) - throw new CanNotUploadRoadNetworkExtractChangesArchiveForSameDownloadMoreThanOnceException( - _externalExtractRequestId, Id, downloadId, uploadId); + throw new CanNotUploadRoadNetworkExtractChangesArchiveForSameDownloadMoreThanOnceException(); Apply(new RoadNetworkExtractChangesArchiveUploaded { diff --git a/test/RoadRegistry.BackOffice.Handlers.Tests/Extracts/WhenRequestingOverlappingTransactionZones/ByContour.cs b/test/RoadRegistry.BackOffice.Handlers.Tests/Extracts/WhenRequestingOverlappingTransactionZones/ByContour.cs index 40308c88a..cb0fa5918 100644 --- a/test/RoadRegistry.BackOffice.Handlers.Tests/Extracts/WhenRequestingOverlappingTransactionZones/ByContour.cs +++ b/test/RoadRegistry.BackOffice.Handlers.Tests/Extracts/WhenRequestingOverlappingTransactionZones/ByContour.cs @@ -38,7 +38,7 @@ public async Task WhenOverlap_ThenReturnExpectedResult() // Act var handler = new GetOverlappingTransactionZonesByContourRequestHandler(editorContext, null, new NullLogger()); - var result = await handler.HandleAsync(request, CancellationToken.None); + var result = await handler.Handle(request, CancellationToken.None); // Assert result.DownloadIds.Should().HaveCount(1); @@ -81,7 +81,7 @@ public async Task WhenOverlapWithInformativeExtract_ThenReturnExpectedResult() // Act var handler = new GetOverlappingTransactionZonesByContourRequestHandler(editorContext, null, new NullLogger()); - var result = await handler.HandleAsync(request, CancellationToken.None); + var result = await handler.Handle(request, CancellationToken.None); // Assert result.DownloadIds.Should().HaveCount(1); @@ -112,7 +112,7 @@ public async Task WhenNoOverlap_ThenNone() // Act var handler = new GetOverlappingTransactionZonesByContourRequestHandler(editorContext, null, new NullLogger()); - var result = await handler.HandleAsync(request, CancellationToken.None); + var result = await handler.Handle(request, CancellationToken.None); // Assert result.DownloadIds.Should().BeEmpty(); @@ -142,7 +142,7 @@ public async Task WhenOverlapOnlyOnTheBorder_ThenNone() // Act var handler = new GetOverlappingTransactionZonesByContourRequestHandler(editorContext, null, new NullLogger()); - var result = await handler.HandleAsync(request, CancellationToken.None); + var result = await handler.Handle(request, CancellationToken.None); // Assert result.DownloadIds.Should().BeEmpty(); diff --git a/test/RoadRegistry.BackOffice.Handlers.Tests/Extracts/WhenRequestingOverlappingTransactionZones/ByNisCode.cs b/test/RoadRegistry.BackOffice.Handlers.Tests/Extracts/WhenRequestingOverlappingTransactionZones/ByNisCode.cs index f1c4aaaac..ea251ab48 100644 --- a/test/RoadRegistry.BackOffice.Handlers.Tests/Extracts/WhenRequestingOverlappingTransactionZones/ByNisCode.cs +++ b/test/RoadRegistry.BackOffice.Handlers.Tests/Extracts/WhenRequestingOverlappingTransactionZones/ByNisCode.cs @@ -38,7 +38,7 @@ public async Task WhenUnknownNisCode_ThenNone() // Act var handler = new GetOverlappingTransactionZonesByNisCodeRequestHandler(editorContext, null, new NullLogger()); - var result = await handler.HandleAsync(request, CancellationToken.None); + var result = await handler.Handle(request, CancellationToken.None); // Assert result.DownloadIds.Should().BeEmpty(); @@ -85,7 +85,7 @@ public async Task WhenOverlapWithoutBufferWithInformativeExtract_ThenReturnExpec // Act var handler = new GetOverlappingTransactionZonesByNisCodeRequestHandler(editorContext, null, new NullLogger()); - var result = await handler.HandleAsync(request, CancellationToken.None); + var result = await handler.Handle(request, CancellationToken.None); // Assert result.DownloadIds.Should().HaveCount(1); @@ -123,7 +123,7 @@ public async Task WhenOverlapWithoutBuffer_ThenReturnExpectedResult() // Act var handler = new GetOverlappingTransactionZonesByNisCodeRequestHandler(editorContext, null, new NullLogger()); - var result = await handler.HandleAsync(request, CancellationToken.None); + var result = await handler.Handle(request, CancellationToken.None); // Assert result.DownloadIds.Should().HaveCount(1); @@ -162,7 +162,7 @@ public async Task WhenOverlapWithBuffer_ThenReturnExpectedResult() // Act var handler = new GetOverlappingTransactionZonesByNisCodeRequestHandler(editorContext, null, new NullLogger()); - var result = await handler.HandleAsync(request, CancellationToken.None); + var result = await handler.Handle(request, CancellationToken.None); // Assert result.DownloadIds.Should().HaveCount(1); @@ -201,7 +201,7 @@ public async Task WhenOnlyBufferedNisCodeOverlaps_ThenReturnExpectedResult() // Act var handler = new GetOverlappingTransactionZonesByNisCodeRequestHandler(editorContext, null, new NullLogger()); - var result = await handler.HandleAsync(request, CancellationToken.None); + var result = await handler.Handle(request, CancellationToken.None); // Assert result.DownloadIds.Should().HaveCount(1); @@ -237,7 +237,7 @@ public async Task WhenNoOverlapWithoutBuffer_ThenNone() // Act var handler = new GetOverlappingTransactionZonesByNisCodeRequestHandler(editorContext, null, new NullLogger()); - var result = await handler.HandleAsync(request, CancellationToken.None); + var result = await handler.Handle(request, CancellationToken.None); // Assert result.DownloadIds.Should().BeEmpty(); @@ -273,7 +273,7 @@ public async Task WhenNoOverlapWithBuffer_ThenNone() // Act var handler = new GetOverlappingTransactionZonesByNisCodeRequestHandler(editorContext, null, new NullLogger()); - var result = await handler.HandleAsync(request, CancellationToken.None); + var result = await handler.Handle(request, CancellationToken.None); // Assert result.DownloadIds.Should().BeEmpty(); @@ -308,7 +308,7 @@ public async Task WhenOverlapOnlyOnTheBorder_ThenNone() // Act var handler = new GetOverlappingTransactionZonesByNisCodeRequestHandler(editorContext, null, new NullLogger()); - var result = await handler.HandleAsync(request, CancellationToken.None); + var result = await handler.Handle(request, CancellationToken.None); // Assert result.DownloadIds.Should().BeEmpty(); diff --git a/test/RoadRegistry.BackOffice.Handlers.Tests/Extracts/WhenUploadingExtract/UploadExtractRequestTests.cs b/test/RoadRegistry.BackOffice.Handlers.Tests/Extracts/WhenUploadingExtract/UploadExtractRequestTests.cs new file mode 100644 index 000000000..1d22bc6a5 --- /dev/null +++ b/test/RoadRegistry.BackOffice.Handlers.Tests/Extracts/WhenUploadingExtract/UploadExtractRequestTests.cs @@ -0,0 +1,299 @@ +namespace RoadRegistry.BackOffice.Handlers.Tests.Extracts.WhenUploadingExtract; + +using Abstractions.Exceptions; +using Abstractions.Uploads; +using Autofac; +using AutoFixture; +using BackOffice.Extracts; +using BackOffice.Framework; +using Be.Vlaanderen.Basisregisters.BlobStore; +using Editor.Schema; +using Editor.Schema.Extracts; +using Exceptions; +using FluentAssertions; +using Handlers.Extracts; +using Messages; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using Moq; +using RoadRegistry.Tests.BackOffice.Scenarios; +using Xunit.Abstractions; +using UploadExtractRequest = Abstractions.Extracts.UploadExtractRequest; + +public class UploadExtractRequestTests: RoadNetworkTestBase +{ + public UploadExtractRequestTests(ITestOutputHelper testOutputHelper) + : base(testOutputHelper) + { + } + + [Fact] + public async Task WhenInvalidContentType_ThenUnsupportedMediaTypeException() + { + // Arrange + await using var editorContext = Container.Resolve(); + + var request = new UploadExtractRequest( + ObjectProvider.Create(), + new UploadExtractArchiveRequest("test.zip", null, ContentType.Parse("application/invalid_contenttype")), + null); + + // Act + var sut = new UploadExtractRequestHandler( + null, + new RoadNetworkExtractUploadsBlobClient(Mock.Of()), + editorContext, + Mock.Of>() + ); + + // Assert + await Xunit.Assert.ThrowsAsync(() => + sut.Handle(request, CancellationToken.None)); + } + + [Fact] + public async Task WhenNoDownloadId_ThenDownloadExtractNotFoundException() + { + // Arrange + await using var editorContext = Container.Resolve(); + + var request = new UploadExtractRequest( + null, + new UploadExtractArchiveRequest("test.zip", null, ContentType.Parse("binary/octet-stream")), + null); + + // Act + var sut = new UploadExtractRequestHandler( + null, + new RoadNetworkExtractUploadsBlobClient(Mock.Of()), + editorContext, + Mock.Of>() + ); + + // Assert + await Xunit.Assert.ThrowsAsync(() => + sut.Handle(request, CancellationToken.None)); + } + + [Fact] + public async Task WhenDownloadIdIsNotAGuid_ThenInvalidGuidValidationException() + { + // Arrange + await using var editorContext = Container.Resolve(); + + var request = new UploadExtractRequest( + "abc", + new UploadExtractArchiveRequest("test.zip", null, ContentType.Parse("binary/octet-stream")), + null); + + // Act + var sut = new UploadExtractRequestHandler( + null, + new RoadNetworkExtractUploadsBlobClient(Mock.Of()), + editorContext, + Mock.Of>() + ); + + // Assert + await Xunit.Assert.ThrowsAsync(() => + sut.Handle(request, CancellationToken.None)); + } + + [Fact] + public async Task GivenNoExtractDownload_ThenExtractDownloadNotFoundException() + { + // Arrange + var downloadId = ObjectProvider.Create(); + + await using var editorContext = Container.Resolve(); + + var request = new UploadExtractRequest( + downloadId, + new UploadExtractArchiveRequest("test.zip", null, ContentType.Parse("binary/octet-stream")), + null); + + // Act + var sut = new UploadExtractRequestHandler( + null, + new RoadNetworkExtractUploadsBlobClient(Mock.Of()), + editorContext, + Mock.Of>() + ); + + // Assert + await Xunit.Assert.ThrowsAsync(() => + sut.Handle(request, CancellationToken.None)); + } + + [Fact] + public async Task GivenExtractUpload_ThenCanNotUploadRoadNetworkExtractChangesArchiveForSameDownloadMoreThanOnceException() + { + // Arrange + var downloadId = ObjectProvider.Create(); + var externalRequestId = ObjectProvider.Create(); + var requestId = ExtractRequestId.FromExternalRequestId(externalRequestId); + + await using var editorContext = Container.Resolve(); + editorContext.ExtractDownloads.Add(new ExtractDownloadRecord + { + DownloadId = downloadId, + RequestId = requestId, + ExternalRequestId = externalRequestId, + IsInformative = true + }); + editorContext.ExtractUploads.Add(new ExtractUploadRecord + { + DownloadId = downloadId, + RequestId = requestId, + ExternalRequestId = externalRequestId, + ArchiveId = ObjectProvider.Create(), + ChangeRequestId = requestId + }); + await editorContext.SaveChangesAsync(); + + var request = new UploadExtractRequest( + downloadId, + new UploadExtractArchiveRequest("test.zip", null, ContentType.Parse("binary/octet-stream")), + null); + + // Act + var sut = new UploadExtractRequestHandler( + null, + new RoadNetworkExtractUploadsBlobClient(Mock.Of()), + editorContext, + Mock.Of>() + ); + + // Assert + await Xunit.Assert.ThrowsAsync(() => + sut.Handle(request, CancellationToken.None)); + } + + [Fact] + public async Task GivenInformativeDownload_ThenExtractRequestMarkedInformativeException() + { + // Arrange + var downloadId = ObjectProvider.Create(); + var externalRequestId = ObjectProvider.Create(); + var requestId = ExtractRequestId.FromExternalRequestId(externalRequestId); + + await using var editorContext = Container.Resolve(); + editorContext.ExtractDownloads.Add(new ExtractDownloadRecord + { + DownloadId = downloadId, + RequestId = requestId, + ExternalRequestId = externalRequestId, + IsInformative = true + }); + await editorContext.SaveChangesAsync(); + + var request = new UploadExtractRequest( + downloadId, + new UploadExtractArchiveRequest("test.zip", null, ContentType.Parse("binary/octet-stream")), + null); + + // Act + var sut = new UploadExtractRequestHandler( + null, + new RoadNetworkExtractUploadsBlobClient(Mock.Of()), + editorContext, + Mock.Of>() + ); + + // Assert + await Xunit.Assert.ThrowsAsync(() => + sut.Handle(request, CancellationToken.None)); + } + + [Fact] + public async Task GivenArchiveIsNotValid_ThenUnsupportedMediaTypeException() + { + // Arrange + var downloadId = ObjectProvider.Create(); + var externalRequestId = ObjectProvider.Create(); + var requestId = ExtractRequestId.FromExternalRequestId(externalRequestId); + + await using var editorContext = Container.Resolve(); + editorContext.ExtractDownloads.Add(new ExtractDownloadRecord + { + DownloadId = downloadId, + RequestId = requestId, + ExternalRequestId = externalRequestId, + IsInformative = false + }); + await editorContext.SaveChangesAsync(); + + var request = new UploadExtractRequest( + downloadId, + new UploadExtractArchiveRequest("test.zip", EmbeddedResourceReader.Read("test.txt"), ContentType.Parse("binary/octet-stream")), + null); + + // Act + var sut = new UploadExtractRequestHandler( + null, + new RoadNetworkExtractUploadsBlobClient(Mock.Of()), + editorContext, + Mock.Of>() + ); + + // Assert + await Xunit.Assert.ThrowsAsync(() => + sut.Handle(request, CancellationToken.None)); + } + + [Fact] + public async Task GivenUpload_WhenValid_ThenUploadRoadNetworkExtractChangesArchive() + { + // Arrange + var downloadId = ObjectProvider.Create(); + var externalRequestId = ObjectProvider.Create(); + var requestId = ExtractRequestId.FromExternalRequestId(externalRequestId); + var ticketId = ObjectProvider.Create(); + + await using var editorContext = Container.Resolve(); + editorContext.ExtractDownloads.Add(new ExtractDownloadRecord + { + DownloadId = downloadId, + RequestId = requestId, + ExternalRequestId = externalRequestId, + IsInformative = false + }); + await editorContext.SaveChangesAsync(); + + var request = new UploadExtractRequest( + downloadId, + new UploadExtractArchiveRequest("test.zip", EmbeddedResourceReader.Read("empty.zip"), ContentType.Parse("binary/octet-stream")), + ticketId); + + // Act + var sut = new UploadExtractRequestHandler( + new RoadNetworkCommandQueue(Store, new ApplicationMetadata(RoadRegistryApplication.BackOffice)).WriteAsync, + new RoadNetworkExtractUploadsBlobClient(Mock.Of()), + editorContext, + Mock.Of>() + ); + var response = await sut.Handle(request, CancellationToken.None); + + // Assert + var command = await Store.GetLastMessage(); + command.DownloadId.Should().Be(downloadId.ToGuid()); + command.RequestId.Should().Be(requestId); + command.UploadId.Should().Be(response.UploadId); + command.TicketId.Should().Be(ticketId); + } + + protected override void ConfigureContainer(ContainerBuilder containerBuilder) + { + base.ConfigureContainer(containerBuilder); + + containerBuilder.RegisterInstance(BuildEditorContext()); + } + + private EditorContext BuildEditorContext() + { + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(Guid.NewGuid().ToString()) + .Options; + return new EditorContext(options); + } +} diff --git a/test/RoadRegistry.BackOffice.Handlers.Tests/RoadRegistry.BackOffice.Handlers.Tests.csproj b/test/RoadRegistry.BackOffice.Handlers.Tests/RoadRegistry.BackOffice.Handlers.Tests.csproj index e6ce79015..8dfd80968 100644 --- a/test/RoadRegistry.BackOffice.Handlers.Tests/RoadRegistry.BackOffice.Handlers.Tests.csproj +++ b/test/RoadRegistry.BackOffice.Handlers.Tests/RoadRegistry.BackOffice.Handlers.Tests.csproj @@ -10,7 +10,9 @@ - + + Always + diff --git a/test/RoadRegistry.BackOffice.Handlers.Tests/TestFiles/empty.zip b/test/RoadRegistry.BackOffice.Handlers.Tests/TestFiles/empty.zip new file mode 100644 index 000000000..97f50753a Binary files /dev/null and b/test/RoadRegistry.BackOffice.Handlers.Tests/TestFiles/empty.zip differ diff --git a/test/RoadRegistry.BackOffice.Handlers.Tests/Uploads/UploadExtractTests.cs b/test/RoadRegistry.BackOffice.Handlers.Tests/Uploads/UploadExtractTests.cs index e52f0468c..c41d82990 100644 --- a/test/RoadRegistry.BackOffice.Handlers.Tests/Uploads/UploadExtractTests.cs +++ b/test/RoadRegistry.BackOffice.Handlers.Tests/Uploads/UploadExtractTests.cs @@ -32,7 +32,7 @@ public async Task GivenNotZipFile_ThenThrowsUnsupportedMediaTypeException() ); // Assert - await Assert.ThrowsAsync(() => sut.HandleAsync(request, CancellationToken.None)); + await Assert.ThrowsAsync(() => sut.Handle(request, CancellationToken.None)); } } } diff --git a/test/RoadRegistry.Tests/BackOffice/Scenarios/ExtractScenarios.cs b/test/RoadRegistry.Tests/BackOffice/Scenarios/ExtractScenarios.cs index 6e4434762..f66ecd4ba 100644 --- a/test/RoadRegistry.Tests/BackOffice/Scenarios/ExtractScenarios.cs +++ b/test/RoadRegistry.Tests/BackOffice/Scenarios/ExtractScenarios.cs @@ -359,7 +359,7 @@ await Run(scenario => scenario When = InstantPattern.ExtendedIso.Format(Clock.GetCurrentInstant()) }) .When(TheExternalSystem.UploadsRoadNetworkExtractChangesArchive(extractRequestId, downloadId, uploadId, archiveId)) - .Throws(new CanNotUploadRoadNetworkExtractChangesArchiveForSameDownloadMoreThanOnceException(externalExtractRequestId, extractRequestId, downloadId, uploadId)) + .Throws(new CanNotUploadRoadNetworkExtractChangesArchiveForSameDownloadMoreThanOnceException()) ); }