diff options
author | Martin Stockhammer <martin_s@apache.org> | 2021-01-11 23:03:23 +0100 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2021-01-11 23:03:23 +0100 |
commit | 27c81c6abe6f94ce931a14a50e5bb28c9297fdda (patch) | |
tree | 86abd800d6122d27d25fea378aec7a71fcad358a /archiva-modules/archiva-web/archiva-rest/archiva-rest-services | |
parent | cc1c52b3d49dccd52a79779601c6639916d86339 (diff) | |
download | archiva-27c81c6abe6f94ce931a14a50e5bb28c9297fdda.tar.gz archiva-27c81c6abe6f94ce931a14a50e5bb28c9297fdda.zip |
Fixing totalCount number for properties
Diffstat (limited to 'archiva-modules/archiva-web/archiva-rest/archiva-rest-services')
2 files changed, 9 insertions, 1 deletions
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<PropertyEntry> filter = PROP_QUERY_HELPER.getQueryFilter( searchTerm ); Comparator<PropertyEntry> comparator = PROP_QUERY_HELPER.getComparator( orderBy, ascending ); Map<String, String> 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<PropertyEntry> 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"; |