Search in sources :

Example 1 with BaseConfig

use of org.nzbhydra.config.BaseConfig 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 BaseConfig

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

the class DuplicateDetectorTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    BaseConfig baseConfig = new BaseConfig();
    baseConfig.setSearching(new SearchingConfig());
    baseConfig.getSearching().setDuplicateSizeThresholdInPercent(1F);
    baseConfig.getSearching().setDuplicateAgeThreshold(2F);
    when(configProviderMock.getBaseConfig()).thenReturn(baseConfig);
}
Also used : SearchingConfig(org.nzbhydra.config.SearchingConfig) BaseConfig(org.nzbhydra.config.BaseConfig) Before(org.junit.Before)

Example 3 with BaseConfig

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

the class SearchResultAcceptor method acceptResults.

public AcceptorResult acceptResults(List<SearchResultItem> items, SearchRequest searchRequest, IndexerConfig indexerConfig) {
    BaseConfig baseConfig = configProvider.getBaseConfig();
    titleWordCache = new HashMap<>();
    List<SearchResultItem> acceptedResults = new ArrayList<>();
    Multiset<String> reasonsForRejection = HashMultiset.create();
    HashSet<SearchResultItem> itemsWithoutActualDuplicates = new HashSet<>(items);
    if (itemsWithoutActualDuplicates.size() < items.size()) {
        int removedDuplicates = items.size() - itemsWithoutActualDuplicates.size();
        logger.warn("Removed {} actual duplicates from the results returned by {}. This is likely an error in their code base", removedDuplicates, indexerConfig.getName());
        reasonsForRejection.add("Duplicate results from indexer", removedDuplicates);
    }
    for (SearchResultItem item : itemsWithoutActualDuplicates) {
        if (!checkForNeededAttributesSuccessfullyMapped(reasonsForRejection, item)) {
            continue;
        }
        if (!checkForPassword(reasonsForRejection, item)) {
            continue;
        }
        if (!checkForForbiddenGroup(reasonsForRejection, item)) {
            continue;
        }
        if (!checkForForbiddenPoster(reasonsForRejection, item)) {
            continue;
        }
        if (!checkForSize(searchRequest, reasonsForRejection, item)) {
            continue;
        }
        if (!checkForAge(searchRequest, reasonsForRejection, item)) {
            continue;
        }
        if (!checkForCategoryShouldBeIgnored(searchRequest, reasonsForRejection, item)) {
            continue;
        }
        if (!checkForCategoryDisabledForIndexer(searchRequest, reasonsForRejection, item)) {
            continue;
        }
        // Forbidden words from query
        if (!checkForForbiddenWords(indexerConfig, reasonsForRejection, searchRequest.getInternalData().getForbiddenWords(), item)) {
            continue;
        }
        if (!checkRequiredWords(reasonsForRejection, searchRequest.getInternalData().getRequiredWords(), item)) {
            continue;
        }
        // Globally configured
        boolean applyWordAndRegexRestrictions = baseConfig.getSearching().getApplyRestrictions() == SearchSourceRestriction.BOTH || Objects.equals(searchRequest.getSource().name(), baseConfig.getSearching().getApplyRestrictions().name());
        if (applyWordAndRegexRestrictions) {
            if (!checkRegexes(item, reasonsForRejection, baseConfig.getSearching().getRequiredRegex().orElse(null), baseConfig.getSearching().getForbiddenRegex().orElse(null))) {
                continue;
            }
            if (!checkRequiredWords(reasonsForRejection, baseConfig.getSearching().getRequiredWords(), item)) {
                continue;
            }
            if (!checkForForbiddenWords(indexerConfig, reasonsForRejection, baseConfig.getSearching().getForbiddenWords(), item)) {
                continue;
            }
        }
        // Per category
        applyWordAndRegexRestrictions = item.getCategory().getApplyRestrictionsType() == SearchSourceRestriction.BOTH || Objects.equals(searchRequest.getSource().name(), item.getCategory().getApplyRestrictionsType().name());
        if (applyWordAndRegexRestrictions) {
            if (!checkRegexes(item, reasonsForRejection, item.getCategory().getRequiredRegex().orElse(null), item.getCategory().getForbiddenRegex().orElse(null))) {
                continue;
            }
            if (!checkRequiredWords(reasonsForRejection, item.getCategory().getRequiredWords(), item)) {
                continue;
            }
            if (!checkForForbiddenWords(indexerConfig, reasonsForRejection, item.getCategory().getForbiddenWords(), item)) {
                continue;
            }
        }
        acceptedResults.add(item);
    }
    if (acceptedResults.size() < items.size()) {
        logger.debug("Rejected {} out of {} search results from indexer {}", items.size() - acceptedResults.size(), items.size(), indexerConfig.getName());
        for (Entry<String> entry : reasonsForRejection.entrySet()) {
            logger.info("Rejected {} search results from {} for the following reason: {}", entry.getCount(), indexerConfig.getName(), entry.getElement());
        }
    }
    return new AcceptorResult(acceptedResults, reasonsForRejection);
}
Also used : BaseConfig(org.nzbhydra.config.BaseConfig)

Example 4 with BaseConfig

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

the class AbstractConfigReplacingTest method replaceConfig.

public void replaceConfig(URL resource) throws IOException {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.writeValueAsString(baseConfig);
    ObjectReader updater = objectMapper.readerForUpdating(baseConfig);
    BaseConfig updatedConfig = updater.readValue(resource);
    baseConfig.replace(updatedConfig);
}
Also used : ObjectReader(com.fasterxml.jackson.databind.ObjectReader) BaseConfig(org.nzbhydra.config.BaseConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with BaseConfig

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

the class DontRestrictStatsAuthTest method shouldAllowChangingRestrictionsAtRuntime.

@Test
public void shouldAllowChangingRestrictionsAtRuntime() throws Exception {
    mvc.perform(MockMvcRequestBuilders.get("/config").with(csrf())).andExpect(status().is(401));
    baseConfig.getAuth().setRestrictAdmin(false);
    authenticationFilter.handleConfigChangedEvent(new ConfigChangedEvent(this, new BaseConfig(), baseConfig));
    mvc.perform(MockMvcRequestBuilders.get("/config").with(csrf())).andExpect(status().is(200));
}
Also used : BaseConfig(org.nzbhydra.config.BaseConfig) ConfigChangedEvent(org.nzbhydra.config.ConfigChangedEvent) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

BaseConfig (org.nzbhydra.config.BaseConfig)13 Before (org.junit.Before)7 Test (org.junit.Test)3 ConfigChangedEvent (org.nzbhydra.config.ConfigChangedEvent)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 SearchingConfig (org.nzbhydra.config.SearchingConfig)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Ignore (org.junit.Ignore)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 CategoriesConfig (org.nzbhydra.config.CategoriesConfig)1 Category (org.nzbhydra.config.Category)1 IndexerCategoryConfig (org.nzbhydra.config.IndexerCategoryConfig)1 IndexerConfig (org.nzbhydra.config.IndexerConfig)1 UserAuthConfig (org.nzbhydra.config.UserAuthConfig)1 NewznabXmlRoot (org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot)1