* under the License.
*/
+import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.database.Constraint;
/**
{
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" };
+++ /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;
- }
-
-}
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()
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()
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 ) );
}
+++ /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.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;
*/
private String q;
+ /**
+ * @plexus.requirement role-hint="jdo"
+ */
+ private ArchivaDAO dao;
+
/**
* The Search Results.
*/
private List databaseResults;
- /**
- * @plexus.requirement role-hint="default"
- */
- private DatabaseSearch databaseSearch;
-
public String quickSearch()
throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException
{
return INPUT;
}
- databaseResults = databaseSearch.searchArtifactsByChecksum( q );
+ Constraint constraint = new ArtifactsByChecksumConstraint( q );
+ databaseResults = dao.getArtifactDAO().queryArtifacts( constraint );
if ( databaseResults.isEmpty() )
{
if ( databaseResults.size() == 1 )
{
- // 1 hit? return it's information directly!
+ // 1 hit? return it's information directly!
return ARTIFACT;
}
else