use of org.apache.archiva.metadata.repository.MetadataResolver in project archiva by apache.
the class DefaultBrowseService method getArtifactDownloadInfos.
@Override
public List<Artifact> getArtifactDownloadInfos(String groupId, String artifactId, String version, String repositoryId) throws ArchivaRestServiceException {
List<String> selectedRepos = getSelectedRepos(repositoryId);
List<Artifact> artifactDownloadInfos = new ArrayList<>();
try (RepositorySession session = repositorySessionFactory.createSession()) {
MetadataResolver metadataResolver = session.getResolver();
for (String repoId : selectedRepos) {
List<ArtifactMetadata> artifacts = new ArrayList<>(metadataResolver.resolveArtifacts(session, repoId, groupId, artifactId, version));
Collections.sort(artifacts, ArtifactMetadataVersionComparator.INSTANCE);
if (artifacts != null && !artifacts.isEmpty()) {
return buildArtifacts(artifacts, repoId);
}
}
} catch (MetadataResolutionException e) {
log.error(e.getMessage(), e);
throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
}
return artifactDownloadInfos;
}
use of org.apache.archiva.metadata.repository.MetadataResolver in project archiva by apache.
the class DefaultBrowseService method getVersions.
private Collection<String> getVersions(List<String> selectedRepos, String groupId, String artifactId) throws MetadataResolutionException {
RepositorySession repositorySession = repositorySessionFactory.createSession();
try {
MetadataResolver metadataResolver = repositorySession.getResolver();
Set<String> versions = new LinkedHashSet<String>();
for (String repoId : selectedRepos) {
Collection<String> projectVersions = metadataResolver.resolveProjectVersions(repositorySession, repoId, groupId, artifactId);
versions.addAll(projectVersions);
}
List<String> sortedVersions = new ArrayList<>(versions);
Collections.sort(sortedVersions, VersionComparator.getInstance());
return sortedVersions;
} finally {
repositorySession.close();
}
}
Aggregations