From fdec223800494a44392c66615e04eeb6983ba69d Mon Sep 17 00:00:00 2001 From: "jack.lewis" Date: Mon, 7 Oct 2024 11:50:55 +0100 Subject: [PATCH 1/7] allowing thumbnail to be set from IIIF type on post --- .../Integration/ModifyCollectionTests.cs | 51 ++++++++----- .../Storage/Requests/CreateCollection.cs | 74 ++++++++++--------- .../Storage/Requests/UpsertCollection.cs | 4 +- .../API/Features/Storage/StorageController.cs | 2 +- .../Collection/Upsert/UpsertFlatCollection.cs | 20 ++++- 5 files changed, 94 insertions(+), 57 deletions(-) diff --git a/src/IIIFPresentation/API.Tests/Integration/ModifyCollectionTests.cs b/src/IIIFPresentation/API.Tests/Integration/ModifyCollectionTests.cs index f665a32..7e94bd4 100644 --- a/src/IIIFPresentation/API.Tests/Integration/ModifyCollectionTests.cs +++ b/src/IIIFPresentation/API.Tests/Integration/ModifyCollectionTests.cs @@ -63,7 +63,7 @@ public async Task CreateCollection_CreatesCollection_WhenAllValuesProvided() Label = new LanguageMap("en", ["test collection"]), Slug = "programmatic-child", Parent = parent, - Thumbnail = "some/thumbnail", + PresentationThumbnail = "some/thumbnail", Tags = "some, tags", ItemsOrder = 1, }; @@ -98,20 +98,32 @@ public async Task CreateCollection_CreatesCollection_WhenAllValuesProvided() public async Task CreateCollection_CreatesCollection_WhenIsStorageCollectionFalse() { // Arrange - var collection = new UpsertFlatCollection() - { - Behavior = new List() - { - Behavior.IsPublic - }, - Label = new LanguageMap("en", ["test collection"]), - Slug = "iiif-child", - Parent = parent, - Tags = "some, tags", - ItemsOrder = 1, - }; + var collection = $@"{{ + ""type"": ""Collection"", + ""behavior"": [ + ""public-iiif"" + ], + ""label"": {{ + ""en"": [ + ""iiif post"" + ] + }}, + ""slug"": ""iiif-child"", + ""parent"": ""{parent}"", + ""tags"": ""some, tags"", + ""itemsOrder"": 1, + ""thumbnail"": [ + {{ + ""id"": ""https://example.org/img/thumb.jpg"", + ""type"": ""Image"", + ""format"": ""image/jpeg"", + ""width"": 300, + ""height"": 200 + }} + ] +}}"; - var requestMessage = HttpRequestMessageBuilder.GetPrivateRequest(HttpMethod.Post, $"{Customer}/collections", JsonSerializer.Serialize(collection)); + var requestMessage = HttpRequestMessageBuilder.GetPrivateRequest(HttpMethod.Post, $"{Customer}/collections", collection); // Act var response = await httpClient.AsCustomer(1).SendAsync(requestMessage); @@ -128,13 +140,14 @@ await amazonS3.GetObjectAsync(LocalStackFixture.StorageBucketName, // Assert response.StatusCode.Should().Be(HttpStatusCode.Created); fromDatabase.Parent.Should().Be(parent); - fromDatabase.Label!.Values.First()[0].Should().Be("test collection"); + fromDatabase.Label!.Values.First()[0].Should().Be("iiif post"); fromDatabase.Slug.Should().Be("iiif-child"); fromDatabase.ItemsOrder.Should().Be(1); fromDatabase.Tags.Should().Be("some, tags"); fromDatabase.IsPublic.Should().BeTrue(); fromDatabase.IsStorageCollection.Should().BeFalse(); fromDatabase.Modified.Should().Be(fromDatabase.Created); + fromDatabase.Thumbnail.Should().Be("https://example.org/img/thumb.jpg"); responseCollection!.View!.PageSize.Should().Be(20); responseCollection.View.Page.Should().Be(1); responseCollection.View.Id.Should().Contain("?page=1&pageSize=20"); @@ -155,7 +168,7 @@ public async Task CreateCollection_ReturnsError_WhenIsStorageCollectionFalseAndU Slug = "iiif-child", Parent = parent, Tags = "some, tags", - Thumbnail = "some/thumbnail", + PresentationThumbnail = "some/thumbnail", ItemsOrder = 1, }; @@ -412,7 +425,7 @@ public async Task UpdateCollection_UpdatesCollection_WhenAllValuesProvided() Slug = "programmatic-child", Parent = parent, ItemsOrder = 1, - Thumbnail = "some/location/2", + PresentationThumbnail = "some/location/2", Tags = "some, tags, 2", }; @@ -457,7 +470,7 @@ public async Task UpdateCollection_CreatesCollection_WhenUnknownCollectionIdProv Slug = "create-from-update", Parent = parent, ItemsOrder = 1, - Thumbnail = "some/location/2", + PresentationThumbnail = "some/location/2", Tags = "some, tags, 2", }; @@ -502,7 +515,7 @@ public async Task UpdateCollection_FailsToCreateCollection_WhenUnknownCollection Slug = "create-from-update-2", Parent = parent, ItemsOrder = 1, - Thumbnail = "some/location/2", + PresentationThumbnail = "some/location/2", Tags = "some, tags, 2", }; diff --git a/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs b/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs index 2a6e5cf..67bf692 100644 --- a/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs +++ b/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs @@ -9,14 +9,14 @@ using AWS.S3.Models; using Core; using Core.Helpers; +using IIIF.Presentation.V3.Content; +using IIIF.Serialisation; using MediatR; using Microsoft.Extensions.Options; using Models.API.Collection; using Models.API.Collection.Upsert; using Models.API.General; using Models.Database.Collections; -using Newtonsoft.Json; -using NuGet.Protocol; using Repository; using Repository.Helpers; using IIdGenerator = API.Infrastructure.IdGenerator.IIdGenerator; @@ -28,7 +28,7 @@ public class CreateCollection(int customerId, UpsertFlatCollection collection, s { public int CustomerId { get; } = customerId; - public UpsertFlatCollection Collection { get; } = collection; + public UpsertFlatCollection? Collection { get; } = collection; public string RawRequestBody { get; } = rawRequestBody; @@ -80,11 +80,29 @@ public async Task(); + } + } + else + { + collection.Thumbnail = request.Collection.PresentationThumbnail; + } + await using var transaction = await dbContext.Database.BeginTransactionAsync(cancellationToken); @@ -99,32 +117,7 @@ await dbContext.TrySaveCollection(request.CustomerId, lo return saveErrors; } - if (!request.Collection.Behavior.IsStorageCollection()) - { - try - { - var collectionToSave = GenerateCollectionFromRawRequest(request.RawRequestBody); - - await bucketWriter.WriteToBucket( - new ObjectInBucket(settings.AWS.S3.StorageBucket, - $"{request.CustomerId}/collections/{collection.Id}"), - collectionToSave, "application/json", cancellationToken); - } - catch (JsonSerializationException ex) - { - logger.LogError(ex, "Error attempting to validate collection is IIIF"); - return ModifyEntityResult.Failure( - "Error attempting to validate collection is IIIF", ModifyCollectionType.CannotValidateIIIF, - WriteResult.BadRequest); - } - catch (Exception ex) - { - logger.LogError(ex, "An unknown exception occured while creating a new collection"); - return ModifyEntityResult.Failure( - "Unknown error occured while creating a collection", ModifyCollectionType.Unknown, - WriteResult.Error); - } - } + await UploadToS3IfRequiredAsync(request, collection.Id, convertedIIIFCollection!, cancellationToken); await transaction.CommitAsync(cancellationToken); @@ -138,9 +131,24 @@ await bucketWriter.WriteToBucket( WriteResult.Created); } - private static string GenerateCollectionFromRawRequest(string rawRequestBody) + private static string ConvertToIIIFCollection(CreateCollection request, Collection collection) + { + var collectionAsIIIF = request.RawRequestBody.FromJson(); + var convertedIIIFCollection = collectionAsIIIF.AsJson(); + var thumbnails = collectionAsIIIF.Thumbnail?.Select(c => c as Image).ToList(); + collection.Thumbnail = thumbnails!?.GetThumbnailPath(); + return convertedIIIFCollection; + } + + private async Task UploadToS3IfRequiredAsync(CreateCollection request, + string id, string convertedIIIFCollection, CancellationToken cancellationToken) { - var collection = rawRequestBody.FromJson(); - return collection.ToJson(); + if (!request.Collection.Behavior.IsStorageCollection()) + { + await bucketWriter.WriteToBucket( + new ObjectInBucket(settings.AWS.S3.StorageBucket, + $"{request.CustomerId}/collections/{id}"), + convertedIIIFCollection, "application/json", cancellationToken); + } } } \ No newline at end of file diff --git a/src/IIIFPresentation/API/Features/Storage/Requests/UpsertCollection.cs b/src/IIIFPresentation/API/Features/Storage/Requests/UpsertCollection.cs index 08dc7f6..fd5e3ca 100644 --- a/src/IIIFPresentation/API/Features/Storage/Requests/UpsertCollection.cs +++ b/src/IIIFPresentation/API/Features/Storage/Requests/UpsertCollection.cs @@ -79,7 +79,7 @@ public async Task Post(int customerId, [FromServices] UpsertFlatC return this.ValidationFailed(validation); } - return await HandleUpsert(new CreateCollection(customerId, collection!, rawRequestBody, GetUrlRoots())); + return await HandleUpsert(new CreateCollection(customerId, collection, rawRequestBody, GetUrlRoots())); } [Authorize] diff --git a/src/IIIFPresentation/Models/API/Collection/Upsert/UpsertFlatCollection.cs b/src/IIIFPresentation/Models/API/Collection/Upsert/UpsertFlatCollection.cs index 8e6c3d8..a48950d 100644 --- a/src/IIIFPresentation/Models/API/Collection/Upsert/UpsertFlatCollection.cs +++ b/src/IIIFPresentation/Models/API/Collection/Upsert/UpsertFlatCollection.cs @@ -1,4 +1,8 @@ -using IIIF.Presentation.V3.Strings; +using System.Diagnostics; +using IIIF.Presentation.V3.Content; +using IIIF.Presentation.V3.Strings; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; namespace Models.API.Collection.Upsert; @@ -14,7 +18,19 @@ public class UpsertFlatCollection public string? Tags { get; set; } - public string? Thumbnail { get; set; } + public string? PresentationThumbnail { get; set; } + + [JsonProperty("thumbnail")] + public object? ThumbnailFromRequest + { + set + { + if (value is not JArray) + { + PresentationThumbnail = value?.ToString(); + } + } + } public int? ItemsOrder { get; set; } } \ No newline at end of file From f17ba85a9053d32274a278124f8910542ab057e3 Mon Sep 17 00:00:00 2001 From: "jack.lewis" Date: Mon, 7 Oct 2024 13:54:45 +0100 Subject: [PATCH 2/7] change to make sure customer id is int --- src/IIIFPresentation/API/Features/Storage/StorageController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IIIFPresentation/API/Features/Storage/StorageController.cs b/src/IIIFPresentation/API/Features/Storage/StorageController.cs index 59514c4..4391738 100644 --- a/src/IIIFPresentation/API/Features/Storage/StorageController.cs +++ b/src/IIIFPresentation/API/Features/Storage/StorageController.cs @@ -20,7 +20,7 @@ namespace API.Features.Storage; -[Route("/{customerId}")] +[Route("/{customerId:int}")] [ApiController] public class StorageController(IAuthenticator authenticator, IOptions options, IMediator mediator) : PresentationController(options.Value, mediator) From 0bc5cba6b3857ac28ebb5b70a72045001604a7fa Mon Sep 17 00:00:00 2001 From: "jack.lewis" Date: Thu, 10 Oct 2024 09:55:49 +0100 Subject: [PATCH 3/7] Changes to remove null errors --- .../API/Features/Storage/Requests/CreateCollection.cs | 2 +- .../API/Features/Storage/StorageController.cs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs b/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs index 67bf692..96fb796 100644 --- a/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs +++ b/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs @@ -28,7 +28,7 @@ public class CreateCollection(int customerId, UpsertFlatCollection collection, s { public int CustomerId { get; } = customerId; - public UpsertFlatCollection? Collection { get; } = collection; + public UpsertFlatCollection Collection { get; } = collection; public string RawRequestBody { get; } = rawRequestBody; diff --git a/src/IIIFPresentation/API/Features/Storage/StorageController.cs b/src/IIIFPresentation/API/Features/Storage/StorageController.cs index 4391738..63aad7f 100644 --- a/src/IIIFPresentation/API/Features/Storage/StorageController.cs +++ b/src/IIIFPresentation/API/Features/Storage/StorageController.cs @@ -102,8 +102,14 @@ public async Task Post(int customerId, [FromServices] UpsertFlatC var rawRequestBody = await streamReader.ReadToEndAsync(); var collection = JsonConvert.DeserializeObject(rawRequestBody); - - var validation = await validator.ValidateAsync(collection!); + + if (collection == null) + { + return this.PresentationProblem("could not deserialize collection", null, (int)HttpStatusCode.BadRequest, + "Deserialization Error"); + } + + var validation = await validator.ValidateAsync(collection); if (!validation.IsValid) { From d07ff1202f8c4246438941fb958dab7773642d55 Mon Sep 17 00:00:00 2001 From: "jack.lewis" Date: Mon, 14 Oct 2024 09:27:44 +0100 Subject: [PATCH 4/7] fix github comment --- .../Storage/Requests/CreateCollection.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs b/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs index 96fb796..622cb56 100644 --- a/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs +++ b/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs @@ -135,11 +135,24 @@ private static string ConvertToIIIFCollection(CreateCollection request, Collecti { var collectionAsIIIF = request.RawRequestBody.FromJson(); var convertedIIIFCollection = collectionAsIIIF.AsJson(); - var thumbnails = collectionAsIIIF.Thumbnail?.Select(c => c as Image).ToList(); - collection.Thumbnail = thumbnails!?.GetThumbnailPath(); + var thumbnails = collectionAsIIIF.Thumbnail?.Where(CheckThumbnailIsImage).Select(c => (Image)c).ToList(); + if (thumbnails != null) + { + collection.Thumbnail = thumbnails.GetThumbnailPath(); + } return convertedIIIFCollection; } + private static bool CheckThumbnailIsImage(ExternalResource externalResource) + { + if (externalResource is Image) + { + return true; + } + + return false; + } + private async Task UploadToS3IfRequiredAsync(CreateCollection request, string id, string convertedIIIFCollection, CancellationToken cancellationToken) { From 258f129bf459cc4b9c1af4898b29dd415dee4ab8 Mon Sep 17 00:00:00 2001 From: "jack.lewis" Date: Mon, 14 Oct 2024 09:28:51 +0100 Subject: [PATCH 5/7] simplify check --- .../Features/Storage/Requests/CreateCollection.cs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs b/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs index 622cb56..ee70590 100644 --- a/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs +++ b/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs @@ -135,7 +135,7 @@ private static string ConvertToIIIFCollection(CreateCollection request, Collecti { var collectionAsIIIF = request.RawRequestBody.FromJson(); var convertedIIIFCollection = collectionAsIIIF.AsJson(); - var thumbnails = collectionAsIIIF.Thumbnail?.Where(CheckThumbnailIsImage).Select(c => (Image)c).ToList(); + var thumbnails = collectionAsIIIF.Thumbnail?.Where(c => c is Image).Select(c => (Image)c).ToList(); if (thumbnails != null) { collection.Thumbnail = thumbnails.GetThumbnailPath(); @@ -143,16 +143,6 @@ private static string ConvertToIIIFCollection(CreateCollection request, Collecti return convertedIIIFCollection; } - private static bool CheckThumbnailIsImage(ExternalResource externalResource) - { - if (externalResource is Image) - { - return true; - } - - return false; - } - private async Task UploadToS3IfRequiredAsync(CreateCollection request, string id, string convertedIIIFCollection, CancellationToken cancellationToken) { From 0f290ced1da98ea9cfdb04c49d8518ebdd5838db Mon Sep 17 00:00:00 2001 From: "jack.lewis" Date: Mon, 14 Oct 2024 09:54:22 +0100 Subject: [PATCH 6/7] remove unneeded transaction --- .../API/Features/Storage/Requests/CreateCollection.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs b/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs index ee70590..17e27fb 100644 --- a/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs +++ b/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs @@ -103,9 +103,6 @@ public async Task(request.CustomerId, lo } await UploadToS3IfRequiredAsync(request, collection.Id, convertedIIIFCollection!, cancellationToken); - - await transaction.CommitAsync(cancellationToken); if (collection.Parent != null) { From 36d0f2a4e05288c6353eb50db933e91372e8a8c6 Mon Sep 17 00:00:00 2001 From: "jack.lewis" Date: Wed, 16 Oct 2024 16:03:06 +0100 Subject: [PATCH 7/7] fixing code review comments --- .../API.Tests/Integration/ModifyCollectionTests.cs | 2 +- .../API/Features/Storage/Helpers/ErrorHelper.cs | 4 ++-- .../Features/Storage/Requests/CreateCollection.cs | 14 +++++++------- .../Storage/Requests/GetHierarchicalCollection.cs | 2 +- .../Storage/Requests/PostHierarchicalCollection.cs | 4 ++-- .../API/Features/Storage/StorageController.cs | 2 +- .../API/Helpers/CollectionHelperX.cs | 3 +++ 7 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/IIIFPresentation/API.Tests/Integration/ModifyCollectionTests.cs b/src/IIIFPresentation/API.Tests/Integration/ModifyCollectionTests.cs index 7e94bd4..d9424c5 100644 --- a/src/IIIFPresentation/API.Tests/Integration/ModifyCollectionTests.cs +++ b/src/IIIFPresentation/API.Tests/Integration/ModifyCollectionTests.cs @@ -181,7 +181,7 @@ public async Task CreateCollection_ReturnsError_WhenIsStorageCollectionFalseAndU // Assert response.StatusCode.Should().Be(HttpStatusCode.BadRequest); - error!.Detail.Should().Be("Error attempting to validate collection is IIIF"); + error!.Detail.Should().Be("An error occurred while attempting to validate the collection as IIIF"); } [Fact] diff --git a/src/IIIFPresentation/API/Features/Storage/Helpers/ErrorHelper.cs b/src/IIIFPresentation/API/Features/Storage/Helpers/ErrorHelper.cs index 2853e80..cbaa373 100644 --- a/src/IIIFPresentation/API/Features/Storage/Helpers/ErrorHelper.cs +++ b/src/IIIFPresentation/API/Features/Storage/Helpers/ErrorHelper.cs @@ -25,7 +25,7 @@ public static ModifyEntityResult CannotValida where TCollection : class { return ModifyEntityResult.Failure( - "Error attempting to validate collection is IIIF", ModifyCollectionType.CannotValidateIIIF, - WriteResult.BadRequest); + "An error occurred while attempting to validate the collection as IIIF", + ModifyCollectionType.CannotValidateIIIF, WriteResult.BadRequest); } } \ No newline at end of file diff --git a/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs b/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs index 17e27fb..c69e682 100644 --- a/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs +++ b/src/IIIFPresentation/API/Features/Storage/Requests/CreateCollection.cs @@ -94,7 +94,7 @@ public async Task(); } } @@ -114,7 +114,7 @@ await dbContext.TrySaveCollection(request.CustomerId, lo return saveErrors; } - await UploadToS3IfRequiredAsync(request, collection.Id, convertedIIIFCollection!, cancellationToken); + await UploadToS3IfRequiredAsync(request.Collection, collection, convertedIIIFCollection!, cancellationToken); if (collection.Parent != null) { @@ -130,7 +130,7 @@ private static string ConvertToIIIFCollection(CreateCollection request, Collecti { var collectionAsIIIF = request.RawRequestBody.FromJson(); var convertedIIIFCollection = collectionAsIIIF.AsJson(); - var thumbnails = collectionAsIIIF.Thumbnail?.Where(c => c is Image).Select(c => (Image)c).ToList(); + var thumbnails = collectionAsIIIF.Thumbnail?.OfType().ToList(); if (thumbnails != null) { collection.Thumbnail = thumbnails.GetThumbnailPath(); @@ -138,14 +138,14 @@ private static string ConvertToIIIFCollection(CreateCollection request, Collecti return convertedIIIFCollection; } - private async Task UploadToS3IfRequiredAsync(CreateCollection request, - string id, string convertedIIIFCollection, CancellationToken cancellationToken) + private async Task UploadToS3IfRequiredAsync(UpsertFlatCollection request, + Collection collection, string convertedIIIFCollection, CancellationToken cancellationToken) { - if (!request.Collection.Behavior.IsStorageCollection()) + if (!request.Behavior.IsStorageCollection()) { await bucketWriter.WriteToBucket( new ObjectInBucket(settings.AWS.S3.StorageBucket, - $"{request.CustomerId}/collections/{id}"), + collection.GetCollectionBucketKey()), convertedIIIFCollection, "application/json", cancellationToken); } } diff --git a/src/IIIFPresentation/API/Features/Storage/Requests/GetHierarchicalCollection.cs b/src/IIIFPresentation/API/Features/Storage/Requests/GetHierarchicalCollection.cs index 07f5ffb..5f086e0 100644 --- a/src/IIIFPresentation/API/Features/Storage/Requests/GetHierarchicalCollection.cs +++ b/src/IIIFPresentation/API/Features/Storage/Requests/GetHierarchicalCollection.cs @@ -40,7 +40,7 @@ public async Task Handle(GetHierarchicalCollection request, if (!collection.IsStorageCollection) { var objectFromS3 = await bucketReader.GetObjectFromBucket(new ObjectInBucket(settings.S3.StorageBucket, - $"{request.CustomerId}/collections/{collection.Id}"), cancellationToken); + collection.GetCollectionBucketKey()), cancellationToken); if (!objectFromS3.Stream.IsNull()) { diff --git a/src/IIIFPresentation/API/Features/Storage/Requests/PostHierarchicalCollection.cs b/src/IIIFPresentation/API/Features/Storage/Requests/PostHierarchicalCollection.cs index e1e952a..40649ed 100644 --- a/src/IIIFPresentation/API/Features/Storage/Requests/PostHierarchicalCollection.cs +++ b/src/IIIFPresentation/API/Features/Storage/Requests/PostHierarchicalCollection.cs @@ -76,7 +76,7 @@ await dbContext.TrySaveCollection(request.CustomerId, logger, await bucketWriter.WriteToBucket( new ObjectInBucket(settings.AWS.S3.StorageBucket, - $"{request.CustomerId}/collections/{collection.Id}"), + collection.GetCollectionBucketKey()), collectionFromBody.AsJson(), "application/json", cancellationToken); if (collection.Parent != null) @@ -120,7 +120,7 @@ private static DatabaseCollection.Collection CreateDatabaseCollection(PostHierar } catch (Exception ex) { - logger.LogError(ex, "Error attempting to validate collection is IIIF"); + logger.LogError(ex, "An error occurred while attempting to validate the collection as IIIF"); } return collection; diff --git a/src/IIIFPresentation/API/Features/Storage/StorageController.cs b/src/IIIFPresentation/API/Features/Storage/StorageController.cs index 63aad7f..e32698d 100644 --- a/src/IIIFPresentation/API/Features/Storage/StorageController.cs +++ b/src/IIIFPresentation/API/Features/Storage/StorageController.cs @@ -105,7 +105,7 @@ public async Task Post(int customerId, [FromServices] UpsertFlatC if (collection == null) { - return this.PresentationProblem("could not deserialize collection", null, (int)HttpStatusCode.BadRequest, + return this.PresentationProblem("Could not deserialize collection", null, (int)HttpStatusCode.BadRequest, "Deserialization Error"); } diff --git a/src/IIIFPresentation/API/Helpers/CollectionHelperX.cs b/src/IIIFPresentation/API/Helpers/CollectionHelperX.cs index 9ba94eb..95ec533 100644 --- a/src/IIIFPresentation/API/Helpers/CollectionHelperX.cs +++ b/src/IIIFPresentation/API/Helpers/CollectionHelperX.cs @@ -46,6 +46,9 @@ public static Uri GenerateFlatCollectionViewLast(this Collection collection, Url new( $"{collection.GenerateFlatCollectionId(urlRoots)}?page={lastPage}&pageSize={pageSize}{orderQueryParam}"); + public static string GetCollectionBucketKey(this Collection collection) => + $"{collection.CustomerId}/collections/{collection.Id}"; + public static string GenerateFullPath(this Collection collection, string itemSlug) => $"{(collection.Parent != null ? $"{collection.Slug}/" : string.Empty)}{itemSlug}";