Search in sources :

Example 31 with ArchivaRestServiceException

use of org.apache.archiva.rest.api.services.ArchivaRestServiceException 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);
    }
}
Also used : SearchFields(org.apache.archiva.indexer.search.SearchFields) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) RepositorySearchException(org.apache.archiva.indexer.search.RepositorySearchException) SearchResults(org.apache.archiva.indexer.search.SearchResults)

Example 32 with ArchivaRestServiceException

use of org.apache.archiva.rest.api.services.ArchivaRestServiceException in project archiva by apache.

the class BrowseServiceTest method metadatagetthenaddthendelete.

@Test
public void metadatagetthenaddthendelete() throws Exception {
    try {
        scanRepo(TEST_REPO_ID);
        waitForScanToComplete(TEST_REPO_ID);
        BrowseService browseService = getBrowseService(authorizationHeader, false);
        Map<String, String> metadatas = toMap(browseService.getMetadatas("commons-cli", "commons-cli", "1.0", TEST_REPO_ID));
        assertThat(metadatas).isNotNull().isEmpty();
        browseService.addMetadata("commons-cli", "commons-cli", "1.0", "wine", "bordeaux", TEST_REPO_ID);
        metadatas = toMap(browseService.getMetadatas("commons-cli", "commons-cli", "1.0", TEST_REPO_ID));
        assertThat(metadatas).isNotNull().isNotEmpty().contains(MapEntry.entry("wine", "bordeaux"));
        browseService.deleteMetadata("commons-cli", "commons-cli", "1.0", "wine", TEST_REPO_ID);
        metadatas = toMap(browseService.getMetadatas("commons-cli", "commons-cli", "1.0", TEST_REPO_ID));
        assertThat(metadatas).isNotNull().isEmpty();
    } catch (ArchivaRestServiceException e) {
        log.error(e.getMessage(), e);
        throw e;
    }
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) BrowseService(org.apache.archiva.rest.api.services.BrowseService) Test(org.junit.Test)

Example 33 with ArchivaRestServiceException

use of org.apache.archiva.rest.api.services.ArchivaRestServiceException in project archiva by apache.

the class DefaultBrowseService method getProjectVersionMetadata.

@Override
public ProjectVersionMetadata getProjectVersionMetadata(String groupId, String artifactId, String repositoryId) throws ArchivaRestServiceException {
    List<String> selectedRepos = getSelectedRepos(repositoryId);
    RepositorySession repositorySession = null;
    try {
        Collection<String> projectVersions = getVersions(selectedRepos, groupId, artifactId);
        repositorySession = repositorySessionFactory.createSession();
        MetadataResolver metadataResolver = repositorySession.getResolver();
        ProjectVersionMetadata sharedModel = new ProjectVersionMetadata();
        MavenProjectFacet mavenFacet = new MavenProjectFacet();
        mavenFacet.setGroupId(groupId);
        mavenFacet.setArtifactId(artifactId);
        sharedModel.addFacet(mavenFacet);
        boolean isFirstVersion = true;
        for (String version : projectVersions) {
            ProjectVersionMetadata versionMetadata = null;
            for (String repoId : selectedRepos) {
                if (versionMetadata == null || versionMetadata.isIncomplete()) {
                    try {
                        ProjectVersionMetadata projectVersionMetadataResolved = null;
                        boolean useCache = !StringUtils.endsWith(version, VersionUtil.SNAPSHOT);
                        String cacheKey = null;
                        boolean cacheToUpdate = false;
                        // not a snapshot so get it from cache
                        if (useCache) {
                            cacheKey = repoId + groupId + artifactId + version;
                            projectVersionMetadataResolved = versionMetadataCache.get(cacheKey);
                        }
                        if (useCache && projectVersionMetadataResolved != null) {
                            versionMetadata = projectVersionMetadataResolved;
                        } else {
                            projectVersionMetadataResolved = metadataResolver.resolveProjectVersion(repositorySession, repoId, groupId, artifactId, version);
                            versionMetadata = projectVersionMetadataResolved;
                            cacheToUpdate = true;
                        }
                        if (useCache && cacheToUpdate) {
                            versionMetadataCache.put(cacheKey, projectVersionMetadataResolved);
                        }
                    } catch (MetadataResolutionException e) {
                        log.error("Skipping invalid metadata while compiling shared model for " + groupId + ":" + artifactId + " in repo " + repoId + ": " + e.getMessage());
                    }
                }
            }
            if (versionMetadata == null) {
                continue;
            }
            if (isFirstVersion) {
                sharedModel = versionMetadata;
                sharedModel.setId(null);
            } else {
                MavenProjectFacet versionMetadataMavenFacet = (MavenProjectFacet) versionMetadata.getFacet(MavenProjectFacet.FACET_ID);
                if (versionMetadataMavenFacet != null) {
                    if (// 
                    mavenFacet.getPackaging() != null && !StringUtils.equalsIgnoreCase(mavenFacet.getPackaging(), versionMetadataMavenFacet.getPackaging())) {
                        mavenFacet.setPackaging(null);
                    }
                }
                if (// 
                StringUtils.isEmpty(sharedModel.getName()) && !StringUtils.isEmpty(versionMetadata.getName())) {
                    sharedModel.setName(versionMetadata.getName());
                }
                if (// 
                sharedModel.getDescription() != null && !StringUtils.equalsIgnoreCase(sharedModel.getDescription(), versionMetadata.getDescription())) {
                    sharedModel.setDescription(StringUtils.isNotEmpty(versionMetadata.getDescription()) ? versionMetadata.getDescription() : "");
                }
                if (// 
                sharedModel.getIssueManagement() != null && // 
                versionMetadata.getIssueManagement() != null && !StringUtils.equalsIgnoreCase(sharedModel.getIssueManagement().getUrl(), versionMetadata.getIssueManagement().getUrl())) {
                    sharedModel.setIssueManagement(versionMetadata.getIssueManagement());
                }
                if (// 
                sharedModel.getCiManagement() != null && // 
                versionMetadata.getCiManagement() != null && !StringUtils.equalsIgnoreCase(sharedModel.getCiManagement().getUrl(), versionMetadata.getCiManagement().getUrl())) {
                    sharedModel.setCiManagement(versionMetadata.getCiManagement());
                }
                if (// 
                sharedModel.getOrganization() != null && // 
                versionMetadata.getOrganization() != null && !StringUtils.equalsIgnoreCase(sharedModel.getOrganization().getName(), versionMetadata.getOrganization().getName())) {
                    sharedModel.setOrganization(versionMetadata.getOrganization());
                }
                if (// 
                sharedModel.getUrl() != null && !StringUtils.equalsIgnoreCase(sharedModel.getUrl(), versionMetadata.getUrl())) {
                    sharedModel.setUrl(versionMetadata.getUrl());
                }
            }
            isFirstVersion = false;
        }
        return sharedModel;
    } catch (MetadataResolutionException e) {
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    } finally {
        if (repositorySession != null) {
            repositorySession.close();
        }
    }
}
Also used : ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) MavenProjectFacet(org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet) MetadataResolver(org.apache.archiva.metadata.repository.MetadataResolver) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException)

Example 34 with ArchivaRestServiceException

use of org.apache.archiva.rest.api.services.ArchivaRestServiceException in project archiva by apache.

the class DefaultBrowseService method getDependees.

@Override
public List<Artifact> getDependees(String groupId, String artifactId, String version, String repositoryId) throws ArchivaRestServiceException {
    List<ProjectVersionReference> references = new ArrayList<>();
    // TODO: what if we get duplicates across repositories?
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    try {
        MetadataResolver metadataResolver = repositorySession.getResolver();
        for (String repoId : getObservableRepos()) {
            // TODO: what about if we want to see this irrespective of version?
            references.addAll(metadataResolver.resolveProjectReferences(repositorySession, repoId, groupId, artifactId, version));
        }
    } catch (MetadataResolutionException e) {
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    } finally {
        repositorySession.close();
    }
    List<Artifact> artifacts = new ArrayList<>(references.size());
    for (ProjectVersionReference projectVersionReference : references) {
        artifacts.add(new Artifact(projectVersionReference.getNamespace(), projectVersionReference.getProjectId(), projectVersionReference.getProjectVersion()));
    }
    return artifacts;
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) ArrayList(java.util.ArrayList) MetadataResolver(org.apache.archiva.metadata.repository.MetadataResolver) ProjectVersionReference(org.apache.archiva.metadata.model.ProjectVersionReference) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) Artifact(org.apache.archiva.maven2.model.Artifact) ArchivaArtifact(org.apache.archiva.model.ArchivaArtifact)

Example 35 with ArchivaRestServiceException

use of org.apache.archiva.rest.api.services.ArchivaRestServiceException 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)

Aggregations

ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)44 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)18 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)16 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)15 RepositoryException (org.apache.archiva.repository.RepositoryException)13 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)11 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)10 ArrayList (java.util.ArrayList)9 IOException (java.io.IOException)8 Path (java.nio.file.Path)8 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)8 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)8 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)7 Artifact (org.apache.archiva.maven2.model.Artifact)6 RepositorySearchException (org.apache.archiva.indexer.search.RepositorySearchException)5 MetadataResolver (org.apache.archiva.metadata.repository.MetadataResolver)5 ArtifactReference (org.apache.archiva.model.ArtifactReference)5 SearchResults (org.apache.archiva.indexer.search.SearchResults)4 ArchivaArtifact (org.apache.archiva.model.ArchivaArtifact)4 RepositoryNotFoundException (org.apache.archiva.repository.RepositoryNotFoundException)4