@Test(expected = InvalidCollectionException.class) public void searchThrowsWhenTheCollectionNameDoesNotExist() throws InvalidCollectionException { TimbuctooActions timbuctooActions = mock(TimbuctooActions.class); given(timbuctooActions.getCollectionMetadata(anyString())).willThrow(new InvalidCollectionException("")); AutocompleteService underTest = new AutocompleteService(null, timbuctooActions); underTest.search("nonexistent", Optional.empty(), Optional.empty()); }
public JsonNode search(String collectionName, Optional<String> query, Optional<String> keywordType) throws InvalidCollectionException { final Collection collection = timbuctooActions.getCollectionMetadata(collectionName); int limit = query.isPresent() ? 50 : 1000; String queryString = query.orElse(null); QuickSearch quickSearch = QuickSearch.fromQueryString(queryString); List<QuickSearchResult> results = timbuctooActions.doQuickSearch( collection, quickSearch, keywordType.orElse(null), limit ); return jsnA(results.stream().map(entity -> jsnO( "value", jsn(entity.getIndexedValue()), "key", jsn(autoCompleteUrlFor.apply(collectionName, entity.getId(), entity.getRev()).toString()) ))); }
AutocompleteService { public JsonNode search(String collectionName, Optional<String> query, Optional<String> keywordType) throws InvalidCollectionException { final Collection collection = timbuctooActions.getCollectionMetadata(collectionName); int limit = query.isPresent() ? 50 : 1000; String queryString = query.orElse(null); QuickSearch quickSearch = QuickSearch.fromQueryString(queryString); List<QuickSearchResult> results = timbuctooActions.doQuickSearch( collection, quickSearch, keywordType.orElse(null), limit ); return jsnA(results.stream().map(entity -> jsnO( "value", jsn(entity.getIndexedValue()), "key", jsn(autoCompleteUrlFor.apply(collectionName, entity.getId(), entity.getRev()).toString()) ))); } }
AutocompleteService { public JsonNode search(String collectionName, Optional<String> query, Optional<String> keywordType) throws InvalidCollectionException { final Collection collection = timbuctooActions.getCollectionMetadata(collectionName); int limit = query.isPresent() ? 50 : 1000; String queryString = query.orElse(null); QuickSearch quickSearch = QuickSearch.fromQueryString(queryString); List<QuickSearchResult> results = timbuctooActions.doQuickSearch( collection, quickSearch, keywordType.orElse(null), limit ); return jsnA(results.stream().map(entity -> jsnO( "value", jsn(entity.getIndexedValue()), "key", jsn(autoCompleteUrlFor.apply(collectionName, entity.getId(), entity.getRev()).toString()) ))); } AutocompleteService(UrlGenerator autoCompleteUrlFor, TimbuctooActions timbuctooActions); }
AutocompleteService { public JsonNode search(String collectionName, Optional<String> query, Optional<String> keywordType) throws InvalidCollectionException { final Collection collection = timbuctooActions.getCollectionMetadata(collectionName); int limit = query.isPresent() ? 50 : 1000; String queryString = query.orElse(null); QuickSearch quickSearch = QuickSearch.fromQueryString(queryString); List<QuickSearchResult> results = timbuctooActions.doQuickSearch( collection, quickSearch, keywordType.orElse(null), limit ); return jsnA(results.stream().map(entity -> jsnO( "value", jsn(entity.getIndexedValue()), "key", jsn(autoCompleteUrlFor.apply(collectionName, entity.getId(), entity.getRev()).toString()) ))); } AutocompleteService(UrlGenerator autoCompleteUrlFor, TimbuctooActions timbuctooActions); JsonNode search(String collectionName, Optional<String> query, Optional<String> keywordType); }
AutocompleteService { public JsonNode search(String collectionName, Optional<String> query, Optional<String> keywordType) throws InvalidCollectionException { final Collection collection = timbuctooActions.getCollectionMetadata(collectionName); int limit = query.isPresent() ? 50 : 1000; String queryString = query.orElse(null); QuickSearch quickSearch = QuickSearch.fromQueryString(queryString); List<QuickSearchResult> results = timbuctooActions.doQuickSearch( collection, quickSearch, keywordType.orElse(null), limit ); return jsnA(results.stream().map(entity -> jsnO( "value", jsn(entity.getIndexedValue()), "key", jsn(autoCompleteUrlFor.apply(collectionName, entity.getId(), entity.getRev()).toString()) ))); } AutocompleteService(UrlGenerator autoCompleteUrlFor, TimbuctooActions timbuctooActions); JsonNode search(String collectionName, Optional<String> query, Optional<String> keywordType);  }