Search in sources :

Example 1 with INVALID_RESULT_SET_ERROR

use of org.apache.archiva.rest.api.v2.svc.ErrorKeys.INVALID_RESULT_SET_ERROR in project archiva by apache.

the class DefaultSecurityConfigurationService method getConfigurationProperties.

@Override
public PagedResult<PropertyEntry> getConfigurationProperties(String searchTerm, Integer offset, Integer limit, List<String> orderBy, String order) throws ArchivaRestServiceException {
    try {
        RedbackRuntimeConfiguration redbackRuntimeConfiguration = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration();
        log.debug("getRedbackRuntimeConfiguration -> {}", redbackRuntimeConfiguration);
        boolean ascending = PROP_QUERY_HELPER.isAscending(order);
        Predicate<PropertyEntry> filter = PROP_QUERY_HELPER.getQueryFilter(searchTerm);
        Comparator<PropertyEntry> comparator = PROP_QUERY_HELPER.getComparator(orderBy, ascending);
        Map<String, String> props = redbackRuntimeConfiguration.getConfigurationProperties();
        int totalCount = Math.toIntExact(props.entrySet().stream().map(entry -> new PropertyEntry(entry.getKey(), entry.getValue())).filter(filter).count());
        List<PropertyEntry> result = props.entrySet().stream().map(entry -> new PropertyEntry(entry.getKey(), entry.getValue())).filter(filter).sorted(comparator).skip(offset).limit(limit).collect(Collectors.toList());
        return new PagedResult<>(totalCount, offset, limit, result);
    } catch (ArithmeticException e) {
        log.error("The total count of the result properties is higher than max integer value!");
        throw new ArchivaRestServiceException(ErrorMessage.of(INVALID_RESULT_SET_ERROR));
    } catch (RepositoryAdminException e) {
        throw new ArchivaRestServiceException(ErrorMessage.of(REPOSITORY_ADMIN_ERROR));
    }
}
Also used : SecurityConfiguration(org.apache.archiva.rest.api.v2.model.SecurityConfiguration) LoggerFactory(org.slf4j.LoggerFactory) NamingException(javax.naming.NamingException) StringUtils(org.apache.commons.lang3.StringUtils) AuthenticationException(javax.naming.AuthenticationException) UserManager(org.apache.archiva.redback.users.UserManager) RBACManager(org.apache.archiva.redback.rbac.RBACManager) Map(java.util.Map) Authenticator(org.apache.archiva.redback.authentication.Authenticator) PasswordRule(org.apache.archiva.redback.policy.PasswordRule) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) QueryHelper(org.apache.archiva.components.rest.util.QueryHelper) Predicate(java.util.function.Predicate) Collection(java.util.Collection) INVALID_RESULT_SET_ERROR(org.apache.archiva.rest.api.v2.svc.ErrorKeys.INVALID_RESULT_SET_ERROR) Collectors(java.util.stream.Collectors) CacheConfiguration(org.apache.archiva.rest.api.v2.model.CacheConfiguration) BeanInformation(org.apache.archiva.rest.api.v2.model.BeanInformation) List(java.util.List) LdapConnectionConfiguration(org.apache.archiva.redback.common.ldap.connection.LdapConnectionConfiguration) REPOSITORY_ADMIN_ERROR(org.apache.archiva.rest.api.v2.svc.ErrorKeys.REPOSITORY_ADMIN_ERROR) Response(javax.ws.rs.core.Response) ServiceUnavailableException(javax.naming.ServiceUnavailableException) PostConstruct(javax.annotation.PostConstruct) RedbackRuntimeConfigurationAdmin(org.apache.archiva.admin.model.runtime.RedbackRuntimeConfigurationAdmin) NoPermissionException(javax.naming.NoPermissionException) ErrorKeys(org.apache.archiva.rest.api.v2.svc.ErrorKeys) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ResourceBundle(java.util.ResourceBundle) PropertyEntry(org.apache.archiva.components.rest.model.PropertyEntry) Service(org.springframework.stereotype.Service) SecurityConfigurationService(org.apache.archiva.rest.api.v2.svc.SecurityConfigurationService) AuthenticationNotSupportedException(javax.naming.AuthenticationNotSupportedException) Named(javax.inject.Named) LdapException(org.apache.archiva.redback.common.ldap.connection.LdapException) LdapConfiguration(org.apache.archiva.rest.api.v2.model.LdapConfiguration) LdapConnectionFactory(org.apache.archiva.redback.common.ldap.connection.LdapConnectionFactory) LdapUserMapper(org.apache.archiva.redback.common.ldap.user.LdapUserMapper) Logger(org.slf4j.Logger) Properties(java.util.Properties) RoleManager(org.apache.archiva.redback.role.RoleManager) ApplicationContext(org.springframework.context.ApplicationContext) LdapConnection(org.apache.archiva.redback.common.ldap.connection.LdapConnection) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) CookieSettings(org.apache.archiva.redback.policy.CookieSettings) ErrorMessage(org.apache.archiva.rest.api.v2.svc.ErrorMessage) InvalidNameException(javax.naming.InvalidNameException) CommunicationException(javax.naming.CommunicationException) PagedResult(org.apache.archiva.components.rest.model.PagedResult) Comparator(java.util.Comparator) Collections(java.util.Collections) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) PropertyEntry(org.apache.archiva.components.rest.model.PropertyEntry) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) PagedResult(org.apache.archiva.components.rest.model.PagedResult)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1 ResourceBundle (java.util.ResourceBundle)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 PostConstruct (javax.annotation.PostConstruct)1 Inject (javax.inject.Inject)1 Named (javax.inject.Named)1 AuthenticationException (javax.naming.AuthenticationException)1 AuthenticationNotSupportedException (javax.naming.AuthenticationNotSupportedException)1 CommunicationException (javax.naming.CommunicationException)1 InvalidNameException (javax.naming.InvalidNameException)1 NamingException (javax.naming.NamingException)1 NoPermissionException (javax.naming.NoPermissionException)1 ServiceUnavailableException (javax.naming.ServiceUnavailableException)1