Search in sources :

Example 16 with MetadataRepository

use of org.apache.archiva.metadata.repository.MetadataRepository in project archiva by apache.

the class DefaultRepositoryArchivaTaskScheduler method startup.

@PostConstruct
public void startup() throws ArchivaException {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    archivaConfiguration.addListener(this);
    List<ManagedRepositoryConfiguration> repositories = archivaConfiguration.getConfiguration().getManagedRepositories();
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    try {
        MetadataRepository metadataRepository = repositorySession.getRepository();
        for (ManagedRepositoryConfiguration repoConfig : repositories) {
            if (repoConfig.isScanned()) {
                try {
                    scheduleRepositoryJobs(repoConfig);
                } catch (SchedulerException e) {
                    throw new ArchivaException("Unable to start scheduler: " + e.getMessage(), e);
                }
                try {
                    if (!isPreviouslyScanned(repoConfig, metadataRepository)) {
                        queueInitialRepoScan(repoConfig);
                    }
                } catch (MetadataRepositoryException e) {
                    log.warn("Unable to determine if a repository is already scanned, skipping initial scan: {}", e.getMessage(), e);
                }
            }
        }
    } finally {
        repositorySession.close();
    }
    stopWatch.stop();
    log.info("Time to initalize DefaultRepositoryArchivaTaskScheduler: {} ms", stopWatch.getTime());
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) SchedulerException(org.quartz.SchedulerException) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) ArchivaException(org.apache.archiva.common.ArchivaException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) StopWatch(org.apache.commons.lang.time.StopWatch) PostConstruct(javax.annotation.PostConstruct)

Example 17 with MetadataRepository

use of org.apache.archiva.metadata.repository.MetadataRepository in project archiva by apache.

the class DefaultReportRepositoriesService method getHealthReport.

@Override
public List<RepositoryProblemFacet> getHealthReport(String repository, String groupId, int rowCount) throws ArchivaRestServiceException {
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    try {
        List<String> observableRepositories = getObservableRepos();
        if (!ALL_REPOSITORIES.equals(repository) && !observableRepositories.contains(repository)) {
            throw new ArchivaRestServiceException("${$.i18n.prop('report.repository.illegal-access', " + repository + ")}", "repositoryId", new IllegalAccessException());
        }
        if (!ALL_REPOSITORIES.equals(repository)) {
            observableRepositories = Collections.singletonList(repository);
        }
        List<RepositoryProblemFacet> problemArtifacts = new ArrayList<>();
        MetadataRepository metadataRepository = repositorySession.getRepository();
        for (String repoId : observableRepositories) {
            for (String name : metadataRepository.getMetadataFacets(repoId, RepositoryProblemFacet.FACET_ID)) {
                RepositoryProblemFacet metadataFacet = (RepositoryProblemFacet) metadataRepository.getMetadataFacet(repoId, RepositoryProblemFacet.FACET_ID, name);
                if (StringUtils.isEmpty(groupId) || groupId.equals(metadataFacet.getNamespace())) {
                    problemArtifacts.add(metadataFacet);
                }
            }
        }
        return problemArtifacts;
    } catch (MetadataRepositoryException e) {
        throw new ArchivaRestServiceException(e.getMessage(), e);
    } finally {
        repositorySession.close();
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) RepositoryProblemFacet(org.apache.archiva.metadata.model.facets.RepositoryProblemFacet) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) ArrayList(java.util.ArrayList) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession)

Example 18 with MetadataRepository

use of org.apache.archiva.metadata.repository.MetadataRepository in project archiva by apache.

the class DefaultRepositoriesService method removeProjectVersion.

@Override
public Boolean removeProjectVersion(String repositoryId, String namespace, String projectId, String version) throws ArchivaRestServiceException {
    // if not a generic we can use the standard way to delete artifact
    if (!VersionUtil.isGenericSnapshot(version)) {
        Artifact artifact = new Artifact(namespace, projectId, version);
        artifact.setRepositoryId(repositoryId);
        artifact.setContext(repositoryId);
        return deleteArtifact(artifact);
    }
    if (StringUtils.isEmpty(repositoryId)) {
        throw new ArchivaRestServiceException("repositoryId cannot be null", 400, null);
    }
    if (!isAuthorizedToDeleteArtifacts(repositoryId)) {
        throw new ArchivaRestServiceException("not authorized to delete artifacts", 403, null);
    }
    if (StringUtils.isEmpty(namespace)) {
        throw new ArchivaRestServiceException("groupId cannot be null", 400, null);
    }
    if (StringUtils.isEmpty(projectId)) {
        throw new ArchivaRestServiceException("artifactId cannot be null", 400, null);
    }
    if (StringUtils.isEmpty(version)) {
        throw new ArchivaRestServiceException("version cannot be null", 400, null);
    }
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    try {
        ManagedRepositoryContent repository = getManagedRepositoryContent(repositoryId);
        VersionedReference ref = new VersionedReference();
        ref.setArtifactId(projectId);
        ref.setGroupId(namespace);
        ref.setVersion(version);
        repository.deleteVersion(ref);
        /*
            ProjectReference projectReference = new ProjectReference();
            projectReference.setGroupId( namespace );
            projectReference.setArtifactId( projectId );

            repository.getVersions(  )
            */
        ArtifactReference artifactReference = new ArtifactReference();
        artifactReference.setGroupId(namespace);
        artifactReference.setArtifactId(projectId);
        artifactReference.setVersion(version);
        MetadataRepository metadataRepository = repositorySession.getRepository();
        Set<ArtifactReference> related = repository.getRelatedArtifacts(artifactReference);
        log.debug("related: {}", related);
        for (ArtifactReference artifactRef : related) {
            repository.deleteArtifact(artifactRef);
        }
        Collection<ArtifactMetadata> artifacts = metadataRepository.getArtifacts(repositoryId, namespace, projectId, version);
        for (ArtifactMetadata artifactMetadata : artifacts) {
            metadataRepository.removeArtifact(artifactMetadata, version);
        }
        metadataRepository.removeProjectVersion(repositoryId, namespace, projectId, version);
    } catch (MetadataRepositoryException e) {
        throw new ArchivaRestServiceException("Repository exception: " + e.getMessage(), 500, e);
    } catch (MetadataResolutionException e) {
        throw new ArchivaRestServiceException("Repository exception: " + e.getMessage(), 500, e);
    } catch (RepositoryException e) {
        throw new ArchivaRestServiceException("Repository exception: " + e.getMessage(), 500, e);
    } finally {
        repositorySession.save();
        repositorySession.close();
    }
    return Boolean.TRUE;
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) Artifact(org.apache.archiva.maven2.model.Artifact) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) VersionedReference(org.apache.archiva.model.VersionedReference) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) ArtifactReference(org.apache.archiva.model.ArtifactReference) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 19 with MetadataRepository

use of org.apache.archiva.metadata.repository.MetadataRepository in project archiva by apache.

the class DefaultRepositoriesService method deleteGroupId.

@Override
public Boolean deleteGroupId(String groupId, String repositoryId) throws ArchivaRestServiceException {
    if (StringUtils.isEmpty(repositoryId)) {
        throw new ArchivaRestServiceException("repositoryId cannot be null", 400, null);
    }
    if (!isAuthorizedToDeleteArtifacts(repositoryId)) {
        throw new ArchivaRestServiceException("not authorized to delete artifacts", 403, null);
    }
    if (StringUtils.isEmpty(groupId)) {
        throw new ArchivaRestServiceException("groupId cannot be null", 400, null);
    }
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    try {
        ManagedRepositoryContent repository = getManagedRepositoryContent(repositoryId);
        repository.deleteGroupId(groupId);
        MetadataRepository metadataRepository = repositorySession.getRepository();
        metadataRepository.removeNamespace(repositoryId, groupId);
        // just invalidate cache entry
        String cacheKey = repositoryId + "-" + groupId;
        namespacesCache.remove(cacheKey);
        namespacesCache.remove(repositoryId);
        metadataRepository.save();
    } catch (MetadataRepositoryException e) {
        log.error(e.getMessage(), e);
        throw new ArchivaRestServiceException("Repository exception: " + e.getMessage(), 500, e);
    } catch (RepositoryException e) {
        log.error(e.getMessage(), e);
        throw new ArchivaRestServiceException("Repository exception: " + e.getMessage(), 500, e);
    } finally {
        repositorySession.close();
    }
    return true;
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession)

Example 20 with MetadataRepository

use of org.apache.archiva.metadata.repository.MetadataRepository in project archiva by apache.

the class NewVersionsOfArtifactRssFeedProcessorTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    newVersionsProcessor = new NewVersionsOfArtifactRssFeedProcessor();
    newVersionsProcessor.setGenerator(new RssFeedGenerator());
    metadataRepositoryControl = createControl();
    metadataRepository = metadataRepositoryControl.createMock(MetadataRepository.class);
}
Also used : MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) RssFeedGenerator(org.apache.archiva.rss.RssFeedGenerator) Before(org.junit.Before)

Aggregations

MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)25 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)20 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)18 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)10 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)8 Path (java.nio.file.Path)6 RepositoryException (org.apache.archiva.repository.RepositoryException)6 ArrayList (java.util.ArrayList)5 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)5 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)5 RepositoryStatistics (org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics)4 ArtifactReference (org.apache.archiva.model.ArtifactReference)4 ContentNotFoundException (org.apache.archiva.repository.ContentNotFoundException)4 IOException (java.io.IOException)3 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)3 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)3 ProjectVersionMetadata (org.apache.archiva.metadata.model.ProjectVersionMetadata)3 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)3 VersionedReference (org.apache.archiva.model.VersionedReference)3 RepositoryListener (org.apache.archiva.repository.events.RepositoryListener)3