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

Rename streetname #328

Merged
merged 8 commits into from
Nov 28, 2023
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
18 changes: 9 additions & 9 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ nuget Be.Vlaanderen.Basisregisters.DataDog.Tracing.SqlStreamStore 5.0.3

nuget Be.Vlaanderen.Basisregisters.Crab 3.0.0

nuget Be.Vlaanderen.Basisregisters.GrAr.Common 19.0.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Contracts 19.0.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Edit 19.0.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Import 19.0.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Legacy 19.0.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Oslo 19.0.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Provenance 19.0.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Provenance.AcmIdm 19.0.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Extracts 19.0.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Common 20.6.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Contracts 20.6.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Edit 20.6.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Import 20.6.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Legacy 20.6.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Oslo 20.6.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Provenance 20.6.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Provenance.AcmIdm 20.6.0
nuget Be.Vlaanderen.Basisregisters.GrAr.Extracts 20.6.0

nuget Be.Vlaanderen.Basisregisters.MessageHandling.AwsSqs.Simple 4.8.3
nuget Be.Vlaanderen.Basisregisters.MessageHandling.Kafka.Consumer 4.8.3
Expand Down
29 changes: 16 additions & 13 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -281,18 +281,20 @@ NUGET
Autofac.Extensions.DependencyInjection (>= 7.2) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.EventHandling (4.2.3) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.Generators.Guid.Deterministic (3.0.1) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (19.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (20.6)
Be.Vlaanderen.Basisregisters.AggregateSource (>= 8.0) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.CommandHandling (>= 8.0) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
NetTopologySuite (>= 2.4) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
NodaTime (>= 3.0.10) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.GrAr.Contracts (19.0)
Be.Vlaanderen.Basisregisters.GrAr.Contracts (20.6)
Be.Vlaanderen.Basisregisters.AggregateSource (>= 8.0) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
NodaTime (>= 3.0.10) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.GrAr.Edit (19.0)
Be.Vlaanderen.Basisregisters.GrAr.Edit (20.6)
NetTopologySuite (>= 2.4) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.GrAr.Extracts (19.0)
Be.Vlaanderen.Basisregisters.GrAr.Extracts (20.6)
Be.Vlaanderen.Basisregisters.Api (>= 20.0) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.Shaperon (>= 9.0.1) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.GrAr.Import (19.0)
Be.Vlaanderen.Basisregisters.GrAr.Import (20.6)
Autofac (>= 6.3) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.AggregateSource.SqlStreamStore (>= 8.0) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.CommandHandling (>= 8.0) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Expand All @@ -308,27 +310,28 @@ NUGET
Serilog.Extensions.Logging (>= 3.1) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Serilog.Sinks.Email (>= 2.4) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
System.Threading.Tasks.Dataflow (>= 6.0) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.GrAr.Legacy (19.0)
Be.Vlaanderen.Basisregisters.GrAr.Legacy (20.6)
Be.Vlaanderen.Basisregisters.GrAr.Common (20.6) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.Utilities.Rfc3339DateTimeOffset (>= 3.0) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Newtonsoft.Json (>= 13.0.1) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.GrAr.Oslo (19.0)
Be.Vlaanderen.Basisregisters.GrAr.Oslo (20.6)
Be.Vlaanderen.Basisregisters.AspNetCore.Mvc.Formatters.Json (>= 4.0) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (19.0) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (20.6) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.Utilities.Rfc3339DateTimeOffset (>= 3.0) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Microsoft.Extensions.Configuration (>= 6.0.1) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Microsoft.Extensions.Http.Polly (>= 6.0.3) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Newtonsoft.Json (>= 13.0.1) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.GrAr.Provenance (19.0)
Be.Vlaanderen.Basisregisters.GrAr.Provenance (20.6)
Be.Vlaanderen.Basisregisters.CommandHandling (>= 8.0) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.Crab (>= 3.0) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (19.0) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (20.6) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Microsoft.CSharp (>= 4.7) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.GrAr.Provenance.AcmIdm (19.0)
Be.Vlaanderen.Basisregisters.GrAr.Provenance.AcmIdm (20.6)
Be.Vlaanderen.Basisregisters.Auth.AcmIdm (>= 1.4) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.CommandHandling (>= 8.0) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.Crab (>= 3.0) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (19.0) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.GrAr.Provenance (19.0) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.GrAr.Common (20.6) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.GrAr.Provenance (20.6) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Microsoft.CSharp (>= 4.7) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Be.Vlaanderen.Basisregisters.MessageHandling.AwsSqs.Simple (4.8.3)
AWSSDK.Core (>= 3.7.106.8) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace StreetNameRegistry.Api.BackOffice.Abstractions.Requests
{
using System.Runtime.Serialization;
using Newtonsoft.Json;

[DataContract(Name = "HernoemenStraatnaam", Namespace = "")]
public sealed class RenameStreetNameRequest
{
/// <summary>
/// De unieke en persistente identificator van de doelstraatnaam.
/// </summary>
[DataMember(Name = "DoelStraatnaamId", Order = 0)]
[JsonProperty(Required = Required.Always)]
public string DoelStraatnaamId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace StreetNameRegistry.Api.BackOffice.Abstractions.Requests
{
using Swashbuckle.AspNetCore.Filters;

public class RenameStreetNameRequestExamples : IExamplesProvider<RenameStreetNameRequest>
{
public RenameStreetNameRequest GetExamples()
{
return new RenameStreetNameRequest
{
DoelStraatnaamId = "https://data.vlaanderen.be/id/straatnaam/45041"
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace StreetNameRegistry.Api.BackOffice.Abstractions.SqsRequests
{
using Be.Vlaanderen.Basisregisters.Sqs.Requests;
using Requests;

public sealed class RenameStreetNameSqsRequest : SqsRequest, IHasBackOfficeRequest<RenameStreetNameRequest>
{
public int PersistentLocalId { get; set; }

public RenameStreetNameRequest Request { get; init; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public static class MunicipalityHasInvalidStatus
public static TicketError ToTicketError() => new TicketError(Message, Code);
}

public static class StreetNameInvalid
{
public const string Code = "StraatnaamNietGekendValidatie";
public static string Message(string streetNamePuri) => $"De straatnaam '{streetNamePuri}' is niet gekend in het straatnaamregister.";
}

public static class StreetNameNotFound
{
public const string Code = "OnbestaandeStraatnaam";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace StreetNameRegistry.Api.BackOffice.Abstractions.Validation
{
using TicketingService.Abstractions;

public static partial class ValidationErrors
{
public static class RenameStreetName
{
public static class SourceStreetNameHasInvalidStatus
{
public const string Code = "StraatnaamVoorgesteldAfgekeurdOfGehistoreerd";
public const string Message = "Deze actie is enkel toegestaan op straatnamen met status 'inGebruik'.";

public static TicketError ToTicketError() => new TicketError(Message, Code);
}

public static class DestinationStreetNameHasInvalidStatus
{
public const string Code = "StraatnaamAfgekeurdOfGehistoreerd";
public const string Message = "Deze actie is enkel toegestaan op straatnamen met status 'voorgesteld' of 'inGebruik'.";

public static TicketError ToTicketError() => new TicketError(Message, Code);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
namespace StreetNameRegistry.Api.BackOffice.Handlers.Lambda.Handlers
{
using Abstractions.Validation;
using Be.Vlaanderen.Basisregisters.AggregateSource;
using Be.Vlaanderen.Basisregisters.Sqs.Exceptions;
using Be.Vlaanderen.Basisregisters.Sqs.Lambda.Handlers;
using Be.Vlaanderen.Basisregisters.Sqs.Lambda.Infrastructure;
using Be.Vlaanderen.Basisregisters.Sqs.Responses;
using Microsoft.Extensions.Configuration;
using Municipality;
using Municipality.Exceptions;
using Requests;
using TicketingService.Abstractions;

public sealed class RenameStreetNameHandler : StreetNameLambdaHandler<RenameStreetNameLambdaRequest>
{
public RenameStreetNameHandler(
IConfiguration configuration,
ICustomRetryPolicy retryPolicy,
ITicketing ticketing,
IMunicipalities municipalities,
IIdempotentCommandHandler idempotentCommandHandler)
: base(
configuration,
retryPolicy,
municipalities,
ticketing,
idempotentCommandHandler)
{ }

protected override async Task<ETagResponse> InnerHandle(RenameStreetNameLambdaRequest request, CancellationToken cancellationToken)
{
var cmd = request.ToCommand();

try
{
await IdempotentCommandHandler.Dispatch(
cmd.CreateCommandId(),
cmd,
request.Metadata!,
cancellationToken);
}
catch (IdempotencyException)
{
// Idempotent: Do Nothing return last etag
}

var lastHash = await GetStreetNameHash(
request.MunicipalityPersistentLocalId(), new PersistentLocalId(request.StreetNamePersistentLocalId), cancellationToken);
return new ETagResponse(string.Format(DetailUrlFormat, request.StreetNamePersistentLocalId), lastHash);
}

protected override TicketError? InnerMapDomainException(DomainException exception, RenameStreetNameLambdaRequest request)
{
return exception switch
{
StreetNameHasInvalidStatusException ex when ex.PersistentLocalId == request.StreetNamePersistentLocalId =>
ValidationErrors.RenameStreetName.SourceStreetNameHasInvalidStatus.ToTicketError(),
StreetNameHasInvalidStatusException =>
ValidationErrors.RenameStreetName.DestinationStreetNameHasInvalidStatus.ToTicketError(),
MunicipalityHasInvalidStatusException =>
ValidationErrors.Common.MunicipalityStatusNotCurrent.ToTicketError(),
_ => null
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public async Task HandleMessage(object? messageData, MessageMetadata messageMeta
await mediator.Send(new RetireStreetNameLambdaRequest(messageMetadata.MessageGroupId!, request), cancellationToken);
break;

case RenameStreetNameSqsRequest request:
await mediator.Send(new RenameStreetNameLambdaRequest(messageMetadata.MessageGroupId!, request), cancellationToken);
break;

case CorrectStreetNameRetirementSqsRequest request:
await mediator.Send(new CorrectStreetNameRetirementLambdaRequest(messageMetadata.MessageGroupId!, request), cancellationToken);
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
namespace StreetNameRegistry.Api.BackOffice.Handlers.Lambda.Requests
{
using Abstractions;
using Abstractions.Requests;
using Abstractions.SqsRequests;
using Be.Vlaanderen.Basisregisters.GrAr.Common.Oslo.Extensions;
using Be.Vlaanderen.Basisregisters.Sqs.Lambda.Requests;
using Municipality;
using Municipality.Commands;

public sealed record RenameStreetNameLambdaRequest :
SqsLambdaRequest,
IHasBackOfficeRequest<RenameStreetNameRequest>,
IHasStreetNamePersistentLocalId
{
public RenameStreetNameLambdaRequest(string groupId, RenameStreetNameSqsRequest sqsRequest)
: base(
groupId,
sqsRequest.TicketId,
sqsRequest.IfMatchHeaderValue,
sqsRequest.ProvenanceData.ToProvenance(),
sqsRequest.Metadata)
{
Request = sqsRequest.Request;
StreetNamePersistentLocalId = sqsRequest.PersistentLocalId;
}

public RenameStreetNameRequest Request { get; init; }

public int StreetNamePersistentLocalId { get; }

/// <summary>
/// Map to RenameStreetName command
/// </summary>
/// <returns>RenameStreetName.</returns>
public RenameStreetName ToCommand()
{
var identifier = Request.DoelStraatnaamId
.AsIdentifier()
.Map(int.Parse);

return new RenameStreetName(
this.MunicipalityPersistentLocalId(),
new PersistentLocalId(StreetNamePersistentLocalId),
new PersistentLocalId(identifier.Value),
Provenance);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace StreetNameRegistry.Api.BackOffice.Handlers
{
using System.Collections.Generic;
using Be.Vlaanderen.Basisregisters.Sqs;
using Be.Vlaanderen.Basisregisters.Sqs.Handlers;
using Abstractions;
using Abstractions.SqsRequests;
using TicketingService.Abstractions;

public sealed class RenameStreetNameHandler : SqsHandler<RenameStreetNameSqsRequest>
{
public const string Action = "RenameStreetName";

private readonly BackOfficeContext _backOfficeContext;

public RenameStreetNameHandler(
ISqsQueue sqsQueue,
ITicketing ticketing,
ITicketingUrl ticketingUrl,
BackOfficeContext backOfficeContext)
: base (sqsQueue, ticketing, ticketingUrl)
{
_backOfficeContext = backOfficeContext;
}

protected override string? WithAggregateId(RenameStreetNameSqsRequest request)
{
var municipalityIdByPersistentLocalId = _backOfficeContext
.MunicipalityIdByPersistentLocalId
.Find(request.PersistentLocalId);

return municipalityIdByPersistentLocalId?.MunicipalityId.ToString();
}

protected override IDictionary<string, string> WithTicketMetadata(string aggregateId, RenameStreetNameSqsRequest sqsRequest)
{
return new Dictionary<string, string>
{
{ RegistryKey, nameof(StreetNameRegistry) },
{ ActionKey, Action },
{ AggregateIdKey, aggregateId },
{ ObjectIdKey, sqsRequest.PersistentLocalId.ToString() }
};
}
}
}
Loading
Loading