示例#1
0
        protected override void EnsureNewParent(Book local, Book remote)
        {
            // Make sure the appropriate author exists (it could be that an book changes parent)
            // The authorMetadata entry will be in the db but make sure a corresponding author is too
            // so that the book doesn't just disappear.

            // TODO filter by metadata id before hitting database
            _logger.Trace($"Ensuring parent author exists [{remote.AuthorMetadata.Value.ForeignAuthorId}]");

            var newAuthor = _authorService.FindById(remote.AuthorMetadata.Value.ForeignAuthorId);

            if (newAuthor == null)
            {
                var oldAuthor = local.Author.Value;
                var addArtist = new Author
                {
                    Metadata          = remote.AuthorMetadata.Value,
                    MetadataProfileId = oldAuthor.MetadataProfileId,
                    QualityProfileId  = oldAuthor.QualityProfileId,
                    RootFolderPath    = oldAuthor.RootFolderPath,
                    Monitored         = oldAuthor.Monitored,
                    Tags = oldAuthor.Tags
                };
                _logger.Debug($"Adding missing parent author {addArtist}");
                _addAuthorService.AddAuthor(addArtist);
            }
        }
示例#2
0
        public Book AddBook(Book book, bool doRefresh = true)
        {
            _logger.Debug($"Adding book {book}");

            // we allow adding extra editions, so check if the book already exists
            var dbBook = _bookService.FindById(book.ForeignBookId);

            if (dbBook != null)
            {
                dbBook.Editions = book.Editions;
                book            = dbBook;
            }
            else
            {
                book = AddSkyhookData(book);
            }

            // Remove any import list exclusions preventing addition
            _importListExclusionService.Delete(book.ForeignBookId);
            _importListExclusionService.Delete(book.AuthorMetadata.Value.ForeignAuthorId);

            // Note it's a manual addition so it's not deleted on next refresh
            book.AddOptions.AddType = BookAddType.Manual;
            book.Editions.Value.Single(x => x.Monitored).ManualAdd = true;

            // Add the author if necessary
            var dbAuthor = _authorService.FindById(book.AuthorMetadata.Value.ForeignAuthorId);

            if (dbAuthor == null)
            {
                var author = book.Author.Value;

                author.Metadata.Value.ForeignAuthorId = book.AuthorMetadata.Value.ForeignAuthorId;

                dbAuthor = _addAuthorService.AddAuthor(author, false);
            }

            book.Author           = dbAuthor;
            book.AuthorMetadataId = dbAuthor.AuthorMetadataId;
            _bookService.AddBook(book, doRefresh);

            return(book);
        }
示例#3
0
        private Author EnsureAuthorAdded(List <ImportDecision <LocalBook> > decisions, List <Author> addedArtists)
        {
            var author = decisions.First().Item.Author;

            if (author.Id == 0)
            {
                var dbArtist = _authorService.FindById(author.ForeignAuthorId);

                if (dbArtist == null)
                {
                    _logger.Debug($"Adding remote author {author}");
                    var path       = decisions.First().Item.Path;
                    var rootFolder = _rootFolderService.GetBestRootFolder(path);

                    author.RootFolderPath    = rootFolder.Path;
                    author.MetadataProfileId = rootFolder.DefaultMetadataProfileId;
                    author.QualityProfileId  = rootFolder.DefaultQualityProfileId;
                    author.Monitored         = rootFolder.DefaultMonitorOption != MonitorTypes.None;
                    author.Tags       = rootFolder.DefaultTags;
                    author.AddOptions = new AddAuthorOptions
                    {
                        SearchForMissingBooks = false,
                        Monitored             = author.Monitored,
                        Monitor = rootFolder.DefaultMonitorOption
                    };

                    if (rootFolder.IsCalibreLibrary)
                    {
                        // calibre has author / book / files
                        author.Path = path.GetParentPath().GetParentPath();
                    }

                    try
                    {
                        dbArtist = _addAuthorService.AddAuthor(author, false);
                        addedArtists.Add(dbArtist);
                    }
                    catch (Exception e)
                    {
                        _logger.Error(e, "Failed to add author {0}", author);
                        foreach (var decision in decisions)
                        {
                            decision.Reject(new Rejection("Failed to add missing author", RejectionType.Temporary));
                        }

                        return(null);
                    }
                }

                // Put in the newly loaded author
                foreach (var decision in decisions)
                {
                    decision.Item.Author                = dbArtist;
                    decision.Item.Book.Author           = dbArtist;
                    decision.Item.Book.AuthorMetadataId = dbArtist.AuthorMetadataId;
                }

                author = dbArtist;
            }

            return(author);
        }
示例#4
0
        public ActionResult <AuthorResource> AddAuthor(AuthorResource authorResource)
        {
            var author = _addAuthorService.AddAuthor(authorResource.ToModel());

            return(Created(author.Id));
        }
示例#5
0
        private int AddAuthor(AuthorResource authorResource)
        {
            var author = _addAuthorService.AddAuthor(authorResource.ToModel());

            return(author.Id);
        }