@Test public void shouldComputeCategory() throws Exception { when(categoryProviderMock.fromResultNewznabCategories(any())).thenReturn(otherCategory); testee.config.getCategoryMapping().setAnime(1010); SearchResultItem item = new SearchResultItem(); testee.computeCategory(item, Arrays.asList(1000, 1010)); assertThat(item.getCategory(), is(animeCategory)); testee.computeCategory(item, Arrays.asList(3030)); assertThat(item.getCategory(), is(otherCategory)); }
protected void computeCategory(SearchResultItem searchResultItem, List<Integer> newznabCategories) { if (!newznabCategories.isEmpty()) { Integer mostSpecific = newznabCategories.stream().max(Integer::compareTo).get(); IndexerCategoryConfig mapping = config.getCategoryMapping(); Category category; if (mapping == null) { category = categoryProvider.fromSearchNewznabCategories(newznabCategories, categoryProvider.getNotAvailable()); searchResultItem.setOriginalCategory(categoryProvider.getNotAvailable().getName()); } else { category = idToCategory.computeIfAbsent(mostSpecific, x -> { Optional<Category> categoryOptional = Optional.empty(); if (mapping.getAnime().isPresent() && Objects.equals(mapping.getAnime().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.ANIME); } else if (mapping.getAudiobook().isPresent() && Objects.equals(mapping.getAudiobook().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.AUDIOBOOK); } else if (mapping.getEbook().isPresent() && Objects.equals(mapping.getEbook().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.EBOOK); } else if (mapping.getComic().isPresent() && Objects.equals(mapping.getComic().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.COMIC); } else if (mapping.getMagazine().isPresent() && Objects.equals(mapping.getMagazine().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.MAGAZINE); } return categoryOptional.orElse(categoryProvider.fromResultNewznabCategories(newznabCategories)); }); searchResultItem.setOriginalCategory(mapping.getNameFromId(mostSpecific)); } if (category == null) { searchResultItem.setCategory(categoryProvider.getNotAvailable()); } else { searchResultItem.setCategory(category); } } else { searchResultItem.setCategory(categoryProvider.getNotAvailable()); } }
Newznab extends Indexer<Xml> { protected void computeCategory(SearchResultItem searchResultItem, List<Integer> newznabCategories) { if (!newznabCategories.isEmpty()) { Integer mostSpecific = newznabCategories.stream().max(Integer::compareTo).get(); IndexerCategoryConfig mapping = config.getCategoryMapping(); Category category; if (mapping == null) { category = categoryProvider.fromSearchNewznabCategories(newznabCategories, categoryProvider.getNotAvailable()); searchResultItem.setOriginalCategory(categoryProvider.getNotAvailable().getName()); } else { category = idToCategory.computeIfAbsent(mostSpecific, x -> { Optional<Category> categoryOptional = Optional.empty(); if (mapping.getAnime().isPresent() && Objects.equals(mapping.getAnime().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.ANIME); } else if (mapping.getAudiobook().isPresent() && Objects.equals(mapping.getAudiobook().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.AUDIOBOOK); } else if (mapping.getEbook().isPresent() && Objects.equals(mapping.getEbook().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.EBOOK); } else if (mapping.getComic().isPresent() && Objects.equals(mapping.getComic().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.COMIC); } else if (mapping.getMagazine().isPresent() && Objects.equals(mapping.getMagazine().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.MAGAZINE); } return categoryOptional.orElse(categoryProvider.fromResultNewznabCategories(newznabCategories)); }); searchResultItem.setOriginalCategory(mapping.getNameFromId(mostSpecific)); } if (category == null) { searchResultItem.setCategory(categoryProvider.getNotAvailable()); } else { searchResultItem.setCategory(category); } } else { searchResultItem.setCategory(categoryProvider.getNotAvailable()); } } }
Newznab extends Indexer<Xml> { protected void computeCategory(SearchResultItem searchResultItem, List<Integer> newznabCategories) { if (!newznabCategories.isEmpty()) { Integer mostSpecific = newznabCategories.stream().max(Integer::compareTo).get(); IndexerCategoryConfig mapping = config.getCategoryMapping(); Category category; if (mapping == null) { category = categoryProvider.fromSearchNewznabCategories(newznabCategories, categoryProvider.getNotAvailable()); searchResultItem.setOriginalCategory(categoryProvider.getNotAvailable().getName()); } else { category = idToCategory.computeIfAbsent(mostSpecific, x -> { Optional<Category> categoryOptional = Optional.empty(); if (mapping.getAnime().isPresent() && Objects.equals(mapping.getAnime().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.ANIME); } else if (mapping.getAudiobook().isPresent() && Objects.equals(mapping.getAudiobook().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.AUDIOBOOK); } else if (mapping.getEbook().isPresent() && Objects.equals(mapping.getEbook().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.EBOOK); } else if (mapping.getComic().isPresent() && Objects.equals(mapping.getComic().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.COMIC); } else if (mapping.getMagazine().isPresent() && Objects.equals(mapping.getMagazine().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.MAGAZINE); } return categoryOptional.orElse(categoryProvider.fromResultNewznabCategories(newznabCategories)); }); searchResultItem.setOriginalCategory(mapping.getNameFromId(mostSpecific)); } if (category == null) { searchResultItem.setCategory(categoryProvider.getNotAvailable()); } else { searchResultItem.setCategory(category); } } else { searchResultItem.setCategory(categoryProvider.getNotAvailable()); } }  }
Newznab extends Indexer<Xml> { protected void computeCategory(SearchResultItem searchResultItem, List<Integer> newznabCategories) { if (!newznabCategories.isEmpty()) { Integer mostSpecific = newznabCategories.stream().max(Integer::compareTo).get(); IndexerCategoryConfig mapping = config.getCategoryMapping(); Category category; if (mapping == null) { category = categoryProvider.fromSearchNewznabCategories(newznabCategories, categoryProvider.getNotAvailable()); searchResultItem.setOriginalCategory(categoryProvider.getNotAvailable().getName()); } else { category = idToCategory.computeIfAbsent(mostSpecific, x -> { Optional<Category> categoryOptional = Optional.empty(); if (mapping.getAnime().isPresent() && Objects.equals(mapping.getAnime().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.ANIME); } else if (mapping.getAudiobook().isPresent() && Objects.equals(mapping.getAudiobook().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.AUDIOBOOK); } else if (mapping.getEbook().isPresent() && Objects.equals(mapping.getEbook().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.EBOOK); } else if (mapping.getComic().isPresent() && Objects.equals(mapping.getComic().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.COMIC); } else if (mapping.getMagazine().isPresent() && Objects.equals(mapping.getMagazine().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.MAGAZINE); } return categoryOptional.orElse(categoryProvider.fromResultNewznabCategories(newznabCategories)); }); searchResultItem.setOriginalCategory(mapping.getNameFromId(mostSpecific)); } if (category == null) { searchResultItem.setCategory(categoryProvider.getNotAvailable()); } else { searchResultItem.setCategory(category); } } else { searchResultItem.setCategory(categoryProvider.getNotAvailable()); } }  @Override NfoResult getNfo(String guid); }
Newznab extends Indexer<Xml> { protected void computeCategory(SearchResultItem searchResultItem, List<Integer> newznabCategories) { if (!newznabCategories.isEmpty()) { Integer mostSpecific = newznabCategories.stream().max(Integer::compareTo).get(); IndexerCategoryConfig mapping = config.getCategoryMapping(); Category category; if (mapping == null) { category = categoryProvider.fromSearchNewznabCategories(newznabCategories, categoryProvider.getNotAvailable()); searchResultItem.setOriginalCategory(categoryProvider.getNotAvailable().getName()); } else { category = idToCategory.computeIfAbsent(mostSpecific, x -> { Optional<Category> categoryOptional = Optional.empty(); if (mapping.getAnime().isPresent() && Objects.equals(mapping.getAnime().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.ANIME); } else if (mapping.getAudiobook().isPresent() && Objects.equals(mapping.getAudiobook().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.AUDIOBOOK); } else if (mapping.getEbook().isPresent() && Objects.equals(mapping.getEbook().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.EBOOK); } else if (mapping.getComic().isPresent() && Objects.equals(mapping.getComic().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.COMIC); } else if (mapping.getMagazine().isPresent() && Objects.equals(mapping.getMagazine().get(), mostSpecific)) { categoryOptional = categoryProvider.fromSubtype(Subtype.MAGAZINE); } return categoryOptional.orElse(categoryProvider.fromResultNewznabCategories(newznabCategories)); }); searchResultItem.setOriginalCategory(mapping.getNameFromId(mostSpecific)); } if (category == null) { searchResultItem.setCategory(categoryProvider.getNotAvailable()); } else { searchResultItem.setCategory(category); } } else { searchResultItem.setCategory(categoryProvider.getNotAvailable()); } }  @Override NfoResult getNfo(String guid);  }