]> source.dussan.org Git - archiva.git/commitdiff
* Fixing ArtifactsByChecksumConstraint for null types.
authorJoakim Erdfelt <joakime@apache.org>
Fri, 29 Jun 2007 18:52:49 +0000 (18:52 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Fri, 29 Jun 2007 18:52:49 +0000 (18:52 +0000)
* Adding anonymous type constructor for ArtifactsByChecksumConstraint.
* Removing DatabaseSearch.  (We don't want a repeat of the mess that exists within continuum!)

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@551997 13f79535-47bb-0310-9956-ffa450edef68

archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsByChecksumConstraint.java
archiva-database/src/main/java/org/apache/maven/archiva/database/search/DatabaseSearch.java [deleted file]
archiva-database/src/main/java/org/apache/maven/archiva/database/search/DefaultDatabaseSearch.java [deleted file]
archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsByChecksumConstraintTest.java
archiva-database/src/test/java/org/apache/maven/archiva/database/search/DatabaseSearchTest.java [deleted file]
archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java

index 91bdf87a81500661c2715ff9a39ccf3b81cd7bb4..397ff44a9eabdb6a34cdc493c96dd191a722f0da 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.maven.archiva.database.constraints;
  * under the License.
  */
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.database.Constraint;
 
 /**
@@ -33,19 +34,42 @@ public class ArtifactsByChecksumConstraint
 {
     private String whereClause;
 
-    public static final String SHA1_CONDITION = "SHA1";
+    public static final String SHA1 = "SHA1";
 
-    public static final String MD5_CONDITION = "MD5";
+    public static final String MD5 = "MD5";
+    
+    /**
+     * Create constraint for checksum (without providing type)
+     * 
+     * @param desiredChecksum the checksum (either SHA1 or MD5)
+     */
+    public ArtifactsByChecksumConstraint( String desiredChecksum )
+    {
+        this( desiredChecksum, null );
+    }
 
-    public ArtifactsByChecksumConstraint( String desiredChecksum, String condition )
+    /**
+     * Create constraint for specific checksum.
+     * 
+     * @param desiredChecksum the checksum (either SHA1 or MD5)
+     * @param type the type of checksum (either {@link #SHA1} or {@link #MD5})
+     */
+    public ArtifactsByChecksumConstraint( String desiredChecksum, String type )
     {
-        if ( !condition.equals( SHA1_CONDITION ) && !condition.equals( MD5_CONDITION ) )
+        if( StringUtils.isEmpty( type ) )
+        {
+            // default for no specified type.
+            whereClause = "this.checksumSHA1 == desiredChecksum || this.checksumMD5 == desiredChecksum";
+        }
+        else if ( !type.equals( SHA1 ) && !type.equals( MD5 ) )
         {
+            // default for type that isn't recognized.
             whereClause = "this.checksumSHA1 == desiredChecksum || this.checksumMD5 == desiredChecksum";
         }
-        else if ( condition.equals( SHA1_CONDITION ) || condition.equals( MD5_CONDITION ) )
+        else if ( type.equals( SHA1 ) || type.equals( MD5 ) )
         {
-            whereClause = "this.checksum" + condition.trim() + " == desiredChecksum";
+            // specific type.
+            whereClause = "this.checksum" + type.trim() + " == desiredChecksum";
         }
 
         declParams = new String[]{ "String desiredChecksum" };
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/search/DatabaseSearch.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/search/DatabaseSearch.java
deleted file mode 100644 (file)
index b14d8be..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-package org.apache.maven.archiva.database.search;
-
-/*
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements.  See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership.  The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License.  You may obtain a copy of the License at
-*
-*  http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing,
-* software distributed under the License is distributed on an
-* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-* KIND, either express or implied.  See the License for the
-* specific language governing permissions and limitations
-* under the License.
-*/
-
-import org.apache.maven.archiva.database.ObjectNotFoundException;
-import org.apache.maven.archiva.database.ArchivaDatabaseException;
-
-import java.util.List;
-
-/**
- * Class for searching the database.
- *
- * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
- */
-public interface DatabaseSearch
-{
-
-    /**
-     * Get artifact(s) with the specified checksum
-     *
-     * @param checksum
-     * @return
-     */
-    public List searchArtifactsByChecksum( String checksum )
-        throws ObjectNotFoundException, ArchivaDatabaseException;
-
-}
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/search/DefaultDatabaseSearch.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/search/DefaultDatabaseSearch.java
deleted file mode 100644 (file)
index 06c1a15..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-package org.apache.maven.archiva.database.search;
-
-/*
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements.  See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership.  The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License.  You may obtain a copy of the License at
-*
-*  http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing,
-* software distributed under the License is distributed on an
-* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-* KIND, either express or implied.  See the License for the
-* specific language governing permissions and limitations
-* under the License.
-*/
-
-import org.apache.maven.archiva.database.ArchivaDAO;
-import org.apache.maven.archiva.database.Constraint;
-import org.apache.maven.archiva.database.ObjectNotFoundException;
-import org.apache.maven.archiva.database.ArchivaDatabaseException;
-import org.apache.maven.archiva.database.constraints.ArtifactsByChecksumConstraint;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
-
-import java.util.List;
-
-/**
- * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
- * @plexus.component role="org.apache.maven.archiva.database.search.DatabaseSearch" role-hint="default"
- */
-public class DefaultDatabaseSearch
-    extends AbstractLogEnabled
-    implements DatabaseSearch
-{
-    /**
-     * @plexus.requirement role-hint="jdo"
-     */
-    private ArchivaDAO dao;
-
-    public List searchArtifactsByChecksum( String checksum )
-        throws ObjectNotFoundException, ArchivaDatabaseException
-    {
-        Constraint constraint = new ArtifactsByChecksumConstraint( checksum.toLowerCase().trim(), "" );
-        List results = dao.getArtifactDAO().queryArtifacts( constraint );
-
-        if ( results != null )
-        {
-            getLogger().info( "Number of database hits : " + results.size() );
-        }
-
-        return results;
-    }
-
-}
index d7751b7e028587f40c372dd594f6663c64b9b6a4..d5004c5b3023cfb803a2a54689dffff2443f50c4 100644 (file)
@@ -105,11 +105,11 @@ public class ArtifactsByChecksumConstraintTest
         artifactDao.saveArtifact( artifact );
 
         assertConstraint( "Artifacts by SHA1 Checksum", 4,
-                          new ArtifactsByChecksumConstraint( SHA1_HASH1, ArtifactsByChecksumConstraint.SHA1_CONDITION ) );
+                          new ArtifactsByChecksumConstraint( SHA1_HASH1, ArtifactsByChecksumConstraint.SHA1 ) );
         assertConstraint( "Artifacts by SHA1 Checksum", 2,
-                          new ArtifactsByChecksumConstraint( SHA1_HASH2, ArtifactsByChecksumConstraint.SHA1_CONDITION ) );
+                          new ArtifactsByChecksumConstraint( SHA1_HASH2, ArtifactsByChecksumConstraint.SHA1 ) );
         assertConstraint( "Artifacts by SHA1 Checksum", 1,
-                          new ArtifactsByChecksumConstraint( SHA1_HASH3, ArtifactsByChecksumConstraint.SHA1_CONDITION ) );
+                          new ArtifactsByChecksumConstraint( SHA1_HASH3, ArtifactsByChecksumConstraint.SHA1 ) );
     }
 
     public void testConstraintMD5()
@@ -146,11 +146,11 @@ public class ArtifactsByChecksumConstraintTest
         artifactDao.saveArtifact( artifact );
 
         assertConstraint( "Artifacts by MD5 Checksum", 4,
-                          new ArtifactsByChecksumConstraint( MD5_HASH1, ArtifactsByChecksumConstraint.MD5_CONDITION ) );
+                          new ArtifactsByChecksumConstraint( MD5_HASH1, ArtifactsByChecksumConstraint.MD5 ) );
         assertConstraint( "Artifacts by MD5 Checksum", 2,
-                          new ArtifactsByChecksumConstraint( MD5_HASH2, ArtifactsByChecksumConstraint.MD5_CONDITION ) );
+                          new ArtifactsByChecksumConstraint( MD5_HASH2, ArtifactsByChecksumConstraint.MD5 ) );
         assertConstraint( "Artifacts by MD5 Checksum", 1,
-                          new ArtifactsByChecksumConstraint( MD5_HASH3, ArtifactsByChecksumConstraint.MD5_CONDITION ) );
+                          new ArtifactsByChecksumConstraint( MD5_HASH3, ArtifactsByChecksumConstraint.MD5 ) );
     }
 
     public void testConstraintOR()
@@ -186,9 +186,9 @@ public class ArtifactsByChecksumConstraintTest
         artifact.getModel().setChecksumMD5( MD5_HASH2 );
         artifactDao.saveArtifact( artifact );
 
-        assertConstraint( "Artifacts by MD5 Checksum", 4, new ArtifactsByChecksumConstraint( MD5_HASH1, "" ) );
-        assertConstraint( "Artifacts by MD5 Checksum", 2, new ArtifactsByChecksumConstraint( MD5_HASH2, "" ) );
-        assertConstraint( "Artifacts by MD5 Checksum", 1, new ArtifactsByChecksumConstraint( MD5_HASH3, "" ) );
+        assertConstraint( "Artifacts by MD5 Checksum", 4, new ArtifactsByChecksumConstraint( MD5_HASH1 ) );
+        assertConstraint( "Artifacts by MD5 Checksum", 2, new ArtifactsByChecksumConstraint( MD5_HASH2 ) );
+        assertConstraint( "Artifacts by MD5 Checksum", 1, new ArtifactsByChecksumConstraint( MD5_HASH3 ) );
     }
 
 
diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/search/DatabaseSearchTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/search/DatabaseSearchTest.java
deleted file mode 100644 (file)
index 8583950..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-package org.apache.maven.archiva.database.search;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
-import org.apache.maven.archiva.database.ArtifactDAO;
-import org.apache.maven.archiva.database.ArchivaDAO;
-import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
-import org.apache.maven.archiva.model.ArchivaArtifact;
-
-import java.util.Date;
-import java.util.List;
-
-/**
- * DatabaseSearchTest
- *
- * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
- * @version
- */
-public class DatabaseSearchTest
-    extends AbstractArchivaDatabaseTestCase
-{
-    private ArtifactDAO artifactDao;
-
-    private static final String MD5_HASH1 = "53e3b856aa1a3f3cb7fe0f7ac6163aaf";
-
-    private static final String SHA1_HASH1 = "232f01b24b1617c46a3d4b0ab3415bc9237dcdec";
-
-    private DatabaseSearch dbSearch;
-
-    protected void setUp()
-        throws Exception
-    {
-        super.setUp();
-        artifactDao = ( ( ArchivaDAO ) lookup( ArchivaDAO.ROLE, "jdo" ) ).getArtifactDAO();
-        dbSearch = (DatabaseSearch) lookup( DatabaseSearch.class.getName() );
-    }
-    
-    public ArchivaArtifact createArtifact( String groupId, String artifactId, String version )
-    {
-        ArchivaArtifact artifact = artifactDao.createArtifact( groupId, artifactId, version, "", "jar" );
-        artifact.getModel().setLastModified( new Date() );
-        artifact.getModel().setRepositoryId( "testable_repo" );
-        return artifact;
-    }
-
-    public void testSearchByChecksum()
-        throws Exception
-    {
-        ArchivaArtifact artifact;
-
-        // Setup artifacts in fresh DB.
-        artifact = createArtifact( "org.apache.maven.test", "test-one", "1.2" );
-        artifact.getModel().setChecksumMD5( MD5_HASH1 );
-        artifactDao.saveArtifact( artifact );
-
-        artifact = createArtifact( "org.apache.maven.test.foo", "test-two", "1.0" );
-        artifact.getModel().setChecksumSHA1( SHA1_HASH1 );
-        artifactDao.saveArtifact( artifact );
-
-        List results = dbSearch.searchArtifactsByChecksum( MD5_HASH1 );
-        assertEquals( 1, results.size() );
-
-        results = dbSearch.searchArtifactsByChecksum( SHA1_HASH1 );
-        assertEquals( 1, results.size() );
-    }
-
-}
index 04fde62884f1f8d19347ed23a15efb0837dc0ee4..37ca5146f8c83ead7a5681af12283a3156d9ac40 100644 (file)
@@ -20,12 +20,14 @@ package org.apache.maven.archiva.web.action;
  */
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.maven.archiva.database.ArchivaDAO;
+import org.apache.maven.archiva.database.Constraint;
+import org.apache.maven.archiva.database.constraints.ArtifactsByChecksumConstraint;
 import org.apache.maven.archiva.indexer.RepositoryIndexException;
 import org.apache.maven.archiva.indexer.RepositoryIndexSearchException;
 import org.apache.maven.archiva.indexer.search.CrossRepositorySearch;
 import org.apache.maven.archiva.indexer.search.SearchResultLimits;
 import org.apache.maven.archiva.indexer.search.SearchResults;
-import org.apache.maven.archiva.database.search.DatabaseSearch;
 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
 
 import java.net.MalformedURLException;
@@ -44,6 +46,11 @@ public class SearchAction
      */
     private String q;
 
+    /**
+     * @plexus.requirement role-hint="jdo"
+     */
+    private ArchivaDAO dao;
+
     /**
      * The Search Results.
      */
@@ -60,11 +67,6 @@ public class SearchAction
 
     private List databaseResults;
 
-    /**
-     * @plexus.requirement role-hint="default"
-     */
-    private DatabaseSearch databaseSearch;
-
     public String quickSearch()
         throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException
     {
@@ -109,7 +111,8 @@ public class SearchAction
             return INPUT;
         }
 
-        databaseResults = databaseSearch.searchArtifactsByChecksum( q );
+        Constraint constraint = new ArtifactsByChecksumConstraint( q );
+        databaseResults = dao.getArtifactDAO().queryArtifacts( constraint );
 
         if ( databaseResults.isEmpty() )
         {
@@ -119,7 +122,7 @@ public class SearchAction
 
         if ( databaseResults.size() == 1 )
         {
-           // 1 hit? return it's information directly!            
+            // 1 hit? return it's information directly!            
             return ARTIFACT;
         }
         else