Skip to content

Commit

Permalink
Merge pull request #145 from dlcs/feature/manifest_publicid
Browse files Browse the repository at this point in the history
Flat manifest gains public_id
  • Loading branch information
donaldgray authored Nov 13, 2024
2 parents efda0d8 + 8c79815 commit 5794f4d
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public void GenerateHierarchicalCollectionId_CreatesIdWhenNoFullPath()
[InlineData("slug", "")]
public void GenerateHierarchicalCollectionParent_Correct_ParentId(string fullPath, string outputUrl)
{


// Arrange
var collection = new Collection
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using API.Tests.Integration.Infrastructure;
using Core.Response;
using IIIF.Presentation.V3;
using Models.API.Manifest;
using Test.Helpers.Integration;

namespace API.Tests.Integration;
Expand All @@ -25,21 +26,22 @@ public GetManifestTests(StorageFixture storageFixture, PresentationAppFactory<Pr


[Fact]
public async Task Get_IiifManifest_Flat_ReturnsManifestFromS3()
public async Task Get_IiifManifest_Flat_ReturnsManifestFromS3_DecoratedWithDbValues()
{
// Arrange and Act
var requestMessage =
HttpRequestMessageBuilder.GetPrivateRequest(HttpMethod.Get, "1/manifests/FirstChildManifest");
var response = await httpClient.AsCustomer(1).SendAsync(requestMessage);

var manifest = await response.ReadAsPresentationJsonAsync<Manifest>();
var manifest = await response.ReadAsPresentationJsonAsync<PresentationManifest>();

// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
manifest.Should().NotBeNull();
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.PublicId.Should().Be("http://localhost/1/iiif-manifest", "iiif-manifest is slug and under root");
}

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

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

[Fact]
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.PublicId = hierarchy.GenerateHierarchicalId(urlRoots);
iiifManifest.Created = dbManifest.Created.Floor(DateTimeX.Precision.Second);
iiifManifest.Modified = dbManifest.Modified.Floor(DateTimeX.Precision.Second);
iiifManifest.CreatedBy = dbManifest.CreatedBy;
Expand Down
18 changes: 14 additions & 4 deletions src/IIIFPresentation/API/Features/Manifest/ManifestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Models.API.Manifest;
using Models.Database.General;
using Repository;
using Repository.Helpers;
using Collection = Models.Database.Collections.Collection;
using DbManifest = Models.Database.Collections.Manifest;
using PresUpdateResult = API.Infrastructure.Requests.ModifyEntityResult<Models.API.Manifest.PresentationManifest, Models.API.General.ModifyCollectionType>;
Expand Down Expand Up @@ -158,9 +159,7 @@ private async Task<PresUpdateResult> UpdateInternal(UpsertManifestRequest reques

dbContext.Add(dbManifest);

var saveErrors =
await dbContext.TrySave<PresentationManifest>("manifest", request.CustomerId, logger, cancellationToken);

var saveErrors = await SaveAndPopulateEntity(request, dbManifest, cancellationToken);
return (saveErrors, dbManifest);
}

Expand All @@ -174,10 +173,21 @@ private async Task<PresUpdateResult> UpdateInternal(UpsertManifestRequest reques
canonicalHierarchy.Slug = request.PresentationManifest.Slug!;
canonicalHierarchy.Parent = parentCollection.Id;

var saveErrors = await SaveAndPopulateEntity(request, existingManifest, cancellationToken);
return (saveErrors, existingManifest);
}

private async Task<PresUpdateResult?> SaveAndPopulateEntity(WriteManifestRequest request, DbManifest dbManifest, CancellationToken cancellationToken)
{
var saveErrors =
await dbContext.TrySave<PresentationManifest>("manifest", request.CustomerId, logger, cancellationToken);

if (saveErrors != null) return saveErrors;

return (saveErrors, existingManifest);
dbManifest.Hierarchy.Single().FullPath =
await ManifestRetrieval.RetrieveFullPathForManifest(dbManifest.Id, dbManifest.CustomerId, dbContext,
cancellationToken);
return null;
}

private async Task<string?> GenerateUniqueId(WriteManifestRequest request, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ public async Task<FetchEntityResult<PresentationManifest>> Handle(GetManifest re

var fetchFullPath = ManifestRetrieval.RetrieveFullPathForManifest(dbManifest.Id, dbManifest.CustomerId,
dbContext, cancellationToken);

if (request.PathOnly)
return FetchEntityResult<PresentationManifest>.Success(new()
{
FullPath = await fetchFullPath
});

var manifest = await iiifS3.ReadIIIFFromS3<PresentationManifest>(dbManifest, cancellationToken);
dbManifest.Hierarchy.Single().FullPath = await fetchFullPath;

// PK: Will this even happen? Should we log or even throw here?
if (manifest == null)
Expand Down
3 changes: 1 addition & 2 deletions src/IIIFPresentation/API/Helpers/CollectionHelperX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ public static class CollectionHelperX

public static string GenerateHierarchicalCollectionId(this Collection collection, UrlRoots urlRoots) =>
$"{urlRoots.BaseUrl}/{collection.CustomerId}{(string.IsNullOrEmpty(collection.FullPath) ? string.Empty : $"/{collection.FullPath}")}";

public static string GenerateHierarchicalCollectionParent(this Collection collection, Hierarchy hierarchy, UrlRoots urlRoots)
{
var parentPath = collection.FullPath![..^hierarchy.Slug.Length].TrimEnd('/');

return $"{urlRoots.BaseUrl}/{collection.CustomerId}{(string.IsNullOrEmpty(parentPath) ? string.Empty : $"/{parentPath}")}";
}


public static string GenerateFlatCollectionId(this Collection collection, UrlRoots urlRoots) =>
$"{urlRoots.BaseUrl}/{collection.CustomerId}/collections/{collection.Id}";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ namespace Models.API.Manifest;

public class PresentationManifest : IIIF.Presentation.V3.Manifest, IPresentation
{
public string? PublicId { get; set; }
public string? Slug { get; set; }

public string? Parent { get; set; }
public DateTime Created { get; set; }
public DateTime Modified { get; set; }
Expand Down

0 comments on commit 5794f4d

Please sign in to comment.