Search in sources :

Example 36 with MetadataRepositoryException

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

the class DefaultBrowseService method deleteMetadata.

@Override
public Boolean deleteMetadata(String groupId, String artifactId, String version, String key, String repositoryId) throws ArchivaRestServiceException {
    ProjectVersionMetadata projectVersionMetadata = getProjectMetadata(groupId, artifactId, version, repositoryId);
    if (projectVersionMetadata == null) {
        return Boolean.FALSE;
    }
    GenericMetadataFacet metadataFacet = (GenericMetadataFacet) projectVersionMetadata.getFacet(GenericMetadataFacet.FACET_ID);
    if (metadataFacet != null && metadataFacet.toProperties() != null) {
        Map<String, String> properties = metadataFacet.toProperties();
        properties.remove(key);
        metadataFacet.setAdditionalProperties(properties);
    } else {
        return Boolean.TRUE;
    }
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    try {
        MetadataRepository metadataRepository = repositorySession.getRepository();
        metadataRepository.updateProjectVersion(repositoryId, groupId, artifactId, projectVersionMetadata);
        repositorySession.save();
    } catch (MetadataRepositoryException e) {
        log.error(e.getMessage(), e);
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    } finally {
        repositorySession.close();
    }
    return Boolean.TRUE;
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) GenericMetadataFacet(org.apache.archiva.metadata.generic.GenericMetadataFacet) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession)

Example 37 with MetadataRepositoryException

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

the class DefaultManagedRepositoriesService method getManagedRepositoryStatistics.

@Override
public ArchivaRepositoryStatistics getManagedRepositoryStatistics(String repositoryId, String lang) throws ArchivaRestServiceException {
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", new Locale(lang));
    try {
        MetadataRepository metadataRepository = repositorySession.getRepository();
        RepositoryStatistics stats = null;
        try {
            stats = repositoryStatisticsManager.getLastStatistics(metadataRepository, repositoryId);
        } catch (MetadataRepositoryException e) {
            log.warn("Error retrieving repository statistics: {}", e.getMessage(), e);
        }
        if (stats != null) {
            ArchivaRepositoryStatistics archivaRepositoryStatistics = getModelMapper().map(stats, ArchivaRepositoryStatistics.class);
            archivaRepositoryStatistics.setDuration(archivaRepositoryStatistics.getScanEndTime().getTime() - archivaRepositoryStatistics.getScanStartTime().getTime());
            archivaRepositoryStatistics.setLastScanDate(sdf.format(archivaRepositoryStatistics.getScanEndTime()));
            return archivaRepositoryStatistics;
        }
    } finally {
        if (repositorySession != null) {
            repositorySession.close();
        }
    }
    return null;
}
Also used : Locale(java.util.Locale) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) ArchivaRepositoryStatistics(org.apache.archiva.rest.api.model.ArchivaRepositoryStatistics) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) SimpleDateFormat(java.text.SimpleDateFormat) RepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics) ArchivaRepositoryStatistics(org.apache.archiva.rest.api.model.ArchivaRepositoryStatistics)

Example 38 with MetadataRepositoryException

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

the class NewArtifactsRssFeedProcessor method processNewArtifactsInRepo.

private SyndFeed processNewArtifactsInRepo(String repoId, MetadataRepository metadataRepository) throws FeedException {
    Calendar greaterThanThisDate = Calendar.getInstance(GMT_TIME_ZONE);
    greaterThanThisDate.add(Calendar.DATE, -(getNumberOfDaysBeforeNow()));
    greaterThanThisDate.clear(Calendar.MILLISECOND);
    List<ArtifactMetadata> artifacts;
    try {
        artifacts = metadataRepository.getArtifactsByDateRange(repoId, greaterThanThisDate.getTime(), null);
    } catch (MetadataRepositoryException e) {
        throw new FeedException("Unable to construct feed, metadata could not be retrieved: " + e.getMessage(), e);
    }
    long tmp = 0;
    RssFeedEntry entry = null;
    List<RssFeedEntry> entries = new ArrayList<>();
    String description = "";
    int idx = 0;
    for (ArtifactMetadata artifact : artifacts) {
        long whenGathered = artifact.getWhenGathered().getTime();
        String id = artifact.getNamespace() + "/" + artifact.getProject() + "/" + artifact.getId();
        if (tmp != whenGathered) {
            if (entry != null) {
                entry.setDescription(description);
                entries.add(entry);
                entry = null;
            }
            String repoId1 = artifact.getRepositoryId();
            entry = new RssFeedEntry(this.getTitle() + "\'" + repoId1 + "\'" + " as of " + new Date(whenGathered));
            entry.setPublishedDate(artifact.getWhenGathered());
            description = this.getDescription() + "\'" + repoId1 + "\'" + ": \n" + id + " | ";
        } else {
            description = description + id + " | ";
        }
        if (idx == (artifacts.size() - 1)) {
            entry.setDescription(description);
            entries.add(entry);
        }
        tmp = whenGathered;
        idx++;
    }
    return generator.generateFeed(getTitle() + "\'" + repoId + "\'", "New artifacts found in repository " + "\'" + repoId + "\'" + " during repository scan.", entries);
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) Calendar(java.util.Calendar) FeedException(com.sun.syndication.io.FeedException) ArrayList(java.util.ArrayList) RssFeedEntry(org.apache.archiva.rss.RssFeedEntry) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Date(java.util.Date)

Example 39 with MetadataRepositoryException

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

the class NewVersionsOfArtifactRssFeedProcessor method processNewVersionsOfArtifact.

private SyndFeed processNewVersionsOfArtifact(String groupId, String artifactId, MetadataRepository metadataRepository) throws FeedException {
    List<ArtifactMetadata> artifacts = new ArrayList<>();
    try {
        for (String repoId : metadataRepository.getRepositories()) {
            Collection<String> versions = metadataRepository.getProjectVersions(repoId, groupId, artifactId);
            for (String version : versions) {
                artifacts.addAll(metadataRepository.getArtifacts(repoId, groupId, artifactId, version));
            }
        }
    } catch (MetadataRepositoryException e) {
        throw new FeedException("Unable to construct feed, metadata could not be retrieved: " + e.getMessage(), e);
    } catch (MetadataResolutionException e) {
        throw new FeedException("Unable to construct feed, metadata could not be retrieved: " + e.getMessage(), e);
    }
    long tmp = 0;
    RssFeedEntry entry = null;
    List<RssFeedEntry> entries = new ArrayList<>();
    String description = "";
    int idx = 0;
    for (ArtifactMetadata artifact : artifacts) {
        long whenGathered = artifact.getWhenGathered().getTime();
        if (tmp != whenGathered) {
            if (entry != null) {
                entry.setDescription(description);
                entries.add(entry);
                entry = null;
            }
            entry = new RssFeedEntry(this.getTitle() + "\'" + groupId + ":" + artifactId + "\'" + " as of " + new Date(whenGathered));
            entry.setPublishedDate(artifact.getWhenGathered());
            description = this.getDescription() + "\'" + groupId + ":" + artifactId + "\'" + ": \n" + artifact.getId() + " | ";
        } else {
            description = description + artifact.getId() + " | ";
        }
        if (idx == (artifacts.size() - 1)) {
            entry.setDescription(description);
            entries.add(entry);
        }
        tmp = whenGathered;
        idx++;
    }
    String key = groupId + ":" + artifactId;
    return generator.generateFeed(getTitle() + "\'" + key + "\'", "New versions of artifact " + "\'" + key + "\' found during repository scan.", entries);
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) FeedException(com.sun.syndication.io.FeedException) ArrayList(java.util.ArrayList) RssFeedEntry(org.apache.archiva.rss.RssFeedEntry) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) Date(java.util.Date) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 40 with MetadataRepositoryException

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

the class DefaultMergeRepositoriesService method doMerge.

protected void doMerge(String sourceRepositoryId, String targetRepositoryId) throws RepositoryMergerException, ArchivaRestServiceException {
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    try {
        ManagedRepository repository = managedRepositoryAdmin.getManagedRepository(targetRepositoryId);
        MetadataRepository metadataRepository = repositorySession.getRepository();
        List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts(sourceRepositoryId);
        if (repository.isReleases() && !repository.isSnapshots()) {
            mergeWithOutSnapshots(metadataRepository, sourceArtifacts, sourceRepositoryId, targetRepositoryId);
        } else {
            repositoryMerger.merge(metadataRepository, sourceRepositoryId, targetRepositoryId);
            for (ArtifactMetadata metadata : sourceArtifacts) {
                triggerAuditEvent(targetRepositoryId, metadata.getId(), AuditEvent.MERGING_REPOSITORIES);
            }
        }
        doScanRepository(targetRepositoryId, false);
    } catch (MetadataRepositoryException e) {
        throw new ArchivaRestServiceException(e.getMessage(), e);
    } catch (RepositoryAdminException 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) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Aggregations

MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)65 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)24 RepositoryException (javax.jcr.RepositoryException)22 Node (javax.jcr.Node)21 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)19 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)18 Path (java.nio.file.Path)15 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)13 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)10 HashMap (java.util.HashMap)8 RepositoryException (org.apache.archiva.repository.RepositoryException)8 Map (java.util.Map)6 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)6 MetadataFacet (org.apache.archiva.metadata.model.MetadataFacet)6 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)6 Date (java.util.Date)5 Query (javax.jcr.query.Query)5 QueryResult (javax.jcr.query.QueryResult)5 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)5