Skip to content

Commit

Permalink
set asset in correctly in the body of a presentation manifest call
Browse files Browse the repository at this point in the history
  • Loading branch information
JackLewis-digirati committed Jan 13, 2025
1 parent cb3a751 commit bbae7b6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using API.Tests.Helpers;
using Models.API.Manifest;
using Models.Database.General;
using Newtonsoft.Json.Linq;
using CanvasPainting = Models.Database.CanvasPainting;
using DBManifest = Models.Database.Collections.Manifest;

Expand Down Expand Up @@ -177,12 +178,52 @@ public void SetGeneratedFields_SetsCanvasPainting_IfPresent()
var result = iiifManifest.SetGeneratedFields(dbManifest, pathGenerator);

// Assert
var cp = result.PaintedResources.Single().CanvasPainting;
cp.CanvasId.Should().Be("http://base/123/canvases/the-canvas");
cp.ChoiceOrder.Should().Be(10);
cp.CanvasOrder.Should().Be(100);
cp.CanvasOriginalId.Should().Be("http://example.test/canvas1");
cp.AssetId.Should().Be("https://dlcs.test/customers/1/spaces/2/images/assetId");
var paintedResource = result.PaintedResources.Single();
paintedResource.CanvasPainting.CanvasId.Should().Be("http://base/123/canvases/the-canvas");
paintedResource.CanvasPainting.ChoiceOrder.Should().Be(10);
paintedResource.CanvasPainting.CanvasOrder.Should().Be(100);
paintedResource.CanvasPainting.CanvasOriginalId.Should().Be("http://example.test/canvas1");

paintedResource.Asset.GetValue("assetId").ToString().Should().Be("https://dlcs.test/customers/1/spaces/2/images/assetId");
}

[Fact]
public void SetGeneratedFields_SetsCanvasPainting_WithoutAssetId()
{
// Arrange
var iiifManifest = new PresentationManifest();
var dbManifest = new DBManifest
{
CustomerId = 123,
Created = DateTime.UtcNow,
Modified = DateTime.UtcNow.AddDays(1),
CreatedBy = "creator",
ModifiedBy = "modifier",
Id = "id",
Hierarchy = [new Hierarchy { Slug = "slug" }],
CanvasPaintings =
[
new CanvasPainting
{
CanvasOriginalId = new Uri("http://example.test/canvas1"),
CustomerId = 123,
Id = "the-canvas",
ChoiceOrder = 10,
CanvasOrder = 100
}
]
};

// Act
var result = iiifManifest.SetGeneratedFields(dbManifest, pathGenerator);

// Assert
var paintedResource = result.PaintedResources.Single();
paintedResource.CanvasPainting.CanvasId.Should().Be("http://base/123/canvases/the-canvas");
paintedResource.CanvasPainting.ChoiceOrder.Should().Be(10);
paintedResource.CanvasPainting.CanvasOrder.Should().Be(100);
paintedResource.CanvasPainting.CanvasOriginalId.Should().Be("http://example.test/canvas1");
paintedResource.Asset.Should().BeNull();
}

[Fact]
Expand Down
7 changes: 6 additions & 1 deletion src/IIIFPresentation/API/Converters/ManifestConverter.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using API.Helpers;
using Core.Helpers;
using Core.IIIF;
using DLCS.Models;
using IIIF;
using IIIF.Presentation;
using Models.API.Manifest;
using Models.Database.Collections;
using Models.Database.General;
using Newtonsoft.Json.Linq;

namespace API.Converters;

Expand Down Expand Up @@ -62,7 +64,10 @@ public static PresentationManifest SetGeneratedFields(this PresentationManifest
Label = cp.Label,
CanvasOriginalId = cp.CanvasOriginalId?.ToString(),
CanvasLabel = cp.CanvasLabel,
AssetId = pathGenerator.GenerateAssetUri(cp)?.ToString()
},
Asset = cp.AssetId == null ? null : new JObject
{
["assetId"] = pathGenerator.GenerateAssetUri(cp)?.ToString()
}
}).ToList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,4 @@ public class CanvasPainting
public string? Target { get; set; }
public int? StaticWidth { get; set; }
public int? StaticHeight { get; set; }
public string? AssetId { get; set; }
}

0 comments on commit bbae7b6

Please sign in to comment.