Search in sources :

Example 6 with MetadataResolver

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;
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) ArrayList(java.util.ArrayList) MetadataResolver(org.apache.archiva.metadata.repository.MetadataResolver) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Artifact(org.apache.archiva.maven2.model.Artifact) ArchivaArtifact(org.apache.archiva.model.ArchivaArtifact) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException)

Example 7 with MetadataResolver

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();
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) MetadataResolver(org.apache.archiva.metadata.repository.MetadataResolver) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession)

Aggregations

MetadataResolver (org.apache.archiva.metadata.repository.MetadataResolver)7 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)7 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)6 ArrayList (java.util.ArrayList)5 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)5 LinkedHashSet (java.util.LinkedHashSet)3 Artifact (org.apache.archiva.maven2.model.Artifact)2 ProjectVersionMetadata (org.apache.archiva.metadata.model.ProjectVersionMetadata)2 ArchivaArtifact (org.apache.archiva.model.ArchivaArtifact)2 BrowseResult (org.apache.archiva.rest.api.model.BrowseResult)2 BrowseResultEntry (org.apache.archiva.rest.api.model.BrowseResultEntry)2 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)1 ProjectVersionReference (org.apache.archiva.metadata.model.ProjectVersionReference)1 MavenProjectFacet (org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet)1