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;
}
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;
}
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);
}
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);
}
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();
}
}
Aggregations