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