Search in sources :

Example 21 with ArchivaRestServiceException

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));
    }
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 22 with ArchivaRestServiceException

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));
    }
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) MavenManagedRepository(org.apache.archiva.rest.api.v2.model.MavenManagedRepository) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException)

Example 23 with ArchivaRestServiceException

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));
    }
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) Repository(org.apache.archiva.repository.Repository) MavenManagedRepository(org.apache.archiva.rest.api.v2.model.MavenManagedRepository) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RepositoryException(org.apache.archiva.repository.RepositoryException)

Example 24 with ArchivaRestServiceException

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();
}
Also used : Response(javax.ws.rs.core.Response) ArchivaRestError(org.apache.archiva.rest.api.v2.svc.ArchivaRestError)

Aggregations

ArchivaRestServiceException (org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException)23 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)9 RedbackRuntimeConfiguration (org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration)8 RepositoryException (org.apache.archiva.repository.RepositoryException)6 Map (java.util.Map)4 PagedResult (org.apache.archiva.components.rest.model.PagedResult)4 AuthenticationException (javax.naming.AuthenticationException)3 AuthenticationNotSupportedException (javax.naming.AuthenticationNotSupportedException)3 CommunicationException (javax.naming.CommunicationException)3 InvalidNameException (javax.naming.InvalidNameException)3 NamingException (javax.naming.NamingException)3 NoPermissionException (javax.naming.NoPermissionException)3 ServiceUnavailableException (javax.naming.ServiceUnavailableException)3 Response (javax.ws.rs.core.Response)3 LdapConnection (org.apache.archiva.redback.common.ldap.connection.LdapConnection)3 LdapConnectionConfiguration (org.apache.archiva.redback.common.ldap.connection.LdapConnectionConfiguration)3 LdapException (org.apache.archiva.redback.common.ldap.connection.LdapException)3 EditableRepositoryGroup (org.apache.archiva.repository.EditableRepositoryGroup)3 LdapConfiguration (org.apache.archiva.rest.api.v2.model.LdapConfiguration)3 ArrayList (java.util.ArrayList)2