From 8ffe658623cf9bfa41b45839986f1bcc81bfa7db Mon Sep 17 00:00:00 2001
From: Brett Porter <brett@apache.org>
Date: Tue, 21 Aug 2007 08:16:36 +0000
Subject: [PATCH] [MRM-449, 450] improvements to the group search reporting
 Submitted by: Teodoro Cue Jr.

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@568011 13f79535-47bb-0310-9956-ffa450edef68
---
 .../constraints/RepositoryProblemByGroupIdConstraint.java  | 4 ++--
 .../database/constraints/RepositoryProblemConstraint.java  | 4 ++--
 .../RepositoryProblemByGroupIdConstraintTest.java          | 3 +++
 .../constraints/RepositoryProblemConstraintTest.java       | 7 +++++++
 .../archiva/web/action/reports/GenerateReportAction.java   | 4 ++--
 .../archiva/web/action/reports/ShowReportsAction.java      | 4 +++-
 6 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByGroupIdConstraint.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByGroupIdConstraint.java
index 1a0971acb..6186b0e3c 100644
--- a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByGroupIdConstraint.java
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByGroupIdConstraint.java
@@ -32,9 +32,9 @@ public class RepositoryProblemByGroupIdConstraint
 
     private void createWhereClause( String desiredGroupId )
     {
-        whereClause = "groupId == desiredGroupId";
+        whereClause = "groupId.like(desiredGroupId)";
         declParams = new String[]{"String desiredGroupId"};
-        params = new Object[]{desiredGroupId};
+        params = new Object[]{desiredGroupId + "%"};
     }
 
     public RepositoryProblemByGroupIdConstraint( String desiredGroupId )
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemConstraint.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemConstraint.java
index 3c2c997ac..eaff8338b 100644
--- a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemConstraint.java
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemConstraint.java
@@ -32,9 +32,9 @@ public class RepositoryProblemConstraint
 
     private void createWhereClause( String desiredGroupId, String desiredRepositoryId )
     {
-        whereClause = "groupId == desiredGroupId && repositoryId == desiredRepositoryId";
+        whereClause = "groupId.like(desiredGroupId) && repositoryId == desiredRepositoryId";
         declParams = new String[]{"String desiredGroupId", "String desiredRepositoryId"};
-        params = new Object[]{desiredGroupId, desiredRepositoryId};
+        params = new Object[]{desiredGroupId + "%", desiredRepositoryId};
     }
 
     public RepositoryProblemConstraint( String desiredGroupId, String desiredRepositoryId )
diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByGroupIdConstraintTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByGroupIdConstraintTest.java
index 49d4713e0..cc8b3f42b 100644
--- a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByGroupIdConstraintTest.java
+++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByGroupIdConstraintTest.java
@@ -39,6 +39,8 @@ public class RepositoryProblemByGroupIdConstraintTest
 
     private static final String GROUP_ID_3 = "org.apache.maven.archiva.test.3";
 
+    private static final String GROUP_ID_PARTIAL = "org.apache.maven.archiva";
+
     private RepositoryProblemDAO repoProblemDao;
 
     protected void setUp()
@@ -81,6 +83,7 @@ public class RepositoryProblemByGroupIdConstraintTest
         assertConstraint( 1, new RepositoryProblemByGroupIdConstraint( GROUP_ID_1 ) );
         assertConstraint( 2, new RepositoryProblemByGroupIdConstraint( GROUP_ID_2 ) );
         assertConstraint( 3, new RepositoryProblemByGroupIdConstraint( GROUP_ID_3 ) );
+        assertConstraint( 6, new RepositoryProblemByGroupIdConstraint( GROUP_ID_PARTIAL ) );
     }
 
     private void assertConstraint( int expectedHits, Constraint constraint )
diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryProblemConstraintTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryProblemConstraintTest.java
index e0d77b31a..a593281ac 100644
--- a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryProblemConstraintTest.java
+++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryProblemConstraintTest.java
@@ -41,6 +41,8 @@ public class RepositoryProblemConstraintTest
 
     private static final String GROUP_ID_4 = "org.apache.maven.archiva.test.4";
 
+    private static final String GROUP_ID_PARTIAL = "org.apache.maven.archiva";
+
     private static final String REPO_ID_1 = "test-repo-1";
 
     private static final String REPO_ID_2 = "test-repo-2";
@@ -92,6 +94,7 @@ public class RepositoryProblemConstraintTest
         assertConstraint( 2, new RepositoryProblemConstraint( GROUP_ID_2, REPO_ID_1 ) );
         assertConstraint( 3, new RepositoryProblemConstraint( GROUP_ID_3, REPO_ID_1 ) );
         assertConstraint( 0, new RepositoryProblemConstraint( GROUP_ID_4, REPO_ID_1 ) );
+        assertConstraint( 6, new RepositoryProblemConstraint( GROUP_ID_PARTIAL, REPO_ID_1 ) );
     }
 
     public void testRepoIdConstraint()
@@ -110,6 +113,10 @@ public class RepositoryProblemConstraintTest
         assertConstraint( 2, new RepositoryProblemConstraint( GROUP_ID_1, REPO_ID_2 ) );
         assertConstraint( 3, new RepositoryProblemConstraint( GROUP_ID_1, REPO_ID_3 ) );
         assertConstraint( 0, new RepositoryProblemConstraint( GROUP_ID_1, REPO_ID_4 ) );
+        assertConstraint( 1, new RepositoryProblemConstraint( GROUP_ID_PARTIAL, REPO_ID_1 ) );
+        assertConstraint( 2, new RepositoryProblemConstraint( GROUP_ID_PARTIAL, REPO_ID_2 ) );
+        assertConstraint( 3, new RepositoryProblemConstraint( GROUP_ID_PARTIAL, REPO_ID_3 ) );
+        assertConstraint( 0, new RepositoryProblemConstraint( GROUP_ID_PARTIAL, REPO_ID_4 ) );
     }
 
     private void assertConstraint( int expectedHits, Constraint constraint )
diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java
index 17c84ada6..b836ddc91 100644
--- a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java
+++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java
@@ -154,7 +154,7 @@ public class GenerateReportAction
 
         if ( groupId != null && ( !groupId.equals( "" ) ) )
         {
-            if ( repositoryId != null && ( !repositoryId.equals( "" ) ) )
+            if ( repositoryId != null && ( !repositoryId.equals( "" ) && !repositoryId.equals( ShowReportsAction.ALL_REPOSITORIES ) ) )
             {
                 constraint = new RepositoryProblemConstraint( range, groupId, repositoryId );
             }
@@ -163,7 +163,7 @@ public class GenerateReportAction
                 constraint = new RepositoryProblemByGroupIdConstraint( range, groupId );
             }
         }
-        else if ( repositoryId != null && ( !repositoryId.equals( "" ) ) )
+        else if ( repositoryId != null && ( !repositoryId.equals( "" ) && !repositoryId.equals( ShowReportsAction.ALL_REPOSITORIES ) ) )
         {
             constraint = new RepositoryProblemByRepositoryIdConstraint( range, repositoryId );
         }
diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ShowReportsAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ShowReportsAction.java
index 004b4b159..2414d2f40 100644
--- a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ShowReportsAction.java
+++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ShowReportsAction.java
@@ -42,10 +42,12 @@ public class ShowReportsAction
 
     private Collection repositoryIds = new ArrayList();
 
+    public static final String ALL_REPOSITORIES = "All Repositories";
+
     public String execute()
         throws Exception
     {
-        repositoryIds.add( "" );
+        repositoryIds.add( ALL_REPOSITORIES );
         repositoryIds.addAll(
             dao.query( new UniqueFieldConstraint( RepositoryProblem.class.getName(), "repositoryId" ) ) );