Skip to content

Commit

Permalink
feat(integration): remove buildingunit from version projection when r…
Browse files Browse the repository at this point in the history
…emoved
  • Loading branch information
ArneD committed Sep 10, 2024
1 parent bc01dfd commit 44b01e3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ await context.CreateNewBuildingVersion(
var buildingUnit = building.BuildingUnits.Single(x =>
x.BuildingUnitPersistentLocalId == message.Message.BuildingUnitPersistentLocalId);

buildingUnit.IsRemoved = true;
buildingUnit.VersionTimestamp = message.Message.Provenance.Timestamp;
building.BuildingUnits.Remove(buildingUnit);

building.VersionTimestamp = message.Message.Provenance.Timestamp;
},
Expand All @@ -234,8 +233,7 @@ await context.CreateNewBuildingVersion(
var buildingUnit = building.BuildingUnits.Single(x =>
x.BuildingUnitPersistentLocalId == message.Message.BuildingUnitPersistentLocalId);

buildingUnit.IsRemoved = true;
buildingUnit.VersionTimestamp = message.Message.Provenance.Timestamp;
building.BuildingUnits.Remove(buildingUnit);

building.VersionTimestamp = message.Message.Provenance.Timestamp;
},
Expand All @@ -249,22 +247,50 @@ await context.CreateNewBuildingVersion(
message,
building =>
{
var buildingUnit = building.BuildingUnits.Single(x =>
var buildingUnit = building.BuildingUnits.SingleOrDefault(x =>
x.BuildingUnitPersistentLocalId == message.Message.BuildingUnitPersistentLocalId);

var geometryAsBinary = message.Message.ExtendedWkbGeometry.ToByteArray();
var sysGeometry = wkbReader.Read(geometryAsBinary);

buildingUnit.Status = BuildingUnitStatus.Parse(message.Message.BuildingUnitStatus).Status;
buildingUnit.OsloStatus = BuildingUnitStatus.Parse(message.Message.BuildingUnitStatus).Map();
buildingUnit.Function = BuildingUnitFunction.Parse(message.Message.Function).Function;
buildingUnit.OsloFunction = BuildingUnitFunction.Parse(message.Message.Function).Map();
buildingUnit.Geometry = sysGeometry;
buildingUnit.GeometryMethod = BuildingUnitPositionGeometryMethod.Parse(message.Message.GeometryMethod).GeometryMethod;
buildingUnit.OsloGeometryMethod = BuildingUnitPositionGeometryMethod.Parse(message.Message.GeometryMethod).Map();
buildingUnit.HasDeviation = message.Message.HasDeviation;
buildingUnit.IsRemoved = false;
buildingUnit.VersionTimestamp = message.Message.Provenance.Timestamp;
if (buildingUnit is not null)
{
buildingUnit.Status = BuildingUnitStatus.Parse(message.Message.BuildingUnitStatus).Status;
buildingUnit.OsloStatus = BuildingUnitStatus.Parse(message.Message.BuildingUnitStatus).Map();
buildingUnit.Function = BuildingUnitFunction.Parse(message.Message.Function).Function;
buildingUnit.OsloFunction = BuildingUnitFunction.Parse(message.Message.Function).Map();
buildingUnit.Geometry = sysGeometry;
buildingUnit.GeometryMethod = BuildingUnitPositionGeometryMethod.Parse(message.Message.GeometryMethod).GeometryMethod;
buildingUnit.OsloGeometryMethod = BuildingUnitPositionGeometryMethod.Parse(message.Message.GeometryMethod).Map();
buildingUnit.HasDeviation = message.Message.HasDeviation;
buildingUnit.IsRemoved = false;
buildingUnit.VersionTimestamp = message.Message.Provenance.Timestamp;
}
else
{
var buildingUnitVersion = new BuildingUnitVersion
{
Position = message.Position,
BuildingUnitPersistentLocalId = message.Message.BuildingUnitPersistentLocalId,
BuildingPersistentLocalId = message.Message.BuildingPersistentLocalId,
Status = BuildingUnitStatus.Parse(message.Message.BuildingUnitStatus).Status,
OsloStatus = BuildingUnitStatus.Parse(message.Message.BuildingUnitStatus).Map(),
Function = BuildingUnitFunction.Parse(message.Message.Function).Function,
OsloFunction = BuildingUnitFunction.Parse(message.Message.Function).Map(),
GeometryMethod = BuildingUnitPositionGeometryMethod.Parse(message.Message.GeometryMethod).GeometryMethod,
OsloGeometryMethod = BuildingUnitPositionGeometryMethod.Parse(message.Message.GeometryMethod).Map(),
Geometry = sysGeometry,
HasDeviation = message.Message.HasDeviation,
IsRemoved = false,
VersionTimestamp = message.Message.Provenance.Timestamp,
CreatedOnTimestamp = message.Message.Provenance.Timestamp,
Namespace = options.BuildingUnitNamespace,
PuriId = $"{options.BuildingUnitNamespace}/{message.Message.BuildingUnitPersistentLocalId}",
Type = message.EventName
};

building.BuildingUnits.Add(buildingUnitVersion);
}

building.VersionTimestamp = message.Message.Provenance.Timestamp;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,11 +689,7 @@ await Sut
buildingVersion.Should().NotBeNull();
var buildingUnitVersion = buildingVersion!.BuildingUnits.SingleOrDefault(x =>
x.BuildingUnitPersistentLocalId == buildingUnitWasPlannedV2.BuildingUnitPersistentLocalId);
buildingUnitVersion.Should().NotBeNull();

buildingUnitVersion!.IsRemoved.Should().BeTrue();
buildingUnitVersion.VersionTimestamp.Should().Be(buildingUnitWasRemovedV2.Provenance.Timestamp);
buildingUnitVersion.Type.Should().Be("EventName");
buildingUnitVersion.Should().BeNull();

buildingVersion.VersionTimestamp.Should().Be(buildingUnitWasRemovedV2.Provenance.Timestamp);
});
Expand Down Expand Up @@ -742,11 +738,7 @@ await Sut
buildingVersion.Should().NotBeNull();
var buildingUnitVersion = buildingVersion!.BuildingUnits.SingleOrDefault(x =>
x.BuildingUnitPersistentLocalId == buildingUnitWasPlannedV2.BuildingUnitPersistentLocalId);
buildingUnitVersion.Should().NotBeNull();

buildingUnitVersion!.IsRemoved.Should().BeTrue();
buildingUnitVersion.VersionTimestamp.Should().Be(buildingUnitWasRemoved.Provenance.Timestamp);
buildingUnitVersion.Type.Should().Be("EventName");
buildingUnitVersion.Should().BeNull();

buildingVersion.VersionTimestamp.Should().Be(buildingUnitWasRemoved.Provenance.Timestamp);
});
Expand Down

0 comments on commit 44b01e3

Please sign in to comment.