Search in sources :

Example 1 with ArtifactBuilder

use of org.apache.archiva.rest.services.utils.ArtifactBuilder in project archiva by apache.

the class AbstractRestService method buildArtifacts.

protected List<Artifact> buildArtifacts(Collection<ArtifactMetadata> artifactMetadatas, String repositoryId) throws ArchivaRestServiceException {
    try {
        if (artifactMetadatas != null && !artifactMetadatas.isEmpty()) {
            List<Artifact> artifacts = new ArrayList<>(artifactMetadatas.size());
            for (ArtifactMetadata artifact : artifactMetadatas) {
                String repoId = repositoryId != null ? repositoryId : artifact.getRepositoryId();
                if (repoId == null) {
                    throw new IllegalStateException("Repository Id is null");
                }
                ManagedRepository repo = repositoryRegistry.getManagedRepository(repoId);
                if (repo == null) {
                    throw new RepositoryException("Repository not found " + repoId);
                }
                ManagedRepositoryContent content = repo.getContent();
                ArtifactBuilder builder = new ArtifactBuilder().forArtifactMetadata(artifact).withManagedRepositoryContent(content);
                Artifact art = builder.build();
                art.setUrl(getArtifactUrl(art, repositoryId));
                artifacts.add(art);
            }
            return artifacts;
        }
        return Collections.emptyList();
    } catch (RepositoryException e) {
        log.error(e.getMessage(), e);
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    }
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) ArrayList(java.util.ArrayList) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) RepositoryException(org.apache.archiva.repository.RepositoryException) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) ArtifactBuilder(org.apache.archiva.rest.services.utils.ArtifactBuilder) Artifact(org.apache.archiva.maven2.model.Artifact)

Aggregations

ArrayList (java.util.ArrayList)1 Artifact (org.apache.archiva.maven2.model.Artifact)1 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)1 ManagedRepository (org.apache.archiva.repository.ManagedRepository)1 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)1 RepositoryException (org.apache.archiva.repository.RepositoryException)1 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)1 ArtifactBuilder (org.apache.archiva.rest.services.utils.ArtifactBuilder)1