Bind the NRC hoofdObject, recognise a zaken/status/create notification, and key the projection on the zaak (hoofdObject) so the status updates the existing INGEDIEND row to INGESCHREVEN — without reading OpenZaak (§8.1). Retain the ZGW resource in the log (new column + migration) so a rebuild reproduces the approved status. Updates the acceptance fakes for the new IAclClient/IZaakGateway members. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
43 lines
2.0 KiB
C#
43 lines
2.0 KiB
C#
namespace EventSubscriber.Application;
|
|
|
|
/// <summary>
|
|
/// Projects inbound NRC notifications into the read projection. Tolerates duplicate and
|
|
/// out-of-order deliveries (CLAUDE.md §8.6): the notification log dedups, and the projection
|
|
/// upsert is idempotent on the zaak id. Rebuilds the projection by replaying the log.
|
|
/// </summary>
|
|
public sealed class NotificationProjector(INotificationLog log, IProjectionStore store)
|
|
{
|
|
/// <summary>Handle one inbound notification. Reacts to a zaak being created (INGEDIEND) and a
|
|
/// status being set (INGESCHREVEN); ignores everything else.</summary>
|
|
public async Task HandleAsync(Notification notification, CancellationToken ct = default)
|
|
{
|
|
if (!notification.IsZaakCreated && !notification.IsZaakStatusSet)
|
|
return;
|
|
|
|
var recorded = new RecordedNotification(
|
|
notification.IdempotencyKey, notification.Actie, notification.ZaakId, notification.Resource);
|
|
|
|
// Atomic record-or-skip: a duplicate (or concurrent) delivery is recognised and dropped
|
|
// before it touches the projection, so the projection stays a faithful derived artefact.
|
|
if (!await log.TryRecordAsync(recorded, ct))
|
|
return;
|
|
|
|
await store.UpsertAsync(ToEntry(recorded), ct);
|
|
}
|
|
|
|
/// <summary>Rebuild the projection from the durable notification log (PRD §8.4).</summary>
|
|
public async Task RebuildAsync(CancellationToken ct = default)
|
|
{
|
|
await store.ClearAsync(ct);
|
|
foreach (var recorded in await log.AllAsync(ct))
|
|
await store.UpsertAsync(ToEntry(recorded), ct);
|
|
}
|
|
|
|
/// <summary>The projection row for an accepted notification: a status-set maps to INGESCHREVEN,
|
|
/// a zaak-create to INGEDIEND. bsn/naam are deferred (ADR-0008).</summary>
|
|
private static RegisterEntry ToEntry(RecordedNotification recorded)
|
|
=> new(recorded.ZaakId, recorded.Resource == "status"
|
|
? RegistrationStatus.Ingeschreven
|
|
: RegistrationStatus.Ingediend);
|
|
}
|