Skip to content

Commit

Permalink
Merge pull request #873 from dlcs/fix/omit_type_p2manifest
Browse files Browse the repository at this point in the history
Omit type from serialized `ImageService2` in Presentation2 manifests
  • Loading branch information
donaldgray committed Jun 27, 2024
2 parents f458a03 + 903026e commit 3c738a4
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Xunit;

namespace DLCS.Model.Tests.Assets;


public class InfoJsonBuilderTests
{
[Fact]
Expand All @@ -15,6 +15,7 @@ public void GetImageApi2_1Level0_ReturnsExpected()
var expected = @"{
""@context"": ""http://iiif.io/api/image/2/context.json"",
""@id"": ""https://test.example.com/iiif-img/2/1/jackal"",
""@type"": ""iiif:Image"",
""profile"": [
""http://iiif.io/api/image/2/level0.json"",
{
Expand Down Expand Up @@ -48,6 +49,7 @@ public void GetImageApi2_1Level1_ReturnsExpected()
var expected = @"{
""@context"": ""http://iiif.io/api/image/2/context.json"",
""@id"": ""https://test.example.com/iiif-img/2/1/jackal"",
""@type"": ""iiif:Image"",
""profile"": [
""http://iiif.io/api/image/2/level1.json"",
{
Expand Down
4 changes: 2 additions & 2 deletions src/protagonist/DLCS.Model/Assets/InfoJsonBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static ImageService2 GetImageApi2_1Level0(string serviceEndpoint, List<in
{
Context = ImageService2.Image2Context,
Id = serviceEndpoint,
Type = null,
Type = IIIF.Constants.ImageService2Type,
Protocol = ImageService2.Image2Protocol,
Profile = ImageService2.Level0Profile,
ProfileDescription = new ProfileDescription
Expand Down Expand Up @@ -56,7 +56,7 @@ public static ImageService2 GetImageApi2_1Level0(string serviceEndpoint, List<in
{
Context = ImageService2.Image2Context,
Id = serviceEndpoint,
Type = null,
Type = IIIF.Constants.ImageService2Type,
Protocol = ImageService2.Image2Protocol,
Profile = ImageService2.Level1Profile,
Width = width,
Expand Down
2 changes: 1 addition & 1 deletion src/protagonist/DLCS.Model/DLCS.Model.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="iiif-net" Version="0.2.3" />
<PackageReference Include="iiif-net" Version="0.2.5" />
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions src/protagonist/DLCS.Model/IIIF/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace DLCS.Model.IIIF;

public static class Constants
{
/// <summary>
/// @type value for ImageService2 for rendering as IIIF Image or Presentation v2
/// </summary>
public const string ImageService2Type = "iiif:Image";
}
2 changes: 1 addition & 1 deletion src/protagonist/DLCS.Repository/DLCS.Repository.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="iiif-net" Version="0.2.3" />
<PackageReference Include="iiif-net" Version="0.2.5" />
<PackageReference Include="LazyCache" Version="2.4.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.5">
<PrivateAssets>all</PrivateAssets>
Expand Down
2 changes: 1 addition & 1 deletion src/protagonist/DLCS.Web/DLCS.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="iiif-net" Version="0.2.3" />
<PackageReference Include="iiif-net" Version="0.2.5" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
Expand Down
2 changes: 1 addition & 1 deletion src/protagonist/Engine/Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="iiif-net" Version="0.2.3" />
<PackageReference Include="iiif-net" Version="0.2.5" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" />
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
<PackageReference Include="AWSSDK.SecurityToken" Version="3.7.1.150" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using Orchestrator.Infrastructure.IIIF;
using Orchestrator.Tests.Integration.Infrastructure;
using Test.Helpers;
using Test.Helpers.Data;
using Test.Helpers.Integration;
using Yarp.ReverseProxy.Forwarder;
using Version = IIIF.ImageApi.Version;
Expand Down Expand Up @@ -261,7 +262,7 @@ public async Task GetInfoJson_Correct_IgnoresQueryParamOnRequestUri()
public async Task GetInfoJsonV2_Correct_ViaDirectPath_NotInS3()
{
// Arrange
var id = AssetId.FromString($"99/1/{nameof(GetInfoJsonV2_Correct_ViaDirectPath_NotInS3)}");
var id = AssetIdGenerator.GetAssetId();
await dbFixture.DbContext.Images.AddTestAsset(id, imageDeliveryChannels: deliveryChannelsForImage);

await amazonS3.PutObjectAsync(new PutObjectRequest
Expand All @@ -282,6 +283,7 @@ public async Task GetInfoJsonV2_Correct_ViaDirectPath_NotInS3()
jsonResponse.Id.Should().Be($"http://localhost/iiif-img/v2/{id}");
jsonResponse.Context.ToString().Should().Be("http://iiif.io/api/image/2/context.json");
jsonResponse.Sizes.Should().BeEquivalentTo(expectedSizes);
jsonResponse.Type.Should().Be("iiif:Image", "ImageService2 is default on class, overridden when read");

// With correct headers/status
response.StatusCode.Should().Be(HttpStatusCode.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AngleSharp" Version="0.16.1" />
<PackageReference Include="AngleSharp" Version="0.17.1" />
<PackageReference Include="FakeItEasy" Version="7.3.1" />
<PackageReference Include="FluentAssertions" Version="6.6.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.5" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ public class InfoJsonService
JsonLdBase deserialisedInfoJson = version == Version.V2
? infoJson.FromJsonStream<ImageService2>()
: infoJson.FromJsonStream<ImageService3>();

logger.LogTrace("Found info.json version {Version} for {AssetId}", version, orchestrationImage.AssetId);
return new InfoJsonResponse(deserialisedInfoJson, false);
return GetInfoJsonResponse(deserialisedInfoJson, false);
}

// If not found, build new copy
Expand All @@ -69,7 +70,17 @@ public class InfoJsonService
if (infoJsonResponse == null) return null;

await StoreInfoJson(infoJsonKey, infoJsonResponse, cancellationToken);
return new InfoJsonResponse(infoJsonResponse, true);
return GetInfoJsonResponse(infoJsonResponse, true);
}

private InfoJsonResponse GetInfoJsonResponse(JsonLdBase infoJsonResponse, bool wasOrchestrated)
{
if (infoJsonResponse is ImageService2 imageService2)
{
imageService2.Type = DLCS.Model.IIIF.Constants.ImageService2Type;
}

return new InfoJsonResponse(infoJsonResponse, wasOrchestrated);
}

private ObjectInBucket GetInfoJsonKey(OrchestrationImage asset, Version version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,17 @@ public class IIIFCanvasFactory
var services = new List<IService>();
if (orchestratorSettings.ImageServerConfig.VersionPathTemplates.ContainsKey(ImageApi.Version.V2))
{
services.Add(new ImageService2
var imageService = new ImageService2
{
Id = GetFullyQualifiedId(asset, customerPathElement, true, ImageApi.Version.V2),
Profile = ImageService2.Level0Profile,
Sizes = thumbnailSizes,
Context = ImageService2.Image2Context,
});
};

if (forPresentation2) imageService.Type = null; // '@Type' is not used in Presentation2

services.Add(imageService);
}

// NOTE - we never include ImageService3 on Presentation2 manifests
Expand Down Expand Up @@ -272,15 +276,19 @@ public class IIIFCanvasFactory
var services = new List<IService>();
if (versionPathTemplates.ContainsKey(ImageApi.Version.V2))
{
services.Add(new ImageService2
var imageService = new ImageService2
{
Id = GetFullyQualifiedId(asset, customerPathElement, false, ImageApi.Version.V2),
Profile = ImageService2.Level2Profile,
Context = ImageService2.Image2Context,
Width = asset.Width ?? 0,
Height = asset.Height ?? 0,
Service = TryGetAuthServices(),
});
};

if (forPresentation2) imageService.Type = null; // '@Type' is not used in Presentation2

services.Add(imageService);
}

// NOTE - we never include ImageService3 on Presentation2 manifests
Expand Down
2 changes: 1 addition & 1 deletion src/protagonist/Portal.Tests/Portal.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AngleSharp" Version="0.16.1" />
<PackageReference Include="AngleSharp" Version="0.17.1" />
<PackageReference Include="FluentAssertions" Version="6.6.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/protagonist/Portal/Portal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageReference Include="AWSSDK.SecurityToken" Version="3.7.1.150" />
<PackageReference Include="CsvHelper" Version="30.0.1" />
<PackageReference Include="Destructurama.Attributed" Version="2.0.0" />
<PackageReference Include="iiif-net" Version="0.2.3" />
<PackageReference Include="iiif-net" Version="0.2.5" />
<PackageReference Include="MediatR" Version="10.0.1" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="10.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.5" />
Expand Down
2 changes: 1 addition & 1 deletion src/protagonist/Thumbs/Thumbs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="6.0.2" />
<PackageReference Include="AWSSDK.SecurityToken" Version="3.7.1.150" />
<PackageReference Include="iiif-net" Version="0.2.3" />
<PackageReference Include="iiif-net" Version="0.2.5" />
<PackageReference Include="LazyCache.AspNetCore" Version="2.4.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
Expand Down

0 comments on commit 3c738a4

Please sign in to comment.