use of org.eclipse.openvsx.search.ExtensionSearch in project openvsx by eclipse.
the class LocalRegistryService method toSearchEntry.
private SearchEntryJson toSearchEntry(SearchHit<ExtensionSearch> searchHit, String serverUrl, ISearchService.Options options) {
var searchItem = searchHit.getContent();
var extension = entityManager.find(Extension.class, searchItem.id);
if (extension == null || !extension.isActive()) {
extension = new Extension();
extension.setId(searchItem.id);
search.removeSearchEntry(extension);
return null;
}
var extVer = extension.getLatest();
var entry = extVer.toSearchEntryJson();
entry.url = createApiUrl(serverUrl, "api", entry.namespace, entry.name);
entry.files = Maps.newLinkedHashMapWithExpectedSize(2);
storageUtil.addFileUrls(extVer, serverUrl, entry.files, DOWNLOAD, ICON);
if (options.includeAllVersions) {
var allVersions = Lists.newArrayList(repositories.findActiveVersions(extension));
Collections.sort(allVersions, ExtensionVersion.SORT_COMPARATOR);
entry.allVersions = CollectionUtil.map(allVersions, ev -> toVersionReference(ev, entry, serverUrl));
}
return entry;
}
use of org.eclipse.openvsx.search.ExtensionSearch in project openvsx by eclipse.
the class VSCodeAdapterTest method mockSearch.
// ---------- UTILITY ----------//
private void mockSearch(boolean active) {
var entry1 = new ExtensionSearch();
entry1.id = 1;
var searchHit = new SearchHit<ExtensionSearch>("0", "1", 1.0f, null, null, entry1);
var searchHits = new SearchHitsImpl<ExtensionSearch>(1, TotalHitsRelation.EQUAL_TO, 1.0f, "1", Arrays.asList(searchHit), new Aggregations(Collections.emptyList()));
Mockito.when(search.isEnabled()).thenReturn(true);
var searchOptions = new ISearchService.Options("yaml", null, 50, 0, "desc", "relevance", false);
Mockito.when(search.search(searchOptions, PageRequest.of(0, 50))).thenReturn(searchHits);
var extension = mockExtensionDTO();
List<ExtensionDTO> results = active ? List.of(extension) : Collections.emptyList();
Mockito.when(repositories.findAllActiveExtensionDTOsById(List.of(entry1.id))).thenReturn(results);
var publicIds = Set.of(extension.getPublicId());
Mockito.when(repositories.findAllActiveExtensionDTOsByPublicId(publicIds)).thenReturn(results);
var ids = List.of(extension.getId());
Mockito.when(repositories.findAllActiveReviewCountsByExtensionId(ids)).thenReturn(Map.of(extension.getId(), 10));
var name = extension.getName();
var namespaceName = extension.getNamespace().getName();
Mockito.when(repositories.findActiveExtensionDTOByNameAndNamespaceName(name, namespaceName)).thenReturn(extension);
mockFileResourceDTOs(extension.getLatest());
}
use of org.eclipse.openvsx.search.ExtensionSearch in project openvsx by eclipse.
the class RegistryAPITest method mockSearch.
private List<Extension> mockSearch() {
var extVersion = mockExtension();
var extension = extVersion.getExtension();
extension.setId(1l);
var entry1 = new ExtensionSearch();
entry1.id = 1;
var searchHit = new SearchHit<ExtensionSearch>("0", "1", 1.0f, null, null, entry1);
var searchHits = new SearchHitsImpl<ExtensionSearch>(1, TotalHitsRelation.EQUAL_TO, 1.0f, "1", Arrays.asList(searchHit), new Aggregations(Collections.emptyList()));
Mockito.when(search.isEnabled()).thenReturn(true);
var searchOptions = new ISearchService.Options("foo", null, 10, 0, "desc", "relevance", false);
Mockito.when(search.search(searchOptions, PageRequest.of(0, 10))).thenReturn(searchHits);
Mockito.when(entityManager.find(Extension.class, 1l)).thenReturn(extension);
return Arrays.asList(extension);
}
Aggregations