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();
}
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);
}
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);
}
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);
}
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));
}
Aggregations