Adds metadata and artwork provider configuration seeding

Seeds a disabled provider configuration for every loaded plugin supporting
a library type, so that libraries list the metadata and artwork providers
they can use. Configurations are seeded on startup, on library creation,
and reconciled when the library type changes, and are removed only when a
library or a plugin is deleted. Reads the library metadata providers
through the new provider configuration store.
This commit is contained in:
BinaryAlley committed 2026-08-26 19:14:35 +03:00
1 parent 9ae8c0c394
commit 00dcf3d471
20 files changed
+1139 -27

No files matched your search

@@ -5,6 +5,7 @@ using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.DomainEvents;
using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Infrastructure.Authorization;
using Lumina.Application.Common.Infrastructure.Plugins;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Contracts.Responses.MediaLibrary.Management;
@@ -37,6 +38,7 @@ public class AddLibraryCommandHandler : ICommandHandler<AddLibraryCommand, Resul
private readonly IDomainEventsQueue _domainEventsQueue;
private readonly IEnvironmentContext _environmentContext;
private readonly IAuthorizationService _authorizationService;
private readonly IMediaLibraryProviderConfigurationStore _providerConfigurationStore;
private readonly IValidator<AddLibraryCommand> _validator;
/// <summary>
@@ -46,13 +48,15 @@ public class AddLibraryCommandHandler : ICommandHandler<AddLibraryCommand, Resul
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
/// <param name="domainEventsQueue">Injected service for the queue of domain events.</param>
/// <param name="environmentContext">Injected facade service for environment contextual services.</param>
/// <param name="providerConfigurationStore">Injected store of the provider configurations of the media libraries.</param>
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
/// <param name="validator">Injected validator for application validation rules.</param>
public AddLibraryCommandHandler(
IAuthorizationService authorizationService,
ICurrentUserService currentUserService,
ICurrentUserService currentUserService,
IDomainEventsQueue domainEventsQueue,
IEnvironmentContext environmentContext,
IMediaLibraryProviderConfigurationStore providerConfigurationStore,
IUnitOfWork unitOfWork,
IValidator<AddLibraryCommand> validator)
{
@@ -61,6 +65,7 @@ public class AddLibraryCommandHandler : ICommandHandler<AddLibraryCommand, Resul
_domainEventsQueue = domainEventsQueue;
_environmentContext = environmentContext;
_authorizationService = authorizationService;
_providerConfigurationStore = providerConfigurationStore;
_validator = validator;
}
@@ -123,10 +128,15 @@ public class AddLibraryCommandHandler : ICommandHandler<AddLibraryCommand, Resul
// convert the domain library entity to a repository library entity
LibraryEntity persistenceLibrary = createLibraryResult.Value.ToRepositoryEntity();
// insert the repository entity and save changes
// insert the repository entity, seed the provider configurations of the new library so that it lists the plugins
// providing metadata or artwork for its type, and save the changes
Result<Created> insertLibraryResult = await _unitOfWork.LibraryRepository.InsertAsync(persistenceLibrary, cancellationToken).ConfigureAwait(false);
if (insertLibraryResult.IsFailure)
return insertLibraryResult.Errors;
Result<Success> ensureProviderConfigurationsResult = await _providerConfigurationStore.EnsureProviderConfigurationsAsync(
createLibraryResult.Value.Id.Value, Enum.Parse<LibraryType>(command.LibraryType!), cancellationToken).ConfigureAwait(false);
if (ensureProviderConfigurationsResult.IsFailure)
return ensureProviderConfigurationsResult.Errors;
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
// retrieve the newly saved media library from the persistence medium and return it
@@ -8,6 +8,7 @@ using Lumina.Application.Common.DomainEvents;
using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Infrastructure.Authorization;
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
using Lumina.Application.Common.Infrastructure.Plugins;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Domain.Common.Events;
@@ -31,6 +32,7 @@ public class DeleteLibraryCommandHandler : ICommandHandler<DeleteLibraryCommand,
private readonly ICurrentUserService _currentUserService;
private readonly IAuthorizationService _authorizationService;
private readonly IDomainEventsQueue _domainEventsQueue;
private readonly IMediaLibraryProviderConfigurationStore _providerConfigurationStore;
private readonly IValidator<DeleteLibraryCommand> _validator;
/// <summary>
@@ -39,18 +41,21 @@ public class DeleteLibraryCommandHandler : ICommandHandler<DeleteLibraryCommand,
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
/// <param name="domainEventsQueue">Injected service for the queue of domain events.</param>
/// <param name="providerConfigurationStore">Injected store of the provider configurations of the media libraries.</param>
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
/// <param name="validator">Injected validator for application validation rules.</param>
public DeleteLibraryCommandHandler(
IAuthorizationService authorizationService,
ICurrentUserService currentUserService,
IDomainEventsQueue domainEventsQueue,
IMediaLibraryProviderConfigurationStore providerConfigurationStore,
IUnitOfWork unitOfWork,
IValidator<DeleteLibraryCommand> validator)
{
_authorizationService = authorizationService;
_currentUserService = currentUserService;
_domainEventsQueue = domainEventsQueue;
_providerConfigurationStore = providerConfigurationStore;
_unitOfWork = unitOfWork;
_validator = validator;
}
@@ -100,7 +105,10 @@ public class DeleteLibraryCommandHandler : ICommandHandler<DeleteLibraryCommand,
foreach (IDomainEvent domainEvent in createLibraryResult.Value.GetDomainEvents())
_domainEventsQueue.Enqueue(domainEvent);
// perform the deletion
// remove the provider configurations of the library, so that they are not orphaned, and delete the library
Result<Deleted> removeProviderConfigurationsResult = await _providerConfigurationStore.RemoveProviderConfigurationsForLibraryAsync(command.Id, cancellationToken).ConfigureAwait(false);
if (removeProviderConfigurationsResult.IsFailure)
return removeProviderConfigurationsResult.Errors;
Result<Deleted> deletePersistenceLibraryResult = await _unitOfWork.LibraryRepository.DeleteByIdAsync(command.Id, cancellationToken).ConfigureAwait(false);
if (deletePersistenceLibraryResult.IsFailure)
return deletePersistenceLibraryResult.Errors;
@@ -6,6 +6,7 @@ using Lumina.Application.Common.DomainEvents;
using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Infrastructure.Authorization;
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
using Lumina.Application.Common.Infrastructure.Plugins;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Contracts.Responses.MediaLibrary.Management;
@@ -41,6 +42,7 @@ public class UpdateLibraryCommandHandler : ICommandHandler<UpdateLibraryCommand,
private readonly IAuthorizationService _authorizationService;
private readonly IDomainEventsQueue _domainEventsQueue;
private readonly IEnvironmentContext _environmentContext;
private readonly IMediaLibraryProviderConfigurationStore _providerConfigurationStore;
private readonly IValidator<UpdateLibraryCommand> _validator;
/// <summary>
@@ -50,13 +52,15 @@ public class UpdateLibraryCommandHandler : ICommandHandler<UpdateLibraryCommand,
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
/// <param name="domainEventsQueue">Injected service for the queue of domain events.</param>
/// <param name="environmentContext">Injected facade service for environment contextual services.</param>
/// <param name="providerConfigurationStore">Injected store of the provider configurations of the media libraries.</param>
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
/// <param name="validator">Injected validator for application validation rules.</param>
public UpdateLibraryCommandHandler(
IAuthorizationService authorizationService,
IAuthorizationService authorizationService,
ICurrentUserService currentUserService,
IDomainEventsQueue domainEventsQueue,
IEnvironmentContext environmentContext,
IMediaLibraryProviderConfigurationStore providerConfigurationStore,
IUnitOfWork unitOfWork,
IValidator<UpdateLibraryCommand> validator)
{
@@ -65,6 +69,7 @@ public class UpdateLibraryCommandHandler : ICommandHandler<UpdateLibraryCommand,
_unitOfWork = unitOfWork;
_domainEventsQueue = domainEventsQueue;
_environmentContext = environmentContext;
_providerConfigurationStore = providerConfigurationStore;
_validator = validator;
}
@@ -117,11 +122,12 @@ public class UpdateLibraryCommandHandler : ICommandHandler<UpdateLibraryCommand,
return ApplicationErrors.Authorization.NotAuthorized;
// create a domain library object
LibraryType newLibraryType = Enum.Parse<LibraryType>(command.LibraryType!);
Result<Library> createLibraryResult = Library.Create(
LibraryId.Create(command.Id),
UserId.Create(command.OwnerId),
command.Title!,
Enum.Parse<LibraryType>(command.LibraryType!),
newLibraryType,
command.ContentLocations!,
command.CoverImage,
command.IsEnabled,
@@ -136,10 +142,17 @@ public class UpdateLibraryCommandHandler : ICommandHandler<UpdateLibraryCommand,
// convert the domain library entity to a repository library entity
LibraryEntity persistenceLibrary = createLibraryResult.Value.ToRepositoryEntity();
// update the repository entity and save changes
// update the repository entity, and when the library type changed, reconcile the provider configurations so that
// they match the plugins supporting the new type, and save the changes
Result<Updated> updateLibraryResult = await _unitOfWork.LibraryRepository.UpdateAsync(persistenceLibrary, cancellationToken).ConfigureAwait(false);
if (updateLibraryResult.IsFailure)
return updateLibraryResult.Errors;
if (getLibraryResult.Value.LibraryType != newLibraryType)
{
Result<Success> reconcileResult = await _providerConfigurationStore.ReconcileProviderConfigurationsAsync(command.Id, newLibraryType, cancellationToken).ConfigureAwait(false);
if (reconcileResult.IsFailure)
return reconcileResult.Errors;
}
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
// retrieve the updated media library from the persistence medium and return it
@@ -5,6 +5,7 @@ using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Infrastructure.Authorization;
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
using Lumina.Application.Common.Infrastructure.Plugins;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Mapping.Plugins;
using Lumina.Contracts.Responses.Plugins;
@@ -27,6 +28,7 @@ public class GetLibraryMetadataProvidersQueryHandler : IQueryHandler<GetLibraryM
private readonly IUnitOfWork _unitOfWork;
private readonly IAuthorizationService _authorizationService;
private readonly ICurrentUserService _currentUserService;
private readonly IMediaLibraryProviderConfigurationStore _providerConfigurationStore;
private readonly IValidator<GetLibraryMetadataProvidersQuery> _validator;
/// <summary>
@@ -34,12 +36,14 @@ public class GetLibraryMetadataProvidersQueryHandler : IQueryHandler<GetLibraryM
/// </summary>
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
/// <param name="providerConfigurationStore">Injected store of the provider configurations of the media libraries.</param>
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
/// <param name="validator">Injected validator for application validation rules.</param>
public GetLibraryMetadataProvidersQueryHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IUnitOfWork unitOfWork, IValidator<GetLibraryMetadataProvidersQuery> validator)
public GetLibraryMetadataProvidersQueryHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IMediaLibraryProviderConfigurationStore providerConfigurationStore, IUnitOfWork unitOfWork, IValidator<GetLibraryMetadataProvidersQuery> validator)
{
_authorizationService = authorizationService;
_currentUserService = currentUserService;
_providerConfigurationStore = providerConfigurationStore;
_unitOfWork = unitOfWork;
_validator = validator;
}
@@ -70,7 +74,7 @@ public class GetLibraryMetadataProvidersQueryHandler : IQueryHandler<GetLibraryM
if (!canAccessLibrary)
return ApplicationErrors.Authorization.NotAuthorized;
Result<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await _unitOfWork.LibraryMetadataProviderConfigurationRepository.GetByLibraryIdAsync(query.LibraryId, cancellationToken).ConfigureAwait(false);
Result<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await _providerConfigurationStore.GetConfigurationsAsync(query.LibraryId, cancellationToken).ConfigureAwait(false);
if (getConfigurationsResult.IsFailure)
return getConfigurationsResult.Errors;