use of org.apache.archiva.indexer.search.RepositorySearchException in project archiva by apache.
the class DefaultSearchService method getAllGroupIds.
@Override
public GroupIdList getAllGroupIds(List<String> selectedRepos) throws ArchivaRestServiceException {
List<String> observableRepos = getObservableRepos();
List<String> repos = ListUtils.intersection(observableRepos, selectedRepos);
if (repos == null || repos.isEmpty()) {
return new GroupIdList(Collections.<String>emptyList());
}
try {
return new GroupIdList(new ArrayList<>(repositorySearch.getAllGroupIds(getPrincipal(), repos)));
} catch (RepositorySearchException e) {
log.error(e.getMessage(), e);
throw new ArchivaRestServiceException(e.getMessage(), e);
}
}
use of org.apache.archiva.indexer.search.RepositorySearchException in project archiva by apache.
the class ArchivaDavResourceFactory method buildMergedIndexDirectory.
protected Path buildMergedIndexDirectory(List<String> repositories, String activePrincipal, DavServletRequest request, RepositoryGroupConfiguration repositoryGroupConfiguration) throws DavException {
try {
HttpSession session = request.getSession();
@SuppressWarnings("unchecked") Map<String, TemporaryGroupIndex> temporaryGroupIndexMap = (Map<String, TemporaryGroupIndex>) session.getAttribute(TemporaryGroupIndexSessionCleaner.TEMPORARY_INDEX_SESSION_KEY);
if (temporaryGroupIndexMap == null) {
temporaryGroupIndexMap = new HashMap<>();
}
TemporaryGroupIndex tmp = temporaryGroupIndexMap.get(repositoryGroupConfiguration.getId());
if (tmp != null && tmp.getDirectory() != null && Files.exists(tmp.getDirectory())) {
if (System.currentTimeMillis() - tmp.getCreationTime() > (repositoryGroupConfiguration.getMergedIndexTtl() * 60 * 1000)) {
log.debug(MarkerFactory.getMarker("group.merged.index"), "tmp group index '{}' is too old so delete it", repositoryGroupConfiguration.getId());
indexMerger.cleanTemporaryGroupIndex(tmp);
} else {
log.debug(MarkerFactory.getMarker("group.merged.index"), "merged index for group '{}' found in cache", repositoryGroupConfiguration.getId());
return tmp.getDirectory();
}
}
Set<String> authzRepos = new HashSet<String>();
String permission = WebdavMethodUtil.getMethodPermission(request.getMethod());
for (String repository : repositories) {
try {
if (servletAuth.isAuthorized(activePrincipal, repository, permission)) {
authzRepos.add(repository);
authzRepos.addAll(this.repositorySearch.getRemoteIndexingContextIds(repository));
}
} catch (UnauthorizedException e) {
// TODO: review exception handling
log.debug("Skipping repository '{}' for user '{}': {}", repository, activePrincipal, e.getMessage());
}
}
log.info("generate temporary merged index for repository group '{}' for repositories '{}'", repositoryGroupConfiguration.getId(), authzRepos);
Path tempRepoFile = Files.createTempDirectory("temp");
tempRepoFile.toFile().deleteOnExit();
IndexMergerRequest indexMergerRequest = new IndexMergerRequest(authzRepos, true, repositoryGroupConfiguration.getId(), repositoryGroupConfiguration.getMergedIndexPath(), repositoryGroupConfiguration.getMergedIndexTtl()).mergedIndexDirectory(tempRepoFile).temporary(true);
MergedRemoteIndexesTaskRequest taskRequest = new MergedRemoteIndexesTaskRequest(indexMergerRequest, indexMerger);
MergedRemoteIndexesTask job = new MergedRemoteIndexesTask(taskRequest);
IndexingContext indexingContext = job.execute().getIndexingContext();
Path mergedRepoDir = indexingContext.getIndexDirectoryFile().toPath();
TemporaryGroupIndex temporaryGroupIndex = new TemporaryGroupIndex(mergedRepoDir, indexingContext.getId(), repositoryGroupConfiguration.getId(), //
repositoryGroupConfiguration.getMergedIndexTtl()).setCreationTime(new Date().getTime());
temporaryGroupIndexMap.put(repositoryGroupConfiguration.getId(), temporaryGroupIndex);
session.setAttribute(TemporaryGroupIndexSessionCleaner.TEMPORARY_INDEX_SESSION_KEY, temporaryGroupIndexMap);
return mergedRepoDir;
} catch (RepositorySearchException e) {
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
} catch (IndexMergerException e) {
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
} catch (IOException e) {
throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
}
}
use of org.apache.archiva.indexer.search.RepositorySearchException in project archiva by apache.
the class DefaultSearchService method quickSearchWithRepositories.
@Override
public List<Artifact> quickSearchWithRepositories(SearchRequest searchRequest) throws ArchivaRestServiceException {
String queryString = searchRequest.getQueryTerms();
if (StringUtils.isBlank(queryString)) {
return Collections.emptyList();
}
List<String> repositories = searchRequest.getRepositories();
if (repositories == null || repositories.isEmpty()) {
repositories = getObservableRepos();
}
SearchResultLimits limits = new SearchResultLimits(searchRequest.getPageSize(), searchRequest.getSelectedPage());
try {
SearchResults searchResults = repositorySearch.search(getPrincipal(), repositories, queryString, limits, Collections.<String>emptyList());
return getArtifacts(searchResults);
} catch (RepositorySearchException e) {
log.error(e.getMessage(), e);
throw new ArchivaRestServiceException(e.getMessage(), e);
}
}
use of org.apache.archiva.indexer.search.RepositorySearchException in project archiva by apache.
the class DefaultSearchService method getArtifactVersions.
@Override
public List<Artifact> getArtifactVersions(String groupId, String artifactId, String packaging) throws ArchivaRestServiceException {
if (StringUtils.isBlank(groupId) || StringUtils.isBlank(artifactId)) {
return Collections.emptyList();
}
SearchFields searchField = new SearchFields();
searchField.setGroupId(groupId);
searchField.setArtifactId(artifactId);
searchField.setPackaging(StringUtils.isBlank(packaging) ? "jar" : packaging);
searchField.setRepositories(getObservableRepos());
try {
SearchResults searchResults = repositorySearch.search(getPrincipal(), searchField, null);
return getArtifacts(searchResults);
} catch (RepositorySearchException e) {
log.error(e.getMessage(), e);
throw new ArchivaRestServiceException(e.getMessage(), e);
}
}
use of org.apache.archiva.indexer.search.RepositorySearchException in project archiva by apache.
the class MavenRepositorySearch method addIndexingContexts.
/**
* @param selectedRepos
* @return indexing contextId used
*/
private List<String> addIndexingContexts(List<String> selectedRepos) {
Set<String> indexingContextIds = new HashSet<>();
for (String repo : selectedRepos) {
try {
Repository rRepo = repositoryRegistry.getRepository(repo);
if (rRepo != null) {
if (rRepo.getType().equals(RepositoryType.MAVEN)) {
assert rRepo.getIndexingContext() != null;
IndexingContext context = rRepo.getIndexingContext().getBaseContext(IndexingContext.class);
if (context.isSearchable()) {
indexingContextIds.addAll(getRemoteIndexingContextIds(repo));
indexingContextIds.add(context.getId());
} else {
log.warn("indexingContext with id {} not searchable", rRepo.getId());
}
}
} else {
log.warn("Repository '{}' not found in configuration.", repo);
}
} catch (RepositorySearchException e) {
log.warn("RepositorySearchException occured while accessing index of repository '{}' : {}", repo, e.getMessage());
continue;
} catch (UnsupportedBaseContextException e) {
log.error("Fatal situation: Maven repository without IndexingContext found.");
continue;
}
}
return new ArrayList<>(indexingContextIds);
}
Aggregations