diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsBySha1ChecksumConstraint.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsByChecksumConstraint.java similarity index 55% rename from archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsBySha1ChecksumConstraint.java rename to archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsByChecksumConstraint.java index e8ac7a539..91bdf87a8 100644 --- a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsBySha1ChecksumConstraint.java +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsByChecksumConstraint.java @@ -22,22 +22,34 @@ package org.apache.maven.archiva.database.constraints; import org.apache.maven.archiva.database.Constraint; /** - * ArtifactsBySha1ChecksumConstraint + * Constraint for retrieving artifacts whose sha1 or md5 checksum matches the + * specified value. * - * @author Joakim Erdfelt - * @version $Id$ + * @author Maria Odea Ching */ -public class ArtifactsBySha1ChecksumConstraint +public class ArtifactsByChecksumConstraint extends AbstractDeclarativeConstraint implements Constraint { private String whereClause; - public ArtifactsBySha1ChecksumConstraint( String desiredChecksum ) + public static final String SHA1_CONDITION = "SHA1"; + + public static final String MD5_CONDITION = "MD5"; + + public ArtifactsByChecksumConstraint( String desiredChecksum, String condition ) { - whereClause = "this.checksumSHA1 == desiredChecksum"; - declParams = new String[] { "String desiredChecksum" }; - params = new Object[] { desiredChecksum }; + if ( !condition.equals( SHA1_CONDITION ) && !condition.equals( MD5_CONDITION ) ) + { + whereClause = "this.checksumSHA1 == desiredChecksum || this.checksumMD5 == desiredChecksum"; + } + else if ( condition.equals( SHA1_CONDITION ) || condition.equals( MD5_CONDITION ) ) + { + whereClause = "this.checksum" + condition.trim() + " == desiredChecksum"; + } + + declParams = new String[]{ "String desiredChecksum" }; + params = new Object[]{ desiredChecksum }; } public String getSortColumn() 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 new file mode 100644 index 000000000..b14d8be60 --- /dev/null +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/search/DatabaseSearch.java @@ -0,0 +1,44 @@ +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 Maria Odea Ching + */ +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 new file mode 100644 index 000000000..06c1a1586 --- /dev/null +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/search/DefaultDatabaseSearch.java @@ -0,0 +1,58 @@ +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 Maria Odea Ching + * @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; + } + +} diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/AllTests.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/AllTests.java index c7fc265bc..e7050942f 100644 --- a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/AllTests.java +++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/AllTests.java @@ -36,7 +36,7 @@ public class AllTests TestSuite suite = new TestSuite( "Test for org.apache.maven.archiva.database.constraints" ); //$JUnit-BEGIN$ suite.addTestSuite( ArtifactsProcessedConstraintTest.class ); - suite.addTestSuite( ArtifactsBySha1ChecksumConstraintTest.class ); + suite.addTestSuite( ArtifactsByChecksumConstraintTest.class ); suite.addTestSuite( OlderArtifactsByAgeConstraintTest.class ); suite.addTestSuite( UniqueGroupIdConstraintTest.class ); suite.addTestSuite( OlderSnapshotArtifactsByAgeConstraintTest.class ); diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsByChecksumConstraintTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsByChecksumConstraintTest.java new file mode 100644 index 000000000..d7751b7e0 --- /dev/null +++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsByChecksumConstraintTest.java @@ -0,0 +1,202 @@ +package org.apache.maven.archiva.database.constraints; + +/* + * 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.model.ArchivaArtifact; + +import java.util.Date; +import java.util.List; + +/** + * ArtifactsByChecksumConstraintTest + * + * @author Joakim Erdfelt + * @author Maria Odea Ching + * @version + */ +public class ArtifactsByChecksumConstraintTest + extends AbstractArchivaDatabaseTestCase +{ + private static final String SHA1_HASH3 = "f3f653289f3217c65324830ab3415bc92feddefa"; + + private static final String SHA1_HASH2 = "a49810ad3eba8651677ab57cd40a0f76fdef9538"; + + private static final String SHA1_HASH1 = "232f01b24b1617c46a3d4b0ab3415bc9237dcdec"; + + private static final String MD5_HASH3 = "5440efd724c9a5246ddc148662a4f20a"; + + private static final String MD5_HASH2 = "4685525525d82dea68c6a6cd5a08f726"; + + private static final String MD5_HASH1 = "53e3b856aa1a3f3cb7fe0f7ac6163aaf"; + + private ArtifactDAO artifactDao; + + + protected void setUp() + throws Exception + { + super.setUp(); + + ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" ); + artifactDao = dao.getArtifactDAO(); + } + + public ArchivaArtifact createArtifact( String artifactId, String version ) + { + ArchivaArtifact artifact = + artifactDao.createArtifact( "org.apache.maven.archiva.test", artifactId, version, "", "jar" ); + artifact.getModel().setLastModified( new Date() ); + artifact.getModel().setRepositoryId( "testable_repo" ); + return artifact; + } + + public void testConstraintSHA1() + throws Exception + { + ArchivaArtifact artifact; + + // Setup artifacts in fresh DB. + artifact = createArtifact( "test-sha1-one", "1.0" ); + artifact.getModel().setChecksumSHA1( SHA1_HASH1 ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "test-sha1-one", "1.1" ); + artifact.getModel().setChecksumSHA1( SHA1_HASH1 ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "test-sha1-one", "1.2" ); + artifact.getModel().setChecksumSHA1( SHA1_HASH1 ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "test-sha1-two", "1.0" ); + artifact.getModel().setChecksumSHA1( SHA1_HASH1 ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "test-sha1-two", "2.0" ); + artifact.getModel().setChecksumSHA1( SHA1_HASH3 ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "test-sha1-two", "2.1" ); + artifact.getModel().setChecksumSHA1( SHA1_HASH2 ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "test-sha1-two", "3.0" ); + artifact.getModel().setChecksumSHA1( SHA1_HASH2 ); + artifactDao.saveArtifact( artifact ); + + assertConstraint( "Artifacts by SHA1 Checksum", 4, + new ArtifactsByChecksumConstraint( SHA1_HASH1, ArtifactsByChecksumConstraint.SHA1_CONDITION ) ); + assertConstraint( "Artifacts by SHA1 Checksum", 2, + new ArtifactsByChecksumConstraint( SHA1_HASH2, ArtifactsByChecksumConstraint.SHA1_CONDITION ) ); + assertConstraint( "Artifacts by SHA1 Checksum", 1, + new ArtifactsByChecksumConstraint( SHA1_HASH3, ArtifactsByChecksumConstraint.SHA1_CONDITION ) ); + } + + public void testConstraintMD5() + throws Exception + { + ArchivaArtifact artifact; + + artifact = createArtifact( "test-md5-one", "1.0" ); + artifact.getModel().setChecksumMD5( MD5_HASH1 ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "test-md5-one", "1.1" ); + artifact.getModel().setChecksumMD5( MD5_HASH1 ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "test-md5-one", "1.2" ); + artifact.getModel().setChecksumMD5( MD5_HASH1 ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "test-md5-two", "1.0" ); + artifact.getModel().setChecksumMD5( MD5_HASH1 ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "test-md5-two", "2.0" ); + artifact.getModel().setChecksumMD5( MD5_HASH3 ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "test-md5-two", "2.1" ); + artifact.getModel().setChecksumMD5( MD5_HASH2 ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "test-md5-two", "3.0" ); + artifact.getModel().setChecksumMD5( MD5_HASH2 ); + artifactDao.saveArtifact( artifact ); + + assertConstraint( "Artifacts by MD5 Checksum", 4, + new ArtifactsByChecksumConstraint( MD5_HASH1, ArtifactsByChecksumConstraint.MD5_CONDITION ) ); + assertConstraint( "Artifacts by MD5 Checksum", 2, + new ArtifactsByChecksumConstraint( MD5_HASH2, ArtifactsByChecksumConstraint.MD5_CONDITION ) ); + assertConstraint( "Artifacts by MD5 Checksum", 1, + new ArtifactsByChecksumConstraint( MD5_HASH3, ArtifactsByChecksumConstraint.MD5_CONDITION ) ); + } + + public void testConstraintOR() + throws Exception + { + ArchivaArtifact artifact; + + artifact = createArtifact( "test-one", "1.0" ); + artifact.getModel().setChecksumMD5( MD5_HASH1 ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "test-one", "1.1" ); + artifact.getModel().setChecksumMD5( MD5_HASH1 ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "test-one", "1.2" ); + artifact.getModel().setChecksumMD5( MD5_HASH1 ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "test-two", "1.0" ); + artifact.getModel().setChecksumMD5( MD5_HASH1 ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "test-two", "2.0" ); + artifact.getModel().setChecksumMD5( MD5_HASH3 ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "test-two", "2.1" ); + artifact.getModel().setChecksumMD5( MD5_HASH2 ); + artifactDao.saveArtifact( artifact ); + + artifact = createArtifact( "test-two", "3.0" ); + 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, "" ) ); + } + + + private void assertConstraint( String msg, int count, ArtifactsByChecksumConstraint constraint ) + throws Exception + { + List results = artifactDao.queryArtifacts( constraint ); + assertNotNull( msg + ": Not Null", results ); + assertEquals( msg + ": Results.size", count, results.size() ); + } +} diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsBySha1ChecksumConstraintTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsBySha1ChecksumConstraintTest.java deleted file mode 100644 index f958384ae..000000000 --- a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsBySha1ChecksumConstraintTest.java +++ /dev/null @@ -1,112 +0,0 @@ -package org.apache.maven.archiva.database.constraints; - -/* - * 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.ArchivaDAO; -import org.apache.maven.archiva.database.ArtifactDAO; -import org.apache.maven.archiva.model.ArchivaArtifact; - -import java.util.Date; -import java.util.List; - -/** - * ArtifactsBySha1ChecksumConstraintTest - * - * @author Joakim Erdfelt - * @version $Id$ - */ -public class ArtifactsBySha1ChecksumConstraintTest - extends AbstractArchivaDatabaseTestCase -{ - private static final String HASH3 = "f3f653289f3217c65324830ab3415bc92feddefa"; - - private static final String HASH2 = "a49810ad3eba8651677ab57cd40a0f76fdef9538"; - - private static final String HASH1 = "232f01b24b1617c46a3d4b0ab3415bc9237dcdec"; - - private ArtifactDAO artifactDao; - - protected void setUp() - throws Exception - { - super.setUp(); - - ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" ); - artifactDao = dao.getArtifactDAO(); - } - - public ArchivaArtifact createArtifact( String artifactId, String version ) - { - ArchivaArtifact artifact = artifactDao.createArtifact( "org.apache.maven.archiva.test", artifactId, version, - "", "jar" ); - artifact.getModel().setLastModified( new Date() ); - artifact.getModel().setRepositoryId( "testable_repo" ); - return artifact; - } - - public void testConstraint() - throws Exception - { - ArchivaArtifact artifact; - - // Setup artifacts in fresh DB. - artifact = createArtifact( "test-one", "1.0" ); - artifact.getModel().setChecksumSHA1( HASH1 ); - artifactDao.saveArtifact( artifact ); - - artifact = createArtifact( "test-one", "1.1" ); - artifact.getModel().setChecksumSHA1( HASH1 ); - artifactDao.saveArtifact( artifact ); - - artifact = createArtifact( "test-one", "1.2" ); - artifact.getModel().setChecksumSHA1( HASH1 ); - artifactDao.saveArtifact( artifact ); - - artifact = createArtifact( "test-two", "1.0" ); - artifact.getModel().setChecksumSHA1( HASH1 ); - artifactDao.saveArtifact( artifact ); - - artifact = createArtifact( "test-two", "2.0" ); - artifact.getModel().setChecksumSHA1( HASH3 ); - artifactDao.saveArtifact( artifact ); - - artifact = createArtifact( "test-two", "2.1" ); - artifact.getModel().setChecksumSHA1( HASH2 ); - artifactDao.saveArtifact( artifact ); - - artifact = createArtifact( "test-two", "3.0" ); - artifact.getModel().setChecksumSHA1( HASH2 ); - artifactDao.saveArtifact( artifact ); - - assertConstraint( "Artifacts by SHA1 Checksum", 4, new ArtifactsBySha1ChecksumConstraint( HASH1 ) ); - assertConstraint( "Artifacts by SHA1 Checksum", 2, new ArtifactsBySha1ChecksumConstraint( HASH2 ) ); - assertConstraint( "Artifacts by SHA1 Checksum", 1, new ArtifactsBySha1ChecksumConstraint( HASH3 ) ); - } - - private void assertConstraint( String msg, int count, ArtifactsBySha1ChecksumConstraint constraint ) - throws Exception - { - List results = artifactDao.queryArtifacts( constraint ); - assertNotNull( msg + ": Not Null", results ); - assertEquals( msg + ": Results.size", count, results.size() ); - } - -} 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 new file mode 100644 index 000000000..8583950a3 --- /dev/null +++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/search/DatabaseSearchTest.java @@ -0,0 +1,85 @@ +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 Maria Odea Ching + * @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() ); + } + +} diff --git a/archiva-reporting/archiva-artifact-reports/src/main/java/org/apache/maven/archiva/reporting/artifact/DuplicateArtifactsConsumer.java b/archiva-reporting/archiva-artifact-reports/src/main/java/org/apache/maven/archiva/reporting/artifact/DuplicateArtifactsConsumer.java index e6715094e..a10f9ceee 100644 --- a/archiva-reporting/archiva-artifact-reports/src/main/java/org/apache/maven/archiva/reporting/artifact/DuplicateArtifactsConsumer.java +++ b/archiva-reporting/archiva-artifact-reports/src/main/java/org/apache/maven/archiva/reporting/artifact/DuplicateArtifactsConsumer.java @@ -29,7 +29,7 @@ import org.apache.maven.archiva.consumers.ConsumerException; import org.apache.maven.archiva.database.ArchivaDAO; import org.apache.maven.archiva.database.ArchivaDatabaseException; import org.apache.maven.archiva.database.ObjectNotFoundException; -import org.apache.maven.archiva.database.constraints.ArtifactsBySha1ChecksumConstraint; +import org.apache.maven.archiva.database.constraints.ArtifactsByChecksumConstraint; import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.model.RepositoryProblem; import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout; @@ -127,7 +127,8 @@ public class DuplicateArtifactsConsumer List results = null; try { - results = dao.getArtifactDAO().queryArtifacts( new ArtifactsBySha1ChecksumConstraint( checksumSha1 ) ); + results = dao.getArtifactDAO().queryArtifacts( new ArtifactsByChecksumConstraint( + checksumSha1, ArtifactsByChecksumConstraint.SHA1_CONDITION ) ); } catch ( ObjectNotFoundException e ) { diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java index 63a7d202a..04fde6288 100644 --- a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java @@ -25,9 +25,11 @@ 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; +import java.util.List; /** * Search all indexed fields by the given criteria. @@ -56,6 +58,13 @@ public class SearchAction private static final String ARTIFACT = "artifact"; + private List databaseResults; + + /** + * @plexus.requirement role-hint="default" + */ + private DatabaseSearch databaseSearch; + public String quickSearch() throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException { @@ -100,19 +109,17 @@ public class SearchAction return INPUT; } - SearchResultLimits limits = new SearchResultLimits( 0 ); + databaseResults = databaseSearch.searchArtifactsByChecksum( q ); - results = crossRepoSearch.searchForChecksum( q, limits ); - - if ( results.isEmpty() ) + if ( databaseResults.isEmpty() ) { addActionError( "No results found" ); return INPUT; } - if ( results.getHits().size() == 1 ) + if ( databaseResults.size() == 1 ) { - // 1 hit? return it's information directly! + // 1 hit? return it's information directly! return ARTIFACT; } else @@ -140,4 +147,9 @@ public class SearchAction { return results; } + + public List getDatabaseResults() + { + return databaseResults; + } } diff --git a/archiva-web/archiva-webapp/src/main/resources/xwork.xml b/archiva-web/archiva-webapp/src/main/resources/xwork.xml index 8bd76ea2c..1cbd63a75 100644 --- a/archiva-web/archiva-webapp/src/main/resources/xwork.xml +++ b/archiva-web/archiva-webapp/src/main/resources/xwork.xml @@ -175,7 +175,7 @@ /WEB-INF/jsp/results.jsp /WEB-INF/jsp/findArtifact.jsp - /browse/${results.getHits().get(0).groupId}/${results.getHits().get(0).artifactId}/${results.getHits().get(0).version} + /browse/${databaseResults.get(0).getGroupId()}/${databaseResults.get(0).getArtifactId()}/${databaseResults.get(0).getVersion()} diff --git a/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/results.jsp b/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/results.jsp index 1da2664af..3367c299f 100644 --- a/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/results.jsp +++ b/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/results.jsp @@ -40,33 +40,73 @@

Results

-

Hits: ${fn:length(results.hits)} of ${results.totalHits}

- - -

No results

+ + <%-- search was made from the indices --%> + +

Hits: ${fn:length(results.hits)} of ${results.totalHits}

+ + + +

No results

+
+ + + + +

+ +

+

+ +

+
+ +

+ + ${record.urlFilename} +

+
+
+
+
+
+ + <%-- search was made from the database (find artifact)--%> - - - -

- -

-

- -

-
- -

- - ${record.urlFilename} -

-
-
-
+

Hits: ${fn:length(databaseResults)}

+ + + +

No results

+
+ + + + +

+ +

+

+ +

+
+ +

+ + ${artifactModel.repositoryId} +

+
+
+
+
+
+