use of org.apache.archiva.rest.api.services.ArchivaRestServiceException in project archiva by apache.
the class DefaultRedbackRuntimeConfigurationService method checkLdapConnection.
@Override
public Boolean checkLdapConnection(LdapConfiguration ldapConfiguration) throws ArchivaRestServiceException {
LdapConnection ldapConnection = null;
try {
LdapConnectionConfiguration ldapConnectionConfiguration = new LdapConnectionConfiguration(ldapConfiguration.getHostName(), ldapConfiguration.getPort(), ldapConfiguration.getBaseDn(), ldapConfiguration.getContextFactory(), ldapConfiguration.getBindDn(), ldapConfiguration.getPassword(), ldapConfiguration.getAuthenticationMethod(), toProperties(ldapConfiguration.getExtraProperties()));
ldapConnectionConfiguration.setSsl(ldapConfiguration.isSsl());
ldapConnection = ldapConnectionFactory.getConnection(ldapConnectionConfiguration);
ldapConnection.close();
// verify groups dn value too
ldapConnectionConfiguration = new LdapConnectionConfiguration(ldapConfiguration.getHostName(), ldapConfiguration.getPort(), ldapConfiguration.getBaseGroupsDn(), ldapConfiguration.getContextFactory(), ldapConfiguration.getBindDn(), ldapConfiguration.getPassword(), ldapConfiguration.getAuthenticationMethod(), toProperties(ldapConfiguration.getExtraProperties()));
ldapConnectionConfiguration.setSsl(ldapConfiguration.isSsl());
ldapConnection = ldapConnectionFactory.getConnection(ldapConnectionConfiguration);
} catch (InvalidNameException e) {
log.warn("fail to get ldapConnection: {}", e.getMessage(), e);
throw new ArchivaRestServiceException(e.getMessage(), e);
} catch (LdapException e) {
log.warn("fail to get ldapConnection: {}", e.getMessage(), e);
throw new ArchivaRestServiceException(e.getMessage(), e);
} finally {
if (ldapConnection != null) {
ldapConnection.close();
}
}
return Boolean.TRUE;
}
use of org.apache.archiva.rest.api.services.ArchivaRestServiceException 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.rest.api.services.ArchivaRestServiceException 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.rest.api.services.ArchivaRestServiceException 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.rest.api.services.ArchivaRestServiceException in project archiva by apache.
the class DefaultSearchService method quickSearchWithRepositories.
@Override
public List<Artifact> quickSearchWithRepositories(SearchRequest searchRequest) throws ArchivaRestServiceException {
String queryString = searchRequest.getQueryTerms();
if (StringUtils.isBlank(queryString)) {
return Collections.emptyList();
}
List<String> repositories = searchRequest.getRepositories();
if (repositories == null || repositories.isEmpty()) {
repositories = getObservableRepos();
}
SearchResultLimits limits = new SearchResultLimits(searchRequest.getPageSize(), searchRequest.getSelectedPage());
try {
SearchResults searchResults = repositorySearch.search(getPrincipal(), repositories, queryString, limits, Collections.<String>emptyList());
return getArtifacts(searchResults);
} catch (RepositorySearchException e) {
log.error(e.getMessage(), e);
throw new ArchivaRestServiceException(e.getMessage(), e);
}
}
Aggregations