Search in sources :

Example 1 with ExtensionSearch

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;
}
Also used : Extension(org.eclipse.openvsx.entities.Extension) Autowired(org.springframework.beans.factory.annotation.Autowired) QueryParamJson(org.eclipse.openvsx.json.QueryParamJson) CacheControl(org.springframework.http.CacheControl) ExtensionSearch(org.eclipse.openvsx.search.ExtensionSearch) ISearchService(org.eclipse.openvsx.search.ISearchService) FileResource(org.eclipse.openvsx.entities.FileResource) Namespace(org.eclipse.openvsx.entities.Namespace) ReviewJson(org.eclipse.openvsx.json.ReviewJson) ExtensionJson(org.eclipse.openvsx.json.ExtensionJson) SearchUtilService(org.eclipse.openvsx.search.SearchUtilService) ResponseStatusException(org.springframework.web.server.ResponseStatusException) Transactional(javax.transaction.Transactional) PageRequest(org.springframework.data.domain.PageRequest) ExtensionReview(org.eclipse.openvsx.entities.ExtensionReview) Collectors(java.util.stream.Collectors) Stream(java.util.stream.Stream) Maps(org.apache.jena.ext.com.google.common.collect.Maps) org.eclipse.openvsx.dto(org.eclipse.openvsx.dto) CollectionUtil(org.eclipse.openvsx.util.CollectionUtil) QueryResultJson(org.eclipse.openvsx.json.QueryResultJson) NamespaceMembership(org.eclipse.openvsx.entities.NamespaceMembership) java.util(java.util) Iterables(com.google.common.collect.Iterables) ExtensionVersion(org.eclipse.openvsx.entities.ExtensionVersion) ReviewListJson(org.eclipse.openvsx.json.ReviewListJson) ErrorResultException(org.eclipse.openvsx.util.ErrorResultException) UrlUtil(org.eclipse.openvsx.util.UrlUtil) TimeUtil(org.eclipse.openvsx.util.TimeUtil) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) NamespaceJson(org.eclipse.openvsx.json.NamespaceJson) NotFoundException(org.eclipse.openvsx.util.NotFoundException) SearchHit(org.springframework.data.elasticsearch.core.SearchHit) UrlUtil.createApiUrl(org.eclipse.openvsx.util.UrlUtil.createApiUrl) Extension(org.eclipse.openvsx.entities.Extension) SearchHits(org.springframework.data.elasticsearch.core.SearchHits) SemanticVersion(org.eclipse.openvsx.util.SemanticVersion) EntityManager(javax.persistence.EntityManager) ResultJson(org.eclipse.openvsx.json.ResultJson) TimeUnit(java.util.concurrent.TimeUnit) SearchResultJson(org.eclipse.openvsx.json.SearchResultJson) RepositoryService(org.eclipse.openvsx.repositories.RepositoryService) HttpStatus(org.springframework.http.HttpStatus) Component(org.springframework.stereotype.Component) SearchEntryJson(org.eclipse.openvsx.json.SearchEntryJson) ResponseEntity(org.springframework.http.ResponseEntity) EclipseService(org.eclipse.openvsx.eclipse.EclipseService) InputStream(java.io.InputStream) StorageUtilService(org.eclipse.openvsx.storage.StorageUtilService)

Example 2 with ExtensionSearch

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());
}
Also used : SearchHit(org.springframework.data.elasticsearch.core.SearchHit) ExtensionSearch(org.eclipse.openvsx.search.ExtensionSearch) Aggregations(org.elasticsearch.search.aggregations.Aggregations) ExtensionDTO(org.eclipse.openvsx.dto.ExtensionDTO) SearchHitsImpl(org.springframework.data.elasticsearch.core.SearchHitsImpl)

Example 3 with ExtensionSearch

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);
}
Also used : SearchHit(org.springframework.data.elasticsearch.core.SearchHit) ExtensionSearch(org.eclipse.openvsx.search.ExtensionSearch) Aggregations(org.elasticsearch.search.aggregations.Aggregations) SearchHitsImpl(org.springframework.data.elasticsearch.core.SearchHitsImpl)

Aggregations

ExtensionSearch (org.eclipse.openvsx.search.ExtensionSearch)3 SearchHit (org.springframework.data.elasticsearch.core.SearchHit)3 Aggregations (org.elasticsearch.search.aggregations.Aggregations)2 SearchHitsImpl (org.springframework.data.elasticsearch.core.SearchHitsImpl)2 Strings (com.google.common.base.Strings)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 InputStream (java.io.InputStream)1 java.util (java.util)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 EntityManager (javax.persistence.EntityManager)1 Transactional (javax.transaction.Transactional)1 Maps (org.apache.jena.ext.com.google.common.collect.Maps)1 org.eclipse.openvsx.dto (org.eclipse.openvsx.dto)1 ExtensionDTO (org.eclipse.openvsx.dto.ExtensionDTO)1 EclipseService (org.eclipse.openvsx.eclipse.EclipseService)1 Extension (org.eclipse.openvsx.entities.Extension)1 ExtensionReview (org.eclipse.openvsx.entities.ExtensionReview)1