use of org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException in project archiva by apache.
the class DefaultSecurityConfigurationService method getConfiguration.
@Override
public SecurityConfiguration getConfiguration() throws ArchivaRestServiceException {
try {
RedbackRuntimeConfiguration redbackRuntimeConfiguration = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration();
log.debug("getRedbackRuntimeConfiguration -> {}", redbackRuntimeConfiguration);
return SecurityConfiguration.ofRedbackConfiguration(redbackRuntimeConfiguration);
} catch (RepositoryAdminException e) {
throw new ArchivaRestServiceException(ErrorMessage.of(REPOSITORY_ADMIN_ERROR));
}
}
use of org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException in project archiva by apache.
the class DefaultMavenManagedRepositoryService method getManagedRepositories.
@Override
public PagedResult<MavenManagedRepository> getManagedRepositories(final String searchTerm, final Integer offset, final Integer limit, final List<String> orderBy, final String order) throws ArchivaRestServiceException {
try {
Collection<ManagedRepository> repos = repositoryRegistry.getManagedRepositories();
final Predicate<ManagedRepository> queryFilter = QUERY_HELPER.getQueryFilter(searchTerm).and(r -> r.getType() == RepositoryType.MAVEN);
final Comparator<ManagedRepository> comparator = QUERY_HELPER.getComparator(orderBy, order);
int totalCount = Math.toIntExact(repos.stream().filter(queryFilter).count());
return PagedResult.of(totalCount, offset, limit, repos.stream().filter(queryFilter).sorted(comparator).map(mapper::reverseMap).skip(offset).limit(limit).collect(Collectors.toList()));
} catch (ArithmeticException e) {
log.error("Invalid number of repositories detected.");
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.INVALID_RESULT_SET_ERROR));
}
}
use of org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException in project archiva by apache.
the class DefaultMavenManagedRepositoryService method addManagedRepository.
@Override
public MavenManagedRepository addManagedRepository(MavenManagedRepository managedRepository) throws ArchivaRestServiceException {
final String repoId = managedRepository.getId();
if (StringUtils.isEmpty(repoId)) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_INVALID_ID, repoId), 422);
}
Repository repo = repositoryRegistry.getRepository(repoId);
if (repo != null) {
httpServletResponse.setHeader("Location", uriInfo.getAbsolutePathBuilder().path(repoId).build().toString());
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_ID_EXISTS, repoId), 303);
}
try {
repositoryRegistry.putRepository(mapper.map(managedRepository));
httpServletResponse.setStatus(201);
return mapper.reverseMap(repositoryRegistry.getManagedRepository(repoId));
} catch (RepositoryException e) {
log.error("Could not create repository: {}", e.getMessage(), e);
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_ADD_FAILED, repoId));
}
}
use of org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException in project archiva by apache.
the class ArchivaRestServiceExceptionMapper method toResponse.
@Override
public Response toResponse(final ArchivaRestServiceException e) {
ArchivaRestError restError = new ArchivaRestError(e);
Response.ResponseBuilder responseBuilder = Response.status(e.getHttpErrorCode()).entity(restError);
if (e.getMessage() != null) {
responseBuilder = responseBuilder.status(new Response.StatusType() {
public int getStatusCode() {
return e.getHttpErrorCode();
}
public Response.Status.Family getFamily() {
return Response.Status.Family.familyOf(e.getHttpErrorCode());
}
public String getReasonPhrase() {
return e.getMessage();
}
});
}
return responseBuilder.build();
}
Aggregations