use of org.apache.archiva.metadata.repository.MetadataRepository in project archiva by apache.
the class DefaultBrowseService method addMetadata.
@Override
public Boolean addMetadata(String groupId, String artifactId, String version, String key, String value, String repositoryId) throws ArchivaRestServiceException {
ProjectVersionMetadata projectVersionMetadata = getProjectMetadata(groupId, artifactId, version, repositoryId);
if (projectVersionMetadata == null) {
return Boolean.FALSE;
}
Map<String, String> properties = new HashMap<>();
MetadataFacet metadataFacet = projectVersionMetadata.getFacet(GenericMetadataFacet.FACET_ID);
if (metadataFacet != null && metadataFacet.toProperties() != null) {
properties.putAll(metadataFacet.toProperties());
} else {
metadataFacet = new GenericMetadataFacet();
}
properties.put(key, value);
metadataFacet.fromProperties(properties);
projectVersionMetadata.addFacet(metadataFacet);
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.MetadataRepository 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.MetadataRepository 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.MetadataRepository 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();
}
}
use of org.apache.archiva.metadata.repository.MetadataRepository in project archiva by apache.
the class DefaultMergeRepositoriesService method mergeBySkippingConflicts.
public void mergeBySkippingConflicts(String sourceRepositoryId, String targetRepositoryId) throws RepositoryMergerException, ArchivaRestServiceException {
RepositorySession repositorySession = repositorySessionFactory.createSession();
try {
List<ArtifactMetadata> conflictSourceArtifacts = repositoryMerger.getConflictingArtifacts(repositorySession.getRepository(), sourceRepositoryId, targetRepositoryId);
MetadataRepository metadataRepository = repositorySession.getRepository();
List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts(sourceRepositoryId);
sourceArtifacts.removeAll(conflictSourceArtifacts);
ManagedRepository repository = managedRepositoryAdmin.getManagedRepository(targetRepositoryId);
if (repository.isReleases() && !repository.isSnapshots()) {
mergeWithOutSnapshots(metadataRepository, sourceArtifacts, sourceRepositoryId, targetRepositoryId);
} else {
Filter<ArtifactMetadata> artifactsWithOutConflicts = new IncludesFilter<ArtifactMetadata>(sourceArtifacts);
repositoryMerger.merge(metadataRepository, sourceRepositoryId, targetRepositoryId, artifactsWithOutConflicts);
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