From 7d045d5c5444b980c3325310420911ff2b1b19cf Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 8 Oct 2017 15:09:46 -0400 Subject: [PATCH] Cleanup RootFolderService and Validation --- src/Lidarr.Api.V3/Artist/ArtistModule.cs | 4 +-- src/NzbDrone.Core/Music/AddArtistValidator.cs | 8 +++--- src/NzbDrone.Core/NzbDrone.Core.csproj | 4 +-- .../RootFolders/RootFolderService.cs | 14 +++++----- src/NzbDrone.Core/Tv/AddSeriesValidator.cs | 6 +---- .../Paths/ArtistAncestorValidator.cs | 25 +++++++++++++++++ .../Paths/SeriesAncestorValidator.cs | 25 ----------------- .../Validation/Paths/SeriesExistsValidator.cs | 26 ------------------ .../Validation/Paths/SeriesPathValidator.cs | 27 ------------------- 9 files changed, 40 insertions(+), 99 deletions(-) create mode 100644 src/NzbDrone.Core/Validation/Paths/ArtistAncestorValidator.cs delete mode 100644 src/NzbDrone.Core/Validation/Paths/SeriesAncestorValidator.cs delete mode 100644 src/NzbDrone.Core/Validation/Paths/SeriesExistsValidator.cs delete mode 100644 src/NzbDrone.Core/Validation/Paths/SeriesPathValidator.cs diff --git a/src/Lidarr.Api.V3/Artist/ArtistModule.cs b/src/Lidarr.Api.V3/Artist/ArtistModule.cs index 17dee9810..0b8707917 100644 --- a/src/Lidarr.Api.V3/Artist/ArtistModule.cs +++ b/src/Lidarr.Api.V3/Artist/ArtistModule.cs @@ -47,7 +47,7 @@ namespace Lidarr.Api.V3.Artist RootFolderValidator rootFolderValidator, ArtistPathValidator artistPathValidator, ArtistExistsValidator artistExistsValidator, - SeriesAncestorValidator seriesAncestorValidator, + ArtistAncestorValidator artistAncestorValidator, ProfileExistsValidator profileExistsValidator, LanguageProfileExistsValidator languageProfileExistsValidator ) @@ -73,7 +73,7 @@ namespace Lidarr.Api.V3.Artist .IsValidPath() .SetValidator(rootFolderValidator) .SetValidator(artistPathValidator) - .SetValidator(seriesAncestorValidator) + .SetValidator(artistAncestorValidator) .When(s => !s.Path.IsNullOrWhiteSpace()); SharedValidator.RuleFor(s => s.QualityProfileId).SetValidator(profileExistsValidator); diff --git a/src/NzbDrone.Core/Music/AddArtistValidator.cs b/src/NzbDrone.Core/Music/AddArtistValidator.cs index 2a03ed990..4a8f84967 100644 --- a/src/NzbDrone.Core/Music/AddArtistValidator.cs +++ b/src/NzbDrone.Core/Music/AddArtistValidator.cs @@ -16,15 +16,15 @@ namespace NzbDrone.Core.Music public class AddArtistValidator : AbstractValidator, IAddArtistValidator { public AddArtistValidator(RootFolderValidator rootFolderValidator, - SeriesPathValidator seriesPathValidator, - SeriesAncestorValidator seriesAncestorValidator, + ArtistPathValidator artistPathValidator, + ArtistAncestorValidator artistAncestorValidator, ArtistSlugValidator artistTitleSlugValidator) { RuleFor(c => c.Path).Cascade(CascadeMode.StopOnFirstFailure) .IsValidPath() .SetValidator(rootFolderValidator) - .SetValidator(seriesPathValidator) - .SetValidator(seriesAncestorValidator); + .SetValidator(artistPathValidator) + .SetValidator(artistAncestorValidator); RuleFor(c => c.NameSlug).SetValidator(artistTitleSlugValidator);// TODO: Check if we are going to use a slug or artistName } diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 387daa5c8..529481c81 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -1216,9 +1216,7 @@ - - - + diff --git a/src/NzbDrone.Core/RootFolders/RootFolderService.cs b/src/NzbDrone.Core/RootFolders/RootFolderService.cs index 7360b5c61..4ee118524 100644 --- a/src/NzbDrone.Core/RootFolders/RootFolderService.cs +++ b/src/NzbDrone.Core/RootFolders/RootFolderService.cs @@ -7,7 +7,7 @@ using NzbDrone.Common; using NzbDrone.Common.Disk; using NzbDrone.Common.Extensions; using NzbDrone.Core.Configuration; -using NzbDrone.Core.Tv; +using NzbDrone.Core.Music; namespace NzbDrone.Core.RootFolders { @@ -24,7 +24,7 @@ namespace NzbDrone.Core.RootFolders { private readonly IRootFolderRepository _rootFolderRepository; private readonly IDiskProvider _diskProvider; - private readonly ISeriesRepository _seriesRepository; + private readonly IArtistRepository _artistRepository; private readonly IConfigService _configService; private readonly Logger _logger; @@ -44,13 +44,13 @@ namespace NzbDrone.Core.RootFolders public RootFolderService(IRootFolderRepository rootFolderRepository, IDiskProvider diskProvider, - ISeriesRepository seriesRepository, + IArtistRepository artistRepository, IConfigService configService, Logger logger) { _rootFolderRepository = rootFolderRepository; _diskProvider = diskProvider; - _seriesRepository = seriesRepository; + _artistRepository = artistRepository; _configService = configService; _logger = logger; } @@ -134,7 +134,7 @@ namespace NzbDrone.Core.RootFolders } var results = new List(); - var series = _seriesRepository.All().ToList(); + var artist = _artistRepository.All().ToList(); if (!_diskProvider.FolderExists(path)) { @@ -142,8 +142,8 @@ namespace NzbDrone.Core.RootFolders return results; } - var possibleSeriesFolders = _diskProvider.GetDirectories(path).ToList(); - var unmappedFolders = possibleSeriesFolders.Except(series.Select(s => s.Path), PathEqualityComparer.Instance).ToList(); + var possibleArtistFolders = _diskProvider.GetDirectories(path).ToList(); + var unmappedFolders = possibleArtistFolders.Except(artist.Select(s => s.Path), PathEqualityComparer.Instance).ToList(); foreach (string unmappedFolder in unmappedFolders) { diff --git a/src/NzbDrone.Core/Tv/AddSeriesValidator.cs b/src/NzbDrone.Core/Tv/AddSeriesValidator.cs index a4fda6b4a..9a608b478 100644 --- a/src/NzbDrone.Core/Tv/AddSeriesValidator.cs +++ b/src/NzbDrone.Core/Tv/AddSeriesValidator.cs @@ -12,15 +12,11 @@ namespace NzbDrone.Core.Tv public class AddSeriesValidator : AbstractValidator, IAddSeriesValidator { public AddSeriesValidator(RootFolderValidator rootFolderValidator, - SeriesPathValidator seriesPathValidator, - SeriesAncestorValidator seriesAncestorValidator, SeriesTitleSlugValidator seriesTitleSlugValidator) { RuleFor(c => c.Path).Cascade(CascadeMode.StopOnFirstFailure) .IsValidPath() - .SetValidator(rootFolderValidator) - .SetValidator(seriesPathValidator) - .SetValidator(seriesAncestorValidator); + .SetValidator(rootFolderValidator); RuleFor(c => c.TitleSlug).SetValidator(seriesTitleSlugValidator); } diff --git a/src/NzbDrone.Core/Validation/Paths/ArtistAncestorValidator.cs b/src/NzbDrone.Core/Validation/Paths/ArtistAncestorValidator.cs new file mode 100644 index 000000000..6ba36edfe --- /dev/null +++ b/src/NzbDrone.Core/Validation/Paths/ArtistAncestorValidator.cs @@ -0,0 +1,25 @@ +using System.Linq; +using FluentValidation.Validators; +using NzbDrone.Common.Extensions; +using NzbDrone.Core.Music; + +namespace NzbDrone.Core.Validation.Paths +{ + public class ArtistAncestorValidator : PropertyValidator + { + private readonly IArtistService _artistService; + + public ArtistAncestorValidator(IArtistService artistService) + : base("Path is an ancestor of an existing path") + { + _artistService = artistService; + } + + protected override bool IsValid(PropertyValidatorContext context) + { + if (context.PropertyValue == null) return true; + + return !_artistService.GetAllArtists().Any(s => context.PropertyValue.ToString().IsParentPath(s.Path)); + } + } +} diff --git a/src/NzbDrone.Core/Validation/Paths/SeriesAncestorValidator.cs b/src/NzbDrone.Core/Validation/Paths/SeriesAncestorValidator.cs deleted file mode 100644 index c91560873..000000000 --- a/src/NzbDrone.Core/Validation/Paths/SeriesAncestorValidator.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Linq; -using FluentValidation.Validators; -using NzbDrone.Common.Extensions; -using NzbDrone.Core.Tv; - -namespace NzbDrone.Core.Validation.Paths -{ - public class SeriesAncestorValidator : PropertyValidator - { - private readonly ISeriesService _seriesService; - - public SeriesAncestorValidator(ISeriesService seriesService) - : base("Path is an ancestor of an existing path") - { - _seriesService = seriesService; - } - - protected override bool IsValid(PropertyValidatorContext context) - { - if (context.PropertyValue == null) return true; - - return !_seriesService.GetAllSeries().Any(s => context.PropertyValue.ToString().IsParentPath(s.Path)); - } - } -} \ No newline at end of file diff --git a/src/NzbDrone.Core/Validation/Paths/SeriesExistsValidator.cs b/src/NzbDrone.Core/Validation/Paths/SeriesExistsValidator.cs deleted file mode 100644 index 21e4ea629..000000000 --- a/src/NzbDrone.Core/Validation/Paths/SeriesExistsValidator.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using FluentValidation.Validators; -using NzbDrone.Core.Tv; - -namespace NzbDrone.Core.Validation.Paths -{ - public class SeriesExistsValidator : PropertyValidator - { - private readonly ISeriesService _seriesService; - - public SeriesExistsValidator(ISeriesService seriesService) - : base("This series has already been added") - { - _seriesService = seriesService; - } - - protected override bool IsValid(PropertyValidatorContext context) - { - if (context.PropertyValue == null) return true; - - var tvdbId = Convert.ToInt32(context.PropertyValue.ToString()); - - return (!_seriesService.GetAllSeries().Exists(s => s.TvdbId == tvdbId)); - } - } -} \ No newline at end of file diff --git a/src/NzbDrone.Core/Validation/Paths/SeriesPathValidator.cs b/src/NzbDrone.Core/Validation/Paths/SeriesPathValidator.cs deleted file mode 100644 index fa4d8fa59..000000000 --- a/src/NzbDrone.Core/Validation/Paths/SeriesPathValidator.cs +++ /dev/null @@ -1,27 +0,0 @@ -using FluentValidation.Validators; -using NzbDrone.Common.Extensions; -using NzbDrone.Core.Tv; - -namespace NzbDrone.Core.Validation.Paths -{ - public class SeriesPathValidator : PropertyValidator - { - private readonly ISeriesService _seriesService; - - public SeriesPathValidator(ISeriesService seriesService) - : base("Path is already configured for another series") - { - _seriesService = seriesService; - } - - protected override bool IsValid(PropertyValidatorContext context) - { - if (context.PropertyValue == null) return true; - - dynamic instance = context.ParentContext.InstanceToValidate; - var instanceId = (int)instance.Id; - - return (!_seriesService.GetAllSeries().Exists(s => s.Path.PathEquals(context.PropertyValue.ToString()) && s.Id != instanceId)); - } - } -} \ No newline at end of file