This is an automated email from the ASF dual-hosted git repository.

martin_s pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/archiva.git

commit 27c81c6abe6f94ce931a14a50e5bb28c9297fdda
Author: Martin Stockhammer <[email protected]>
AuthorDate: Mon Jan 11 23:03:23 2021 +0100

    Fixing totalCount number for properties
---
 .../rest/services/v2/DefaultSecurityConfigurationService.java     | 8 +++++++-
 .../main/java/org/apache/archiva/rest/services/v2/ErrorKeys.java  | 2 ++
 2 files changed, 9 insertions(+), 1 deletion(-)

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 3ecda4a..f059613 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 22b8543..83fec93 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";

Reply via email to