Search in sources :

Example 11 with RepositorySearchException

use of org.apache.archiva.indexer.search.RepositorySearchException in project archiva by apache.

the class MavenRepositorySearch method getRemoteIndexingContextIds.

@Override
public Set<String> getRemoteIndexingContextIds(String managedRepoId) throws RepositorySearchException {
    Set<String> ids = new HashSet<>();
    List<ProxyConnector> proxyConnectors = null;
    try {
        proxyConnectors = proxyConnectorAdmin.getProxyConnectorAsMap().get(managedRepoId);
    } catch (RepositoryAdminException e) {
        throw new RepositorySearchException(e.getMessage(), e);
    }
    if (proxyConnectors == null || proxyConnectors.isEmpty()) {
        return ids;
    }
    for (ProxyConnector proxyConnector : proxyConnectors) {
        String remoteId = "remote-" + proxyConnector.getTargetRepoId();
        RemoteRepository repo = repositoryRegistry.getRemoteRepository(proxyConnector.getTargetRepoId());
        if (repo.getType() == RepositoryType.MAVEN) {
            try {
                IndexingContext context = repo.getIndexingContext() != null ? repo.getIndexingContext().getBaseContext(IndexingContext.class) : null;
                if (context != null && context.isSearchable()) {
                    ids.add(remoteId);
                }
            } catch (UnsupportedBaseContextException e) {
            // Ignore this one
            }
        }
    }
    return ids;
}
Also used : UnsupportedBaseContextException(org.apache.archiva.indexer.UnsupportedBaseContextException) IndexingContext(org.apache.maven.index.context.IndexingContext) RemoteRepository(org.apache.archiva.repository.RemoteRepository) ProxyConnector(org.apache.archiva.admin.model.beans.ProxyConnector) RepositorySearchException(org.apache.archiva.indexer.search.RepositorySearchException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) HashSet(java.util.HashSet)

Example 12 with RepositorySearchException

use of org.apache.archiva.indexer.search.RepositorySearchException in project archiva by apache.

the class MavenRepositorySearch method search.

private SearchResults search(SearchResultLimits limits, BooleanQuery q, List<String> indexingContextIds, List<? extends ArtifactInfoFilter> filters, List<String> selectedRepos, boolean includePoms) throws RepositorySearchException {
    try {
        FlatSearchRequest request = new FlatSearchRequest(q);
        request.setContexts(getIndexingContexts(indexingContextIds));
        if (limits != null) {
            // we apply limits only when first page asked
            if (limits.getSelectedPage() == 0) {
                request.setCount(limits.getPageSize() * (Math.max(1, limits.getSelectedPage())));
            }
        }
        FlatSearchResponse response = indexer.searchFlat(request);
        if (response == null || response.getTotalHitsCount() == 0) {
            SearchResults results = new SearchResults();
            results.setLimits(limits);
            return results;
        }
        return convertToSearchResults(response, limits, filters, selectedRepos, includePoms);
    } catch (IOException e) {
        throw new RepositorySearchException(e.getMessage(), e);
    } catch (RepositoryAdminException e) {
        throw new RepositorySearchException(e.getMessage(), e);
    }
}
Also used : FlatSearchResponse(org.apache.maven.index.FlatSearchResponse) FlatSearchRequest(org.apache.maven.index.FlatSearchRequest) IOException(java.io.IOException) RepositorySearchException(org.apache.archiva.indexer.search.RepositorySearchException) SearchResults(org.apache.archiva.indexer.search.SearchResults) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Aggregations

RepositorySearchException (org.apache.archiva.indexer.search.RepositorySearchException)12 SearchFields (org.apache.archiva.indexer.search.SearchFields)5 SearchResults (org.apache.archiva.indexer.search.SearchResults)5 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 IndexingContext (org.apache.maven.index.context.IndexingContext)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)2 UnsupportedBaseContextException (org.apache.archiva.indexer.UnsupportedBaseContextException)2 SearchResultLimits (org.apache.archiva.indexer.search.SearchResultLimits)2 RemoteRepository (org.apache.archiva.repository.RemoteRepository)2 Path (java.nio.file.Path)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 HttpSession (javax.servlet.http.HttpSession)1 ProxyConnector (org.apache.archiva.admin.model.beans.ProxyConnector)1 IndexMergerException (org.apache.archiva.indexer.merger.IndexMergerException)1