Search in sources :

Example 1 with Category

use of org.nzbhydra.config.Category in project nzbhydra2 by theotherp.

the class CategoryProviderTest method setUp.

@Before
public void setUp() throws Exception {
    List<Category> categories = new ArrayList<>();
    Category category = new Category();
    category.setName("all");
    category.setNewznabCategories(Collections.emptyList());
    categories.add(category);
    category = new Category();
    category.setName("n/a");
    category.setNewznabCategories(Collections.emptyList());
    categories.add(category);
    category = new Category();
    category.setName("3000,3030");
    category.setNewznabCategories(Arrays.asList(3000, 3030));
    categories.add(category);
    category = new Category();
    category.setName("4000");
    category.setNewznabCategories(Arrays.asList(4000));
    categories.add(category);
    category = new Category();
    category.setName("4030");
    category.setNewznabCategories(Arrays.asList(4030));
    categories.add(category);
    category = new Category();
    category.setName("4090");
    category.setSubtype(Subtype.COMIC);
    category.setNewznabCategories(Arrays.asList(4090));
    categories.add(category);
    category = new Category();
    category.setName("7020,8010");
    category.setSubtype(Subtype.ANIME);
    category.setNewznabCategories(Arrays.asList(7020, 8010));
    categories.add(category);
    BaseConfig baseConfig = new BaseConfig();
    CategoriesConfig categoriesConfig = new CategoriesConfig();
    categoriesConfig.setCategories(categories);
    baseConfig.setCategoriesConfig(categoriesConfig);
    testee.baseConfig = baseConfig;
    testee.initialize();
}
Also used : Category(org.nzbhydra.config.Category) BaseConfig(org.nzbhydra.config.BaseConfig) CategoriesConfig(org.nzbhydra.config.CategoriesConfig) Before(org.junit.Before)

Example 2 with Category

use of org.nzbhydra.config.Category in project nzbhydra2 by theotherp.

the class SearcherUnitTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    when(searchResultEntityMock.getIndexer()).thenReturn(indexerEntity);
    searcher.duplicateDetector = duplicateDetector;
    when(indexer1.getName()).thenReturn("indexer1");
    when(indexer2.getName()).thenReturn("indexer2");
    when(indexer1.getConfig()).thenReturn(indexerConfigMock);
    when(indexer2.getConfig()).thenReturn(indexerConfigMock);
    when(indexer1.getIndexerEntity()).thenReturn(indexerEntity);
    Category category = new Category();
    category.setName("cat");
    when(searchRequestMock.getCategory()).thenReturn(category);
    when(searchRequestMock.getInternalData()).thenReturn(new InternalData());
    when(indexerPicker.pickIndexers(any())).thenReturn(pickingResultMock);
    when(indexerSearchRepository.findByIndexerEntityAndSearchEntity(any(), any())).thenReturn(indexerSearchEntityMock);
    when(pickingResultMock.getSelectedIndexers()).thenReturn(Arrays.asList(indexer1));
    when(duplicateDetector.detectDuplicates(any())).thenAnswer(new Answer<DuplicateDetectionResult>() {

        @Override
        public DuplicateDetectionResult answer(InvocationOnMock invocation) throws Throwable {
            List<SearchResultItem> items = invocation.getArgument(0);
            List<LinkedHashSet<SearchResultItem>> sets = items.stream().map(x -> {
                return Sets.newLinkedHashSet(Arrays.asList(x));
            }).collect(Collectors.toList());
            return new DuplicateDetectionResult(sets, HashMultiset.create());
        }
    });
}
Also used : Category(org.nzbhydra.config.Category) InvocationOnMock(org.mockito.invocation.InvocationOnMock) InternalData(org.nzbhydra.searching.searchrequests.InternalData) ArrayList(java.util.ArrayList) List(java.util.List) Before(org.junit.Before)

Example 3 with Category

use of org.nzbhydra.config.Category in project nzbhydra2 by theotherp.

the class CategoryConverterTest method convertToEntityAttribute.

@Test
public void convertToEntityAttribute() throws Exception {
    Category category = new Category();
    when(categoryProviderMock.getByInternalName("name")).thenReturn(category);
    assertThat(testee.convertToEntityAttribute("name"), is(category));
}
Also used : Category(org.nzbhydra.config.Category) Test(org.junit.Test)

Example 4 with Category

use of org.nzbhydra.config.Category in project nzbhydra2 by theotherp.

the class CategoryConverterTest method convertToDatabaseColumn.

@Test
public void convertToDatabaseColumn() throws Exception {
    Category category = new Category();
    category.setName("name");
    assertThat(testee.convertToDatabaseColumn(category), is("name"));
}
Also used : Category(org.nzbhydra.config.Category) Test(org.junit.Test)

Example 5 with Category

use of org.nzbhydra.config.Category in project nzbhydra2 by theotherp.

the class SearchWeb method createSearchRequest.

private SearchRequest createSearchRequest(@RequestBody SearchRequestParameters parameters) {
    Category category = categoryProvider.getByInternalName(parameters.getCategory());
    SearchType searchType = category.getSearchType() == null ? SearchType.SEARCH : category.getSearchType();
    SearchRequest searchRequest = searchRequestFactory.getSearchRequest(searchType, SearchSource.INTERNAL, category, parameters.getSearchRequestId(), parameters.getOffset(), parameters.getLimit());
    searchRequest.setLoadAll(parameters.isLoadAll());
    searchRequest.setIndexers(parameters.getIndexers());
    searchRequest.setQuery(parameters.getQuery());
    searchRequest.setMinage(parameters.getMinage());
    searchRequest.setMaxage(parameters.getMaxage());
    searchRequest.setMinsize(parameters.getMinsize());
    searchRequest.setMaxsize(parameters.getMaxsize());
    if (!Strings.isNullOrEmpty(parameters.getTitle())) {
        searchRequest.setTitle(parameters.getTitle());
    }
    if (!Strings.isNullOrEmpty(parameters.getImdbId())) {
        searchRequest.getIdentifiers().put(IdType.IMDB, parameters.getImdbId());
    }
    if (!Strings.isNullOrEmpty(parameters.getTmdbId())) {
        searchRequest.getIdentifiers().put(IdType.TMDB, parameters.getTmdbId());
    }
    if (!Strings.isNullOrEmpty(parameters.getTvrageId())) {
        searchRequest.getIdentifiers().put(IdType.TVRAGE, parameters.getTvrageId());
    }
    if (!Strings.isNullOrEmpty(parameters.getTvdbId())) {
        searchRequest.getIdentifiers().put(IdType.TVDB, parameters.getTvdbId());
    }
    if (!Strings.isNullOrEmpty(parameters.getTvmazeId())) {
        searchRequest.getIdentifiers().put(IdType.TVMAZE, parameters.getTvmazeId());
    }
    if (parameters.getSeason() != null) {
        searchRequest.setSeason(parameters.getSeason());
    }
    if (!Strings.isNullOrEmpty(parameters.getEpisode())) {
        searchRequest.setEpisode(parameters.getEpisode());
    }
    if (!searchRequest.getIdentifiers().isEmpty() && searchRequest.getQuery().isPresent()) {
        // Add additional restrictions to required words
        logger.debug("Adding additional search terms '{}' to required words", searchRequest.getQuery().get());
        searchRequest.getInternalData().getRequiredWords().addAll(Splitter.on(" ").splitToList(searchRequest.getQuery().get()));
        // Remove query, would be ignored by most indexers anyway
        searchRequest.setQuery(null);
    }
    searchRequest = searchRequestFactory.extendWithSavedIdentifiers(searchRequest);
    // Initialize messages for this search request
    searchStates.put(searchRequest.getSearchRequestId(), new SearchState());
    return searchRequest;
}
Also used : SearchRequest(org.nzbhydra.searching.searchrequests.SearchRequest) Category(org.nzbhydra.config.Category)

Aggregations

Category (org.nzbhydra.config.Category)10 IOException (java.io.IOException)4 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 IdType (org.nzbhydra.mediainfo.InfoProvider.IdType)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Component (org.springframework.stereotype.Component)4 Instant (java.time.Instant)3 ActionAttribute (org.nzbhydra.mapping.newznab.ActionAttribute)3 org.nzbhydra.searching (org.nzbhydra.searching)3 SearchRequest (org.nzbhydra.searching.searchrequests.SearchRequest)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Joiner (com.google.common.base.Joiner)2 Strings (com.google.common.base.Strings)2 StringReader (java.io.StringReader)2 URI (java.net.URI)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Matcher (java.util.regex.Matcher)2