--- /dev/null
+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.Constraint;
+
+/**
+ * Constraint for retrieving artifacts whose sha1 or md5 checksum matches the
+ * specified value.
+ *
+ * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ */
+public class ArtifactsByChecksumConstraint
+ extends AbstractDeclarativeConstraint
+ implements Constraint
+{
+ private String whereClause;
+
+ public static final String SHA1_CONDITION = "SHA1";
+
+ public static final String MD5_CONDITION = "MD5";
+
+ public ArtifactsByChecksumConstraint( String desiredChecksum, String condition )
+ {
+ 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()
+ {
+ return "groupId";
+ }
+
+ public String getWhereCondition()
+ {
+ return whereClause;
+ }
+}
+++ /dev/null
-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.Constraint;
-
-/**
- * ArtifactsBySha1ChecksumConstraint
- *
- * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @version $Id$
- */
-public class ArtifactsBySha1ChecksumConstraint
- extends AbstractDeclarativeConstraint
- implements Constraint
-{
- private String whereClause;
-
- public ArtifactsBySha1ChecksumConstraint( String desiredChecksum )
- {
- whereClause = "this.checksumSHA1 == desiredChecksum";
- declParams = new String[] { "String desiredChecksum" };
- params = new Object[] { desiredChecksum };
- }
-
- public String getSortColumn()
- {
- return "groupId";
- }
-
- public String getWhereCondition()
- {
- return whereClause;
- }
-}
--- /dev/null
+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;
+
+}
--- /dev/null
+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;
+ }
+
+}
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 );
--- /dev/null
+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 <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ * @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() );
+ }
+}
+++ /dev/null
-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 <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- * @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() );
- }
-
-}
--- /dev/null
+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() );
+ }
+
+}
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;
List results = null;
try
{
- results = dao.getArtifactDAO().queryArtifacts( new ArtifactsBySha1ChecksumConstraint( checksumSha1 ) );
+ results = dao.getArtifactDAO().queryArtifacts( new ArtifactsByChecksumConstraint(
+ checksumSha1, ArtifactsByChecksumConstraint.SHA1_CONDITION ) );
}
catch ( ObjectNotFoundException e )
{
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.
private static final String ARTIFACT = "artifact";
+ private List databaseResults;
+
+ /**
+ * @plexus.requirement role-hint="default"
+ */
+ private DatabaseSearch databaseSearch;
+
public String quickSearch()
throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException
{
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
{
return results;
}
+
+ public List getDatabaseResults()
+ {
+ return databaseResults;
+ }
}
<result name="results">/WEB-INF/jsp/results.jsp</result>
<result name="error">/WEB-INF/jsp/findArtifact.jsp</result>
<result name="artifact" type="redirect">
- /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()}
</result>
</action>
<h1>Results</h1>
<div id="resultsBox">
- <p>Hits: ${fn:length(results.hits)} of ${results.totalHits}</p>
-
<c:choose>
- <c:when test="${empty results.hits}">
- <p>No results</p>
+
+ <%-- search was made from the indices --%>
+ <c:when test="${databaseResults == null}">
+ <p>Hits: ${fn:length(results.hits)} of ${results.totalHits}</p>
+
+ <c:choose>
+ <c:when test="${empty results.hits}">
+ <p>No results</p>
+ </c:when>
+ <c:otherwise>
+ <c:forEach items="${results.hits}" var="record" varStatus="i">
+ <c:choose>
+ <c:when test="${not empty (record.groupId)}">
+ <h3 class="artifact-title">
+ <my:showArtifactTitle groupId="${record.groupId}" artifactId="${record.artifactId}"
+ version="${record.version}"/>
+ </h3>
+ <p>
+ <my:showArtifactLink groupId="${record.groupId}" artifactId="${record.artifactId}"
+ version="${record.version}" versions="${record.versions}"/>
+ </p>
+ </c:when>
+ <c:otherwise>
+ <p>
+ <c:url var="hiturl" value="/repository/${record.url}" />
+ <a href="${hiturl}">${record.urlFilename}</a>
+ </p>
+ </c:otherwise>
+ </c:choose>
+ </c:forEach>
+ </c:otherwise>
+ </c:choose>
</c:when>
+
+ <%-- search was made from the database (find artifact)--%>
<c:otherwise>
- <c:forEach items="${results.hits}" var="record" varStatus="i">
- <c:choose>
- <c:when test="${not empty (record.groupId)}">
- <h3 class="artifact-title">
- <my:showArtifactTitle groupId="${record.groupId}" artifactId="${record.artifactId}"
- version="${record.version}"/>
- </h3>
- <p>
- <my:showArtifactLink groupId="${record.groupId}" artifactId="${record.artifactId}"
- version="${record.version}" versions="${record.versions}"/>
- </p>
- </c:when>
- <c:otherwise>
- <p>
- <c:url var="hiturl" value="/repository/${record.url}" />
- <a href="${hiturl}">${record.urlFilename}</a>
- </p>
- </c:otherwise>
- </c:choose>
- </c:forEach>
+ <p>Hits: ${fn:length(databaseResults)}</p>
+
+ <c:choose>
+ <c:when test="${empty databaseResults}">
+ <p>No results</p>
+ </c:when>
+ <c:otherwise>
+ <c:forEach items="${databaseResults}" var="artifactModel" varStatus="i">
+ <c:choose>
+ <c:when test="${not empty (artifactModel.groupId)}">
+ <h3 class="artifact-title">
+ <my:showArtifactTitle groupId="${artifactModel.groupId}" artifactId="${artifactModel.artifactId}"
+ version="${artifactModel.version}"/>
+ </h3>
+ <p>
+ <my:showArtifactLink groupId="${artifactModel.groupId}" artifactId="${artifactModel.artifactId}"
+ version="${artifactModel.version}" versions="${artifactModel.versions}"/>
+ </p>
+ </c:when>
+ <c:otherwise>
+ <p>
+ <c:url var="hiturl" value="/repository/${artifactModel.repositoryId}" />
+ <a href="${hiturl}">${artifactModel.repositoryId}</a>
+ </p>
+ </c:otherwise>
+ </c:choose>
+ </c:forEach>
+ </c:otherwise>
+ </c:choose>
+
</c:otherwise>
</c:choose>
</div>