From: Martin Stockhammer Date: Mon, 11 Jan 2021 22:03:23 +0000 (+0100) Subject: Fixing totalCount number for properties X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=27c81c6abe6f94ce931a14a50e5bb28c9297fdda;p=archiva.git Fixing totalCount number for properties --- diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java index 3ecda4a06..f059613c0 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java @@ -70,6 +70,7 @@ import java.util.ResourceBundle; import java.util.function.Predicate; import java.util.stream.Collectors; +import static org.apache.archiva.rest.services.v2.ErrorKeys.INVALID_RESULT_SET_ERROR; import static org.apache.archiva.rest.services.v2.ErrorKeys.REPOSITORY_ADMIN_ERROR; /** @@ -334,7 +335,9 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio Predicate filter = PROP_QUERY_HELPER.getQueryFilter( searchTerm ); Comparator comparator = PROP_QUERY_HELPER.getComparator( orderBy, ascending ); Map props = redbackRuntimeConfiguration.getConfigurationProperties( ); - int totalCount = props.size( ); + int totalCount = Math.toIntExact( props.entrySet( ).stream( ).map( + entry -> new PropertyEntry( entry.getKey( ), entry.getValue( ) ) + ).filter( filter ).count( ) ); List result = props.entrySet( ).stream( ).map( entry -> new PropertyEntry( entry.getKey( ), entry.getValue( ) ) ).filter( filter ) @@ -342,6 +345,9 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio .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 ) { diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/ErrorKeys.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/ErrorKeys.java index 22b8543d4..83fec9361 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/ErrorKeys.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/ErrorKeys.java @@ -21,6 +21,8 @@ package org.apache.archiva.rest.services.v2;/* */ public interface ErrorKeys { + + String INVALID_RESULT_SET_ERROR = "archiva.result_set.invalid"; String REPOSITORY_ADMIN_ERROR = "archiva.repositoryadmin.error"; String LDAP_CF_INIT_FAILED = "archiva.ldap.cf.init.failed"; String LDAP_USER_MAPPER_INIT_FAILED = "archiva.ldap.usermapper.init.failed";