@Test public void shouldCheckIdConversion() { Set<MediaIdType> supported = Sets.newSet(MediaIdType.TVMAZE, MediaIdType.TVDB); Set<MediaIdType> provided = Sets.newSet(MediaIdType.TVMAZE); when(searchRequest.getQuery()).thenReturn(Optional.empty()); when(infoProviderMock.canConvertAny(provided, supported)).thenReturn(true); assertTrue(testee.checkSearchId(indexer)); when(searchRequest.getQuery()).thenReturn(Optional.of("a query")); when(infoProviderMock.canConvertAny(provided, supported)).thenReturn(false); assertTrue(testee.checkSearchId(indexer)); provided = new HashSet<>(); when(searchRequest.getQuery()).thenReturn(Optional.empty()); verify(infoProviderMock, never()).canConvertAny(provided, supported); assertTrue(testee.checkSearchId(indexer)); }
protected boolean checkSearchId(Indexer indexer) { boolean needToSearchById = !searchRequest.getIdentifiers().isEmpty() && !searchRequest.getQuery().isPresent(); if (needToSearchById) { boolean canUseAnyProvidedId = !Collections.disjoint(searchRequest.getIdentifiers().keySet(), indexer.getConfig().getSupportedSearchIds()); boolean cannotSearchProvidedOrConvertableId = !canUseAnyProvidedId && !infoProvider.canConvertAny(searchRequest.getIdentifiers().keySet(), Sets.newHashSet(indexer.getConfig().getSupportedSearchIds())); boolean queryGenerationEnabled = configProvider.getBaseConfig().getSearching().getGenerateQueries().meets(searchRequest); if (cannotSearchProvidedOrConvertableId && !queryGenerationEnabled) { String message = String.format("Not using %s because the search did not provide any ID that the indexer can handle and query generation is disabled", indexer.getName()); return handleIndexerNotSelected(indexer, message, "No usable ID"); } } return true; }
IndexerForSearchSelector { protected boolean checkSearchId(Indexer indexer) { boolean needToSearchById = !searchRequest.getIdentifiers().isEmpty() && !searchRequest.getQuery().isPresent(); if (needToSearchById) { boolean canUseAnyProvidedId = !Collections.disjoint(searchRequest.getIdentifiers().keySet(), indexer.getConfig().getSupportedSearchIds()); boolean cannotSearchProvidedOrConvertableId = !canUseAnyProvidedId && !infoProvider.canConvertAny(searchRequest.getIdentifiers().keySet(), Sets.newHashSet(indexer.getConfig().getSupportedSearchIds())); boolean queryGenerationEnabled = configProvider.getBaseConfig().getSearching().getGenerateQueries().meets(searchRequest); if (cannotSearchProvidedOrConvertableId && !queryGenerationEnabled) { String message = String.format("Not using %s because the search did not provide any ID that the indexer can handle and query generation is disabled", indexer.getName()); return handleIndexerNotSelected(indexer, message, "No usable ID"); } } return true; } }
IndexerForSearchSelector { protected boolean checkSearchId(Indexer indexer) { boolean needToSearchById = !searchRequest.getIdentifiers().isEmpty() && !searchRequest.getQuery().isPresent(); if (needToSearchById) { boolean canUseAnyProvidedId = !Collections.disjoint(searchRequest.getIdentifiers().keySet(), indexer.getConfig().getSupportedSearchIds()); boolean cannotSearchProvidedOrConvertableId = !canUseAnyProvidedId && !infoProvider.canConvertAny(searchRequest.getIdentifiers().keySet(), Sets.newHashSet(indexer.getConfig().getSupportedSearchIds())); boolean queryGenerationEnabled = configProvider.getBaseConfig().getSearching().getGenerateQueries().meets(searchRequest); if (cannotSearchProvidedOrConvertableId && !queryGenerationEnabled) { String message = String.format("Not using %s because the search did not provide any ID that the indexer can handle and query generation is disabled", indexer.getName()); return handleIndexerNotSelected(indexer, message, "No usable ID"); } } return true; }  }
IndexerForSearchSelector { protected boolean checkSearchId(Indexer indexer) { boolean needToSearchById = !searchRequest.getIdentifiers().isEmpty() && !searchRequest.getQuery().isPresent(); if (needToSearchById) { boolean canUseAnyProvidedId = !Collections.disjoint(searchRequest.getIdentifiers().keySet(), indexer.getConfig().getSupportedSearchIds()); boolean cannotSearchProvidedOrConvertableId = !canUseAnyProvidedId && !infoProvider.canConvertAny(searchRequest.getIdentifiers().keySet(), Sets.newHashSet(indexer.getConfig().getSupportedSearchIds())); boolean queryGenerationEnabled = configProvider.getBaseConfig().getSearching().getGenerateQueries().meets(searchRequest); if (cannotSearchProvidedOrConvertableId && !queryGenerationEnabled) { String message = String.format("Not using %s because the search did not provide any ID that the indexer can handle and query generation is disabled", indexer.getName()); return handleIndexerNotSelected(indexer, message, "No usable ID"); } } return true; }  IndexerForSearchSelection pickIndexers(SearchRequest searchRequest); }
IndexerForSearchSelector { protected boolean checkSearchId(Indexer indexer) { boolean needToSearchById = !searchRequest.getIdentifiers().isEmpty() && !searchRequest.getQuery().isPresent(); if (needToSearchById) { boolean canUseAnyProvidedId = !Collections.disjoint(searchRequest.getIdentifiers().keySet(), indexer.getConfig().getSupportedSearchIds()); boolean cannotSearchProvidedOrConvertableId = !canUseAnyProvidedId && !infoProvider.canConvertAny(searchRequest.getIdentifiers().keySet(), Sets.newHashSet(indexer.getConfig().getSupportedSearchIds())); boolean queryGenerationEnabled = configProvider.getBaseConfig().getSearching().getGenerateQueries().meets(searchRequest); if (cannotSearchProvidedOrConvertableId && !queryGenerationEnabled) { String message = String.format("Not using %s because the search did not provide any ID that the indexer can handle and query generation is disabled", indexer.getName()); return handleIndexerNotSelected(indexer, message, "No usable ID"); } } return true; }  IndexerForSearchSelection pickIndexers(SearchRequest searchRequest); static final Pattern SCHEDULER_PATTERN; }