mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 10:11:10 +00:00
Adds independent metadata and artwork enrichment
Splits the single combined enrichment phase of the media library scan into independent, modular jobs, so that the metadata and the artwork of a book are enriched separately and only when their respective triggers fire. - Adds the MediaContributorRoleCategory enum (Other first, then Author, Translator, Illustrator, Publisher and Narrator) and makes the role category canonical, so that roles describing the same kind of contribution are never treated as distinct. - Realizes the media contributor bounded context: a MediaContributor is a person, unique by display name, without a role. The role moves to the per-work participation (BookContributors), so that a single contributor can play multiple roles. Contributors are created and linked by the metadata enrichment job, and exposed to subsequent jobs. - Makes the Book aggregate pure: the enrichment tracking state (metadata status, providers, timestamps and covers) no longer lives on the domain aggregate, but stays in the Books table, managed directly by the jobs. - Models artwork generically as a BookArtwork child table (type, ordinal, content hash, status and provider), so that each piece of artwork is tracked independently and a change of one does not require the others to be re-fetched. - Splits the scan DAG into ResultsSave, ProviderConfigurationInvalidation, MetadataEnrichment and ArtworkEnrichment jobs. The invalidation job fingerprints the provider configuration of a library and resets the enrichment state of the affected channel when it changed. The artwork job resolves the missing artwork, hashing it to detect identical covers and skip re-copying. Content-changed books are reset by the results save job. - Deletes the book and its stored artwork when the file disappears from the library. - Adds the migration creating the new tables, backfilling the existing covers into the artwork table, and adding the configuration fingerprints. - Localizes the new scan job stages, and fixes the invalidation job wiping the library content locations by persisting the fingerprints through the change tracker instead of the repository update action.
This commit is contained in:
1 parent
4ee2976806
commit
565fe68239
98 files changed
+5845
-630
No files matched your search
+33
-10
@@ -2,6 +2,7 @@
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -17,7 +18,7 @@ public class MediaContributorTests
|
||||
{
|
||||
private readonly MediaContributorIdFixture _mediaContributorIdFixture = new();
|
||||
private readonly MediaContributorNameFixture _mediaContributorNameFixture = new();
|
||||
private readonly MediaContributorRoleFixture _mediaContributorRoleFixture = new();
|
||||
private readonly MediaContributorFixture _mediaContributorFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithPreExistingIdAndValues_ShouldCreateContributor()
|
||||
@@ -25,22 +26,22 @@ public class MediaContributorTests
|
||||
// Arrange
|
||||
MediaContributorId id = _mediaContributorIdFixture.Create();
|
||||
MediaContributorName name = _mediaContributorNameFixture.Create(displayName: "Jane Doe", legalName: Optional<string>.Some("Jane Doe Smith"));
|
||||
MediaContributorRole role = _mediaContributorRoleFixture.Create(name: "Actor", category: "Crew");
|
||||
Optional<string> biography = Optional<string>.Some("A well-known author.");
|
||||
Optional<DateOnly> dateOfBirth = Optional<DateOnly>.Some(new DateOnly(1980, 1, 1));
|
||||
Optional<DateOnly> dateOfDeath = Optional<DateOnly>.None();
|
||||
|
||||
// Act
|
||||
Result<MediaContributor> result = MediaContributor.Create(id, name, role, dateOfBirth, dateOfDeath);
|
||||
Result<MediaContributor> result = MediaContributor.Create(id, name, biography, dateOfBirth, dateOfDeath);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(id, result.Value.Id);
|
||||
Assert.Equal(name, result.Value.Name);
|
||||
Assert.Equal(role, result.Value.Role);
|
||||
Assert.True(result.Value.Biography.HasValue);
|
||||
Assert.Equal("A well-known author.", result.Value.Biography.Value);
|
||||
Assert.True(result.Value.DateOfBirth.HasValue);
|
||||
Assert.Equal(new DateOnly(1980, 1, 1), result.Value.DateOfBirth.Value);
|
||||
Assert.False(result.Value.DateOfDeath.HasValue);
|
||||
Assert.False(result.Value.Biography.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -48,24 +49,46 @@ public class MediaContributorTests
|
||||
{
|
||||
// Arrange
|
||||
MediaContributorName name = _mediaContributorNameFixture.Create(displayName: "Jane Doe", legalName: Optional<string>.None());
|
||||
MediaContributorRole role = _mediaContributorRoleFixture.Create(name: "Actor", category: "Crew");
|
||||
|
||||
// Act
|
||||
Result<MediaContributor> result = MediaContributor.Create(_mediaContributorIdFixture.Create(), name, role, Optional<DateOnly>.None(), Optional<DateOnly>.None());
|
||||
Result<MediaContributor> result = MediaContributor.Create(_mediaContributorIdFixture.Create(), name, Optional<string>.None(), Optional<DateOnly>.None(), Optional<DateOnly>.None());
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(result.Value.Biography.HasValue);
|
||||
Assert.False(result.Value.DateOfBirth.HasValue);
|
||||
Assert.False(result.Value.DateOfDeath.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithoutId_ShouldThrowNotImplementedException()
|
||||
public void Create_WhenCalledWithoutId_ShouldCreateContributorWithGeneratedId()
|
||||
{
|
||||
// Arrange
|
||||
MediaContributorName name = _mediaContributorNameFixture.Create(displayName: "Jane Doe", legalName: Optional<string>.None());
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<NotImplementedException>(() => MediaContributor.Create(name));
|
||||
// Act
|
||||
Result<MediaContributor> result = MediaContributor.Create(name);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotNull(result.Value.Id);
|
||||
Assert.Equal(name, result.Value.Name);
|
||||
Assert.False(result.Value.Biography.HasValue);
|
||||
Assert.False(result.Value.DateOfBirth.HasValue);
|
||||
Assert.False(result.Value.DateOfDeath.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithPreExistingId_ShouldNotContainARole()
|
||||
{
|
||||
// Arrange
|
||||
MediaContributor contributor = _mediaContributorFixture.Create();
|
||||
|
||||
// Act
|
||||
Type contributorType = contributor.GetType();
|
||||
|
||||
// Assert
|
||||
// the contributor is a person, agnostic of the roles it played in the media items, so it must not expose a role
|
||||
Assert.Null(contributorType.GetProperty("Role"));
|
||||
}
|
||||
}
|
||||
+26
-11
@@ -1,6 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -15,22 +18,34 @@ public class MediaContributorRoleTests
|
||||
private readonly MediaContributorRoleFixture _mediaContributorRoleFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithNameAndCategory_ShouldCreateRole()
|
||||
public void Create_WhenCalledWithDisplayNameAndCategory_ShouldCreateRole()
|
||||
{
|
||||
// Act
|
||||
MediaContributorRole role = MediaContributorRole.Create("Actor", "Crew");
|
||||
Result<MediaContributorRole> result = MediaContributorRole.Create("Author", MediaContributorRoleCategory.Author);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Actor", role.Name);
|
||||
Assert.Equal("Crew", role.Category);
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("Author", result.Value.DisplayName);
|
||||
Assert.Equal(MediaContributorRoleCategory.Author, result.Value.Category);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithEmptyDisplayName_ShouldReturnError()
|
||||
{
|
||||
// Act
|
||||
Result<MediaContributorRole> result = MediaContributorRole.Create(" ", MediaContributorRoleCategory.Author);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.MediaContributors.MediaContributorRoleNameCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValues_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
MediaContributorRole firstRole = _mediaContributorRoleFixture.Create(name: "Actor", category: "Crew");
|
||||
MediaContributorRole secondRole = _mediaContributorRoleFixture.Create(name: "Actor", category: "Crew");
|
||||
MediaContributorRole firstRole = _mediaContributorRoleFixture.Create(name: "Author", category: MediaContributorRoleCategory.Author);
|
||||
MediaContributorRole secondRole = _mediaContributorRoleFixture.Create(name: "Author", category: MediaContributorRoleCategory.Author);
|
||||
|
||||
// Act
|
||||
bool result = firstRole.Equals(secondRole);
|
||||
@@ -40,11 +55,11 @@ public class MediaContributorRoleTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentName_ShouldReturnFalse()
|
||||
public void Equals_WithDifferentDisplayName_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MediaContributorRole firstRole = _mediaContributorRoleFixture.Create(name: "Actor", category: "Crew");
|
||||
MediaContributorRole secondRole = _mediaContributorRoleFixture.Create(name: "Director", category: "Crew");
|
||||
MediaContributorRole firstRole = _mediaContributorRoleFixture.Create(name: "Author", category: MediaContributorRoleCategory.Author);
|
||||
MediaContributorRole secondRole = _mediaContributorRoleFixture.Create(name: "Writer", category: MediaContributorRoleCategory.Author);
|
||||
|
||||
// Act
|
||||
bool result = firstRole.Equals(secondRole);
|
||||
@@ -57,8 +72,8 @@ public class MediaContributorRoleTests
|
||||
public void Equals_WithDifferentCategory_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MediaContributorRole firstRole = _mediaContributorRoleFixture.Create(name: "Actor", category: "Crew");
|
||||
MediaContributorRole secondRole = _mediaContributorRoleFixture.Create(name: "Actor", category: "Voice");
|
||||
MediaContributorRole firstRole = _mediaContributorRoleFixture.Create(name: "Author", category: MediaContributorRoleCategory.Author);
|
||||
MediaContributorRole secondRole = _mediaContributorRoleFixture.Create(name: "Author", category: MediaContributorRoleCategory.Translator);
|
||||
|
||||
// Act
|
||||
bool result = firstRole.Equals(secondRole);
|
||||
|
||||
+44
-14
@@ -1,8 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -15,46 +18,73 @@ namespace Lumina.Domain.UnitTests.Core.BoundedContexts.WrittenContentLibraryBoun
|
||||
public class BookTests
|
||||
{
|
||||
private readonly BookFixture _bookFixture = new();
|
||||
private readonly MediaContributorIdFixture _mediaContributorIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValidData_ShouldCreateBookWithPendingMetadataStatus()
|
||||
public void Create_WhenCalledWithValidData_ShouldCreateBook()
|
||||
{
|
||||
// Act
|
||||
Book book = _bookFixture.Create();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(book);
|
||||
Assert.Equal(MetadataStatus.Pending, book.MetadataStatus);
|
||||
Assert.False(book.LastMetadataUpdateUtc.HasValue);
|
||||
Assert.False(book.MetadataProvider.HasValue);
|
||||
Assert.NotNull(book.Metadata);
|
||||
Assert.NotNull(book.Path);
|
||||
Assert.NotNull(book.LibraryId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MarkMetadataAsEnriched_WhenCalled_ShouldUpdateStatusAndProvider()
|
||||
public void UpdateContributors_WhenCalled_ShouldReplaceTheContributors()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
DateTime lastUpdateUtc = DateTime.UtcNow;
|
||||
MediaContributorId firstContributorId = _mediaContributorIdFixture.Create();
|
||||
MediaContributorId secondContributorId = _mediaContributorIdFixture.Create();
|
||||
|
||||
// Act
|
||||
book.MarkMetadataAsEnriched("Goodreads", lastUpdateUtc);
|
||||
book.UpdateContributors([firstContributorId, secondContributorId]);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(MetadataStatus.Enriched, book.MetadataStatus);
|
||||
Assert.Equal("Goodreads", book.MetadataProvider.Value);
|
||||
Assert.Equal(lastUpdateUtc, book.LastMetadataUpdateUtc.Value);
|
||||
Assert.Equal(2, book.Contributors.Count);
|
||||
Assert.Contains(book.Contributors, contributorId => contributorId == firstContributorId);
|
||||
Assert.Contains(book.Contributors, contributorId => contributorId == secondContributorId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MarkMetadataAsFailed_WhenCalled_ShouldUpdateStatus()
|
||||
public void UpdateContributors_WhenCalledAgain_ShouldReplaceTheContributors()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
book.UpdateContributors([_mediaContributorIdFixture.Create()]);
|
||||
MediaContributorId replacementContributorId = _mediaContributorIdFixture.Create();
|
||||
|
||||
// Act
|
||||
book.MarkMetadataAsFailed();
|
||||
book.UpdateContributors([replacementContributorId]);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(MetadataStatus.Failed, book.MetadataStatus);
|
||||
// the previous contributors are replaced, not appended
|
||||
MediaContributorId contributorId = Assert.Single(book.Contributors);
|
||||
Assert.Equal(replacementContributorId, contributorId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalled_ShouldNotExposeEnrichmentTracking()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
Type bookType = book.GetType();
|
||||
|
||||
// Act
|
||||
bool hasMetadataStatus = bookType.GetProperty("MetadataStatus") is not null;
|
||||
bool hasLastMetadataUpdateUtc = bookType.GetProperty("LastMetadataUpdateUtc") is not null;
|
||||
bool hasMetadataProvider = bookType.GetProperty("MetadataProvider") is not null;
|
||||
bool hasCoverImagePath = bookType.GetProperty("CoverImagePath") is not null;
|
||||
|
||||
// Assert
|
||||
// the enrichment state is a persistence concern, tracked on the repository entity by the enrichment jobs
|
||||
Assert.False(hasMetadataStatus);
|
||||
Assert.False(hasLastMetadataUpdateUtc);
|
||||
Assert.False(hasMetadataProvider);
|
||||
Assert.False(hasCoverImagePath);
|
||||
}
|
||||
}
|
||||
+17
-4
@@ -40,7 +40,7 @@ public class BookLibraryTypeScannerTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateScanJobsForLibrary_WhenCalled_ShouldCreateJobChainWithMetadataEnrichment()
|
||||
public void CreateScanJobsForLibrary_WhenCalled_ShouldCreateJobChainWithEnrichmentJobs()
|
||||
{
|
||||
// Arrange
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
@@ -48,7 +48,9 @@ public class BookLibraryTypeScannerTests
|
||||
TestScanJob diffJob = CreateJob<IMediaLibraryScanDiffJob>();
|
||||
TestScanJob hashJob = CreateJob<IMediaLibraryScanHashJob>();
|
||||
TestScanJob saveJob = CreateJob<IMediaLibraryScanResultsSaveJob>();
|
||||
TestScanJob invalidationJob = CreateJob<IMediaLibraryScanProviderConfigurationInvalidationJob>();
|
||||
TestScanJob enrichmentJob = CreateJob<IMediaLibraryScanMetadataEnrichmentJob>();
|
||||
TestScanJob artworkEnrichmentJob = CreateJob<IMediaLibraryScanArtworkEnrichmentJob>();
|
||||
BookLibraryTypeScanner sut = new(_mockJobFactory);
|
||||
|
||||
// Act
|
||||
@@ -63,9 +65,14 @@ public class BookLibraryTypeScannerTests
|
||||
Assert.Contains(diffJob, hashJob.Parents);
|
||||
Assert.Contains(saveJob, hashJob.Children);
|
||||
Assert.Contains(hashJob, saveJob.Parents);
|
||||
Assert.Contains(enrichmentJob, saveJob.Children);
|
||||
Assert.Contains(saveJob, enrichmentJob.Parents);
|
||||
Assert.Contains(invalidationJob, saveJob.Children);
|
||||
Assert.Contains(saveJob, invalidationJob.Parents);
|
||||
Assert.Contains(enrichmentJob, invalidationJob.Children);
|
||||
Assert.Contains(invalidationJob, enrichmentJob.Parents);
|
||||
Assert.Contains(artworkEnrichmentJob, enrichmentJob.Children);
|
||||
Assert.Contains(enrichmentJob, artworkEnrichmentJob.Parents);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanMetadataEnrichmentJob>(libraryId);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanArtworkEnrichmentJob>(libraryId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -77,7 +84,9 @@ public class BookLibraryTypeScannerTests
|
||||
CreateJob<IMediaLibraryScanDiffJob>();
|
||||
CreateJob<IMediaLibraryScanHashJob>();
|
||||
CreateJob<IMediaLibraryScanResultsSaveJob>();
|
||||
CreateJob<IMediaLibraryScanProviderConfigurationInvalidationJob>();
|
||||
CreateJob<IMediaLibraryScanMetadataEnrichmentJob>();
|
||||
CreateJob<IMediaLibraryScanArtworkEnrichmentJob>();
|
||||
BookLibraryTypeScanner sut = new(_mockJobFactory);
|
||||
|
||||
// Act
|
||||
@@ -88,7 +97,9 @@ public class BookLibraryTypeScannerTests
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanDiffJob>(libraryId);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanHashJob>(libraryId);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanResultsSaveJob>(libraryId);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanProviderConfigurationInvalidationJob>(libraryId);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanMetadataEnrichmentJob>(libraryId);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanArtworkEnrichmentJob>(libraryId);
|
||||
}
|
||||
|
||||
private TestScanJob CreateJob<TJob>() where TJob : class, IMediaLibraryScanJob
|
||||
@@ -111,7 +122,9 @@ public class BookLibraryTypeScannerTests
|
||||
IMediaLibraryScanDiffJob,
|
||||
IMediaLibraryScanHashJob,
|
||||
IMediaLibraryScanResultsSaveJob,
|
||||
IMediaLibraryScanMetadataEnrichmentJob
|
||||
IMediaLibraryScanProviderConfigurationInvalidationJob,
|
||||
IMediaLibraryScanMetadataEnrichmentJob,
|
||||
IMediaLibraryScanArtworkEnrichmentJob
|
||||
{
|
||||
/// <summary>
|
||||
/// Executes the payload of the media library scan job.
|
||||
|
||||
Reference in new issue
Block a user