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

feat: add create building oslo snapshots #1279

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
@@ -0,0 +1,11 @@
namespace BuildingRegistry.Api.BackOffice.Abstractions.Building.Requests
{
using System.Collections.Generic;

public class CreateBuildingOsloSnapshotsRequest
{
public List<int> BuildingPersistentLocalIds { get; set; }

public string Reden { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace BuildingRegistry.Api.BackOffice.Abstractions.Building.SqsRequests
{
using Be.Vlaanderen.Basisregisters.Sqs.Requests;
using Requests;

public class CreateBuildingOsloSnapshotsSqsRequest : SqsRequest
{
public CreateBuildingOsloSnapshotsRequest Request { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace BuildingRegistry.Api.BackOffice.Abstractions.BuildingUnit.Requests
{
using System.Collections.Generic;

public class CreateOsloSnapshotsRequest
public class CreateBuildingUnitOsloSnapshotsRequest
{
public List<int> BuildingUnitPersistentLocalIds { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ namespace BuildingRegistry.Api.BackOffice.Abstractions.BuildingUnit.SqsRequests
using Be.Vlaanderen.Basisregisters.Sqs.Requests;
using Requests;

public class CreateOsloSnapshotsSqsRequest : SqsRequest
public class CreateBuildingUnitOsloSnapshotsSqsRequest : SqsRequest
{
public CreateOsloSnapshotsRequest Request { get; set; }
public CreateBuildingUnitOsloSnapshotsRequest Request { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace BuildingRegistry.Api.BackOffice.Handlers.Lambda.Handlers.Building
{
using Be.Vlaanderen.Basisregisters.AggregateSource;
using Be.Vlaanderen.Basisregisters.CommandHandling.Idempotency;
using Be.Vlaanderen.Basisregisters.Sqs.Lambda.Handlers;
using Be.Vlaanderen.Basisregisters.Sqs.Lambda.Infrastructure;
using Requests.Building;
using TicketingService.Abstractions;

public sealed class CreateBuildingOsloSnapshotsLambdaHandler : SqsLambdaHandlerBase<CreateBuildingOsloSnapshotsLambdaRequest>
{
public CreateBuildingOsloSnapshotsLambdaHandler(
ICustomRetryPolicy retryPolicy,
ITicketing ticketing,
IIdempotentCommandHandler idempotentCommandHandler)
: base(retryPolicy, ticketing, idempotentCommandHandler)
{
}

protected override async Task<object> InnerHandle(CreateBuildingOsloSnapshotsLambdaRequest 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
}

return "done";
}

protected override TicketError? MapDomainException(DomainException exception, CreateBuildingOsloSnapshotsLambdaRequest request) => null;

protected override Task HandleAggregateIdIsNotFoundException(CreateBuildingOsloSnapshotsLambdaRequest request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

protected override Task ValidateIfMatchHeaderValue(CreateBuildingOsloSnapshotsLambdaRequest request, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ namespace BuildingRegistry.Api.BackOffice.Handlers.Lambda.Handlers.BuildingUnit
using Requests.BuildingUnit;
using TicketingService.Abstractions;

public sealed class CreateOsloSnapshotsLambdaHandler : SqsLambdaHandlerBase<CreateOsloSnapshotsLambdaRequest>
public sealed class CreateBuildingUnitOsloSnapshotsLambdaHandler : SqsLambdaHandlerBase<CreateBuildingUnitOsloSnapshotsLambdaRequest>
{
public CreateOsloSnapshotsLambdaHandler(
public CreateBuildingUnitOsloSnapshotsLambdaHandler(
ICustomRetryPolicy retryPolicy,
ITicketing ticketing,
IIdempotentCommandHandler idempotentCommandHandler)
: base(retryPolicy, ticketing, idempotentCommandHandler)
{
}

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

Expand All @@ -37,14 +37,14 @@ await IdempotentCommandHandler.Dispatch(
return "done";
}

protected override TicketError? MapDomainException(DomainException exception, CreateOsloSnapshotsLambdaRequest request) => null;
protected override TicketError? MapDomainException(DomainException exception, CreateBuildingUnitOsloSnapshotsLambdaRequest request) => null;

protected override Task HandleAggregateIdIsNotFoundException(CreateOsloSnapshotsLambdaRequest request, CancellationToken cancellationToken)
protected override Task HandleAggregateIdIsNotFoundException(CreateBuildingUnitOsloSnapshotsLambdaRequest request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

protected override Task ValidateIfMatchHeaderValue(CreateOsloSnapshotsLambdaRequest request, CancellationToken cancellationToken)
protected override Task ValidateIfMatchHeaderValue(CreateBuildingUnitOsloSnapshotsLambdaRequest request, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,15 @@ await mediator.Send(new NotifyOutlinedRealizedBuildingLambdaRequest(
new ExtendedWkbGeometry(request.ExtendedWkbGeometry)), cancellationToken);
break;

case CreateOsloSnapshotsSqsRequest request:
case CreateBuildingOsloSnapshotsSqsRequest request:
await mediator.Send(
new CreateOsloSnapshotsLambdaRequest(messageMetadata.MessageGroupId!, request),
new CreateBuildingOsloSnapshotsLambdaRequest(messageMetadata.MessageGroupId!, request),
cancellationToken);
break;

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace BuildingRegistry.Api.BackOffice.Handlers.Lambda.Requests.Building
{
using Be.Vlaanderen.Basisregisters.Sqs.Lambda.Requests;
using BuildingRegistry.AllStream.Commands;
using BuildingRegistry.Api.BackOffice.Abstractions.Building.Requests;
using BuildingRegistry.Api.BackOffice.Abstractions.Building.SqsRequests;
using BuildingRegistry.Building;

public sealed record CreateBuildingOsloSnapshotsLambdaRequest : SqsLambdaRequest
{
public CreateBuildingOsloSnapshotsRequest Request { get; }

public CreateBuildingOsloSnapshotsLambdaRequest(
string messageGroupId,
CreateBuildingOsloSnapshotsSqsRequest sqsRequest)
: base(
messageGroupId,
sqsRequest.TicketId,
null,
sqsRequest.ProvenanceData.ToProvenance(),
sqsRequest.Metadata)
{
Request = sqsRequest.Request;
}

/// <summary>
/// Map to CreateOsloSnapshots command
/// </summary>
/// <returns>CreateOsloSnapshots</returns>
public CreateOsloSnapshots ToCommand()
{
return new CreateOsloSnapshots(
Request.BuildingPersistentLocalIds.Select(x => new BuildingPersistentLocalId(x)),
[],
Provenance);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ namespace BuildingRegistry.Api.BackOffice.Handlers.Lambda.Requests.BuildingUnit
using BuildingRegistry.Api.BackOffice.Abstractions.BuildingUnit.SqsRequests;
using BuildingRegistry.Building;

public sealed record CreateOsloSnapshotsLambdaRequest : SqsLambdaRequest
public sealed record CreateBuildingUnitOsloSnapshotsLambdaRequest : SqsLambdaRequest
{
public CreateOsloSnapshotsRequest Request { get; }
public CreateBuildingUnitOsloSnapshotsRequest Request { get; }

public CreateOsloSnapshotsLambdaRequest(
public CreateBuildingUnitOsloSnapshotsLambdaRequest(
string messageGroupId,
CreateOsloSnapshotsSqsRequest sqsRequest)
CreateBuildingUnitOsloSnapshotsSqsRequest sqsRequest)
: base(
messageGroupId,
sqsRequest.TicketId,
Expand All @@ -30,6 +30,7 @@ public CreateOsloSnapshotsLambdaRequest(
public CreateOsloSnapshots ToCommand()
{
return new CreateOsloSnapshots(
[],
Request.BuildingUnitPersistentLocalIds.Select(x => new BuildingUnitPersistentLocalId(x)),
Provenance);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace BuildingRegistry.Api.BackOffice.Building
{
using System.Threading;
using System.Threading.Tasks;
using Be.Vlaanderen.Basisregisters.Auth.AcmIdm;
using Be.Vlaanderen.Basisregisters.GrAr.Provenance;
using BuildingRegistry.Api.BackOffice.Abstractions.Building.Requests;
using BuildingRegistry.Api.BackOffice.Abstractions.Building.SqsRequests;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

public partial class BuildingController
{
/// <summary>
/// Creëer nieuwe OSLO snapshots.
/// </summary>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("acties/oslosnapshots")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Policy = PolicyNames.GeschetstGebouw.InterneBijwerker)]
public async Task<IActionResult> CreateOsloSnapshots(
[FromBody] CreateBuildingOsloSnapshotsRequest request,
CancellationToken cancellationToken = default)
{
var provenance = ProvenanceFactory.Create(new Reason(request.Reden), Modification.Unknown);

var sqsRequest = new CreateBuildingOsloSnapshotsSqsRequest
{
Request = request,
Metadata = GetMetadata(),
ProvenanceData = new ProvenanceData(provenance)
};

var sqsResult = await Mediator.Send(sqsRequest, cancellationToken);

return Accepted(sqsResult);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public partial class BuildingUnitController
[HttpPost("acties/oslosnapshots")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Policy = PolicyNames.GeschetstGebouw.InterneBijwerker)]
public async Task<IActionResult> CreateOsloSnapshots(
[FromBody] CreateOsloSnapshotsRequest request,
[FromBody] CreateBuildingUnitOsloSnapshotsRequest request,
CancellationToken cancellationToken = default)
{
var provenance = ProvenanceFactory.Create(new Reason(request.Reden), Modification.Unknown);

var sqsRequest = new CreateOsloSnapshotsSqsRequest
var sqsRequest = new CreateBuildingUnitOsloSnapshotsSqsRequest
{
Request = request,
Metadata = GetMetadata(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace BuildingRegistry.Api.BackOffice.Handlers.Building
{
using System.Collections.Generic;
using Abstractions.Building.SqsRequests;
using AllStream;
using Be.Vlaanderen.Basisregisters.Sqs;
using Be.Vlaanderen.Basisregisters.Sqs.Handlers;
using TicketingService.Abstractions;

public sealed class CreateBuildingOsloSnapshotsSqsHandler : SqsHandler<CreateBuildingOsloSnapshotsSqsRequest>
{
public const string Action = "CreateBuildingOsloSnapshots";

public CreateBuildingOsloSnapshotsSqsHandler(
ISqsQueue sqsQueue,
ITicketing ticketing,
ITicketingUrl ticketingUrl) : base(sqsQueue, ticketing, ticketingUrl)
{ }

protected override string? WithAggregateId(CreateBuildingOsloSnapshotsSqsRequest request)
{
return AllStreamId.Instance;
}

protected override IDictionary<string, string> WithTicketMetadata(string aggregateId, CreateBuildingOsloSnapshotsSqsRequest sqsRequest)
{
return new Dictionary<string, string>
{
{ RegistryKey, nameof(BuildingRegistry) },
{ ActionKey, Action },
{ AggregateIdKey, aggregateId }
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ namespace BuildingRegistry.Api.BackOffice.Handlers.BuildingUnit
using BuildingRegistry.Api.BackOffice.Abstractions.BuildingUnit.SqsRequests;
using TicketingService.Abstractions;

public sealed class CreateOsloSnapshotsSqsHandler : SqsHandler<CreateOsloSnapshotsSqsRequest>
public sealed class CreateBuildingUnitOsloSnapshotsSqsHandler : SqsHandler<CreateBuildingUnitOsloSnapshotsSqsRequest>
{
public const string Action = "CreateOsloSnapshots";
public const string Action = "CreateBuildingUnitOsloSnapshots";

public CreateOsloSnapshotsSqsHandler(
public CreateBuildingUnitOsloSnapshotsSqsHandler(
ISqsQueue sqsQueue,
ITicketing ticketing,
ITicketingUrl ticketingUrl) : base(sqsQueue, ticketing, ticketingUrl)
{ }

protected override string? WithAggregateId(CreateOsloSnapshotsSqsRequest request)
protected override string? WithAggregateId(CreateBuildingUnitOsloSnapshotsSqsRequest request)
{
return AllStreamId.Instance;
}

protected override IDictionary<string, string> WithTicketMetadata(string aggregateId, CreateOsloSnapshotsSqsRequest sqsRequest)
protected override IDictionary<string, string> WithTicketMetadata(string aggregateId, CreateBuildingUnitOsloSnapshotsSqsRequest sqsRequest)
{
return new Dictionary<string, string>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,21 @@ private void RegisterProjections(ContainerBuilder builder)
var osloNamespace = _configuration["BuildingOsloNamespace"]!.TrimEnd('/');
var producerOptions = CreateBuildingProducerOptions();

var osloProxy = new OsloProxy(new HttpClient
{
BaseAddress = new Uri(_configuration["BuildingOsloApiUrl"]!.TrimEnd('/')),
});

return new ProducerBuildingProjections(
new Producer(producerOptions),
new SnapshotManager(
c.Resolve<ILoggerFactory>(),
new OsloProxy(new HttpClient
{
BaseAddress = new Uri(_configuration["BuildingOsloApiUrl"]!.TrimEnd('/')),
}),
osloProxy,
SnapshotManagerOptions.Create(
maxRetryWaitIntervalSeconds,
retryBackoffFactor)),
osloNamespace);
osloNamespace,
osloProxy);
},
connectedProjectionSettings)
.RegisterProjections<ProducerBuildingUnitProjections, ProducerContext>(c =>
Expand Down
Loading
Loading