Skip to content

Commit

Permalink
feat(wfs): add wfsv2 with housenumberlabel GAWR-5318
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneD committed Jan 13, 2025
1 parent 323b4df commit 7fab434
Show file tree
Hide file tree
Showing 19 changed files with 4,084 additions and 455 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<ProjectReference Include="..\AddressRegistry.Infrastructure\AddressRegistry.Infrastructure.csproj" />
<ProjectReference Include="..\AddressRegistry\AddressRegistry.csproj" />
</ItemGroup>

<Import Project="..\..\.paket\Paket.Restore.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,51 @@ public static class AddressWfsV2Extensions
public static async Task<AddressWfsV2Item> FindAndUpdateAddressDetail(
this WfsContext context,
int addressPersistentLocalId,
Action<AddressWfsV2Item> updateFunc,
CancellationToken ct)
Action<AddressWfsV2Item> updateAddressAction,
IHouseNumberLabelUpdater houseNumberLabelUpdater,
bool updateHouseNumberLabelsBeforeAddressUpdate,
bool updateHouseNumberLabelsAfterAddressUpdate,
bool allowUpdateRemovedAddress = false,
CancellationToken ct = default)
{
var address = await context
.AddressWfsV2Items
.FindAsync(addressPersistentLocalId, cancellationToken: ct);
var address = await context.FindAddressDetail(addressPersistentLocalId, ct, allowUpdateRemovedAddress);

if (updateHouseNumberLabelsBeforeAddressUpdate)
{
await houseNumberLabelUpdater.UpdateHouseNumberLabels(context, address, ct);
}

updateAddressAction(address);

if (updateHouseNumberLabelsAfterAddressUpdate)
{
await houseNumberLabelUpdater.UpdateHouseNumberLabels(context, address, ct, includeAddressInUpdate: true);
}

return address;
}

public static async Task<AddressWfsV2Item> FindAddressDetail(
this WfsContext context,
int addressPersistentLocalId,
CancellationToken ct,
bool allowRemovedAddress = false)
{
// NOTE: We cannot depend on SQL computed columns when facing with bulk insert that needs to perform queries.
var address = await context.AddressWfsV2Items.FindAsync(addressPersistentLocalId, cancellationToken: ct);

if (address == null)
{
throw DatabaseItemNotFound(addressPersistentLocalId);
}

updateFunc(address);
// exclude soft deleted entries, unless allowed
if (!address.Removed || allowRemovedAddress)
{
return address;
}

return address;
throw DatabaseItemNotFound(addressPersistentLocalId);
}

private static ProjectionItemNotFoundException<AddressWfsProjections> DatabaseItemNotFound(int addressPersistentLocalId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ protected AddressWfsV2Item()

public AddressWfsV2Item(
int addressPersistentLocalId,
int? parentAddressPersistentLocalId,
int streetNamePersistentLocalId,
string? postalCode,
string houseNumber,
Expand All @@ -28,21 +29,26 @@ public AddressWfsV2Item(
bool removed,
Instant versionTimestamp)
{
BoxNumber = boxNumber;
OfficiallyAssigned = officiallyAssigned;
Position = position;
PositionMethod = positionMethod;
PositionSpecification = positionSpecification;
AddressPersistentLocalId = addressPersistentLocalId;
ParentAddressPersistentLocalId = parentAddressPersistentLocalId;
StreetNamePersistentLocalId = streetNamePersistentLocalId;
PostalCode = postalCode;
HouseNumber = houseNumber;
BoxNumber = boxNumber;
LabelType = string.IsNullOrWhiteSpace(boxNumber)
? WfsAddressLabelType.HouseNumberWithoutBoxNumbersOnSamePosition
: WfsAddressLabelType.HouseNumberWithBoxNumbersOnSamePosition;
Status = status;
OfficiallyAssigned = officiallyAssigned;
SetPosition(position);
PositionMethod = positionMethod;
PositionSpecification = positionSpecification;
Removed = removed;
VersionTimestamp = versionTimestamp;
}

public int AddressPersistentLocalId { get; set; }
public int? ParentAddressPersistentLocalId { get; set; }
public int StreetNamePersistentLocalId { get; set; }
public string? PostalCode { get; set; }
public string HouseNumber { get; set; }
Expand Down Expand Up @@ -103,6 +109,7 @@ public void Configure(EntityTypeBuilder<AddressWfsV2Item> b)

b.Ignore(x => x.VersionTimestamp);

b.Property(p => p.ParentAddressPersistentLocalId);
b.Property(p => p.StreetNamePersistentLocalId);
b.Property(p => p.PostalCode);
b.Property(p => p.HouseNumber);
Expand All @@ -117,8 +124,8 @@ public void Configure(EntityTypeBuilder<AddressWfsV2Item> b)

b.Property(p => p.HouseNumberLabel);
b.Property<int>("HouseNumberLabelLength")
.HasComputedColumnSql("LEN(HouseNumberLabel)")
.ValueGeneratedOnAddOrUpdate();
.HasComputedColumnSql("LEN(HouseNumberLabel)", stored: true);

b.Property(p => p.LabelType);

b.HasIndex(p => p.StreetNamePersistentLocalId);
Expand Down
Loading

0 comments on commit 7fab434

Please sign in to comment.