Skip to content

Commit

Permalink
Merge pull request #149 from dlcs/feature/flatid
Browse files Browse the repository at this point in the history
PresentationManifest and Collection gain FlatId
  • Loading branch information
donaldgray authored Nov 15, 2024
2 parents 4eb9f12 + 1114784 commit c03bb87
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public void ToFlatCollection_ConvertsStorageCollection()

// Assert
flatCollection.Id.Should().Be("http://base/1/collections/some-id");
flatCollection.FlatId.Should().Be("some-id");
flatCollection.PublicId.Should().Be("http://base/1");
flatCollection.Label!.Count.Should().Be(1);
flatCollection.Label["en"].Should().Contain("repository root");
Expand Down Expand Up @@ -129,6 +130,7 @@ public void ToFlatCollection_ConvertsStorageCollection_WithFullPath()

// Assert
flatCollection.Id.Should().Be("http://base/1/collections/some-id");
flatCollection.FlatId.Should().Be("some-id");
flatCollection.PublicId.Should().Be("http://base/1/top/some-id");
flatCollection.Label!.Count.Should().Be(1);
flatCollection.Label["en"].Should().Contain("repository root");
Expand Down Expand Up @@ -160,6 +162,7 @@ public void ToFlatCollection_ConvertsStorageCollection_WithCorrectPaging()

// Assert
flatCollection.Id.Should().Be("http://base/1/collections/some-id");
flatCollection.FlatId.Should().Be("some-id");
flatCollection.PublicId.Should().Be("http://base/1/top/some-id");
flatCollection.Label!.Count.Should().Be(1);
flatCollection.Label["en"].Should().Contain("repository root");
Expand Down
2 changes: 2 additions & 0 deletions src/IIIFPresentation/API.Tests/Helpers/PresentationX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public void GetParentSlug_ReturnsLastPathElement(string parentSlug)

public class TestPresentation : IPresentation
{
public string? PublicId { get; set; }
public string? FlatId { get; set; }
public string? Slug { get; set; }
public string? Parent { get; set; }
public DateTime Created { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public void IsUriParentInvalid_True_IfUriAndDoesNotMatchParent()

public class TestPresentation : IPresentation
{
public string? PublicId { get; set; }
public string? FlatId { get; set; }
public string? Slug { get; set; }
public string? Parent { get; set; }
public DateTime Created { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public async Task Get_RootFlat_ReturnsEntryPointFlat_WhenAuthAndHeader()
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
collection!.Id.Should().Be($"http://localhost/1/collections/{RootCollection.Id}");
collection.FlatId.Should().Be(RootCollection.Id);
collection.PublicId.Should().Be("http://localhost/1");
collection.Items!.Count.Should().Be(TotalDatabaseChildItems);
collection.Items.OfType<Collection>().First().Id.Should().Be("http://localhost/1/collections/FirstChildCollection");
Expand Down Expand Up @@ -245,6 +246,7 @@ public async Task Get_ChildFlat_ReturnsEntryPointFlat_WhenCalledByChildId()
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
collection!.Id.Should().Be("http://localhost/1/collections/FirstChildCollection");
collection.FlatId.Should().Be("FirstChildCollection");
collection.PublicId.Should().Be("http://localhost/1/first-child");
collection.Items!.Count.Should().Be(1);
collection.Items.OfType<Collection>().First().Id.Should().Be("http://localhost/1/collections/SecondChildCollection");
Expand All @@ -269,6 +271,7 @@ public async Task Get_PrivateChild_ReturnsCorrectlyFlatAndHierarchical()
// Assert
flatResponse.StatusCode.Should().Be(HttpStatusCode.OK);
flatCollection!.Id.Should().Be("http://localhost/1/collections/NonPublic");
flatCollection.FlatId.Should().Be("NonPublic");
flatCollection.PublicId.Should().Be("http://localhost/1/non-public");
flatCollection.Items!.Count.Should().Be(0);
flatCollection.CreatedBy.Should().Be("admin");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public async Task Get_IiifManifest_Flat_ReturnsManifestFromS3_DecoratedWithDbVal
manifest!.Type.Should().Be("Manifest");
manifest.Id.Should().Be("http://localhost/1/manifests/FirstChildManifest", "requested by flat URI");
manifest.Items.Should().HaveCount(3, "the test content contains 3 children");
manifest.FlatId.Should().Be("FirstChildManifest");
manifest.PublicId.Should().Be("http://localhost/1/iiif-manifest", "iiif-manifest is slug and under root");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ public async Task PutFlatId_Insert_ReturnsManifest()
responseManifest.Slug.Should().Be(slug);
responseManifest.Parent.Should().Be("http://localhost/1/collections/root");
responseManifest.PublicId.Should().Be($"http://localhost/1/{slug}");
responseManifest.FlatId.Should().Be(id);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ public async Task PutFlatId_Update_UpdatesManifest_ParentIsValidHierarchicalUrl(
responseManifest.Slug.Should().Be(slug);
responseManifest.Parent.Should().Be(parent);
responseManifest.PublicId.Should().Be($"http://localhost/1/{slug}");
responseManifest.FlatId.Should().Be(dbManifest.Id);
}

[Fact]
Expand Down
1 change: 1 addition & 0 deletions src/IIIFPresentation/API/Converters/CollectionConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static PresentationCollection ToFlatCollection(this Models.Database.Colle
Id = dbAsset.GenerateFlatCollectionId(urlRoots),
Context = GenerateContext(),
Label = dbAsset.Label,
FlatId = dbAsset.Id,
PublicId = dbAsset.GenerateHierarchicalCollectionId(urlRoots),
Behavior = GenerateBehavior(dbAsset),
Slug = hierarchy.Slug,
Expand Down
1 change: 1 addition & 0 deletions src/IIIFPresentation/API/Converters/ManifestConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static PresentationManifest SetGeneratedFields(this PresentationManifest
var hierarchy = hierarchyFactory(dbManifest);

iiifManifest.Id = dbManifest.GenerateFlatManifestId(urlRoots);
iiifManifest.FlatId = dbManifest.Id;
iiifManifest.PublicId = hierarchy.GenerateHierarchicalId(urlRoots);
iiifManifest.Created = dbManifest.Created.Floor(DateTimeX.Precision.Second);
iiifManifest.Modified = dbManifest.Modified.Floor(DateTimeX.Precision.Second);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static PresentationCollection EnrichPresentationCollection(this Presentat
presentationCollection.Items ??= CollectionConverter.GenerateItems(urlRoots, items);
presentationCollection.TotalItems = totalItems;

presentationCollection.FlatId = collection.Id;
presentationCollection.Id = collection.GenerateFlatCollectionId(urlRoots);
presentationCollection.PublicId = collection.GenerateHierarchicalCollectionId(urlRoots);
presentationCollection.Parent = CollectionConverter.GeneratePresentationCollectionParent(urlRoots, hierarchy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Models.API.Collection;
public class PresentationCollection : IIIF.Presentation.V3.Collection, IPresentation
{
public string? PublicId { get; set; }
public string? FlatId { get; set; }

public string? Slug { get; set; }

Expand Down
2 changes: 2 additions & 0 deletions src/IIIFPresentation/Models/API/IPresentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
/// <remarks>Shared items should be added to this as required</remarks>
public interface IPresentation
{
public string? PublicId { get; set; }
public string? FlatId { get; set; }
string? Slug { get; set; }
string? Parent { get; set; }
public DateTime Created { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Models.API.Manifest;
public class PresentationManifest : IIIF.Presentation.V3.Manifest, IPresentation
{
public string? PublicId { get; set; }
public string? FlatId { get; set; }
public string? Slug { get; set; }
public string? Parent { get; set; }
public DateTime Created { get; set; }
Expand Down

0 comments on commit c03bb87

Please sign in to comment.