mirror of https://github.com/apache/archiva.git
[MRM-416]
- Added DatabaseSearch class for querying from the database (This could be used for future database queries so there is only one entry point for all db queries) - Added ArtifactsByChecksumConstraint to be used for querying artifacts by checksum (either sha1, md5 or both) - Updated "artifact" result of findArtifact action in xwork.xml - Updated SearchAction to find an artifact (using checksums) in the database instead of in the indices - Updated results.jsp to accomodate when the results came from the database instead of the SearchResults that is for index searching - Deleted ArtifactsBySha1Constraint and its test, replaced by ArtifactsByChecksumConstraint - Created tests for the new classes added git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@549792 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3df7e0ac3f
commit
49ec5dcb1f
|
@ -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 <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
* @version $Id$
|
||||
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
|
||||
*/
|
||||
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()
|
|
@ -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 <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;
|
||||
|
||||
}
|
|
@ -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 <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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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 );
|
||||
|
|
|
@ -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 <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() );
|
||||
}
|
||||
}
|
|
@ -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 <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() );
|
||||
}
|
||||
|
||||
}
|
|
@ -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 <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() );
|
||||
}
|
||||
|
||||
}
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -175,7 +175,7 @@
|
|||
<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>
|
||||
|
||||
|
|
|
@ -40,33 +40,73 @@
|
|||
<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>
|
||||
|
|
Loading…
Reference in New Issue