]> source.dussan.org Git - archiva.git/commitdiff
Fixing totalCount number for properties
authorMartin Stockhammer <martin_s@apache.org>
Mon, 11 Jan 2021 22:03:23 +0000 (23:03 +0100)
committerMartin Stockhammer <martin_s@apache.org>
Mon, 11 Jan 2021 22:03:23 +0000 (23:03 +0100)
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/ErrorKeys.java

index 3ecda4a0642042f095eee3a15fcffaa24722f49d..f059613c0e302281120734f3fd308f854dd11d48 100644 (file)
@@ -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 )
         {
index 22b8543d48baa0b1cd44bd3f13d4b05af7fd38a1..83fec93619cd5aa6ff0608c1e617d2741f23897b 100644 (file)
@@ -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";