/**
* ConsumerProcessFileClosure
*
- *
*/
public class ConsumerProcessFileClosure
implements Closure
/**
* DataRefreshTask - task for discovering changes in the repository
* and updating all associated data.
- *
- *
*/
public class RepositoryTask
implements Task
private boolean scanAll;
+ public RepositoryTask()
+ {
+ // no op
+ }
+
+ public RepositoryTask( String repositoryId )
+ {
+ this.repositoryId = repositoryId;
+ }
+
+ public RepositoryTask( String repositoryId, boolean scanAll )
+ {
+ this.repositoryId = repositoryId;
+ this.scanAll = scanAll;
+ }
+
public boolean isScanAll()
{
return scanAll;
--- /dev/null
+package org.apache.archiva.rest.api.model;
+
+/*
+ * 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 java.io.Serializable;
+import java.util.List;
+
+/**
+ * @since 2.2.0
+ */
+public class ChecksumSearch
+ implements Serializable
+{
+ private List<String> repositories;
+
+ private String checksum;
+
+ public ChecksumSearch()
+ {
+ // nope
+ }
+
+ public ChecksumSearch( List<String> repositories, String checksum )
+ {
+ this.repositories = repositories;
+ this.checksum = checksum;
+ }
+
+ public List<String> getRepositories()
+ {
+ return repositories;
+ }
+
+ public void setRepositories( List<String> repositories )
+ {
+ this.repositories = repositories;
+ }
+
+ public String getChecksum()
+ {
+ return checksum;
+ }
+
+ public void setChecksum( String checksum )
+ {
+ this.checksum = checksum;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "ChecksumSearch{" +
+ "repositories=" + repositories +
+ ", checksum='" + checksum + '\'' +
+ '}';
+ }
+}
import org.apache.archiva.maven2.model.Artifact;
import org.apache.archiva.redback.authorization.RedbackAuthorization;
+import org.apache.archiva.rest.api.model.ChecksumSearch;
import org.apache.archiva.rest.api.model.GroupIdList;
import org.apache.archiva.rest.api.model.SearchRequest;
import org.apache.archiva.rest.api.model.StringList;
@GET
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@RedbackAuthorization( noPermission = true, noRestriction = true )
- List<Artifact> getArtifactVersions( @QueryParam( "groupId" ) String groupId,
- @QueryParam( "artifactId" ) String artifactId,
+ List<Artifact> getArtifactVersions( @QueryParam( "groupId" ) String groupId, //
+ @QueryParam( "artifactId" ) String artifactId, //
@QueryParam( "packaging" ) String packaging )
throws ArchivaRestServiceException;
@QueryParam( "artifactId" ) String artifactId,
@QueryParam( "version" ) String version )
throws ArchivaRestServiceException;
+ */
- @Path( "getArtifactByChecksum" )
@GET
- @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
+ @Path( "/artifact" )
+ @Produces( "text/html" )
@RedbackAuthorization( noPermission = true, noRestriction = true )
- List<Artifact> getArtifactByChecksum( @QueryParam( "checksum" ) String checksum )
+ Response redirectToArtifactFile( @QueryParam( "r" ) String repositoryId, //
+ @QueryParam( "g" ) String groupId, //
+ @QueryParam( "a" ) String artifactId, //
+ @QueryParam( "v" ) String version, //
+ @QueryParam( "p" ) String packaging, //
+ @QueryParam( "c" ) String classifier )
throws ArchivaRestServiceException;
- */
- @GET
- @Path( "/artifact" )
- @Produces( "text/html" )
+
+ /**
+ * If searchRequest contains repositories, the search will be done only on those repositories.
+ * <b>if no repositories, the search will be apply on all repositories the current user has karma</b>
+ */
+ @Path( "artifactsByChecksum" )
+ @POST
+ @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@RedbackAuthorization( noPermission = true, noRestriction = true )
- Response redirectToArtifactFile( @QueryParam( "r" ) String repositoryId, @QueryParam( "g" ) String groupId,
- @QueryParam( "a" ) String artifactId, @QueryParam( "v" ) String version,
- @QueryParam( "p" ) String packaging, @QueryParam( "c" ) String classifier )
+ List<Artifact> getArtifactByChecksum( ChecksumSearch checksumSearch )
throws ArchivaRestServiceException;
+
}
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
import org.apache.archiva.rest.services.utils.ArtifactBuilder;
import org.apache.archiva.scheduler.repository.DefaultRepositoryArchivaTaskScheduler;
+import org.apache.archiva.scheduler.repository.model.RepositoryArchivaTaskScheduler;
import org.apache.archiva.scheduler.repository.model.RepositoryTask;
import org.apache.archiva.security.AccessDeniedException;
import org.apache.archiva.security.ArchivaSecurityException;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@Inject
@Named(value = "archivaTaskScheduler#repository")
- protected DefaultRepositoryArchivaTaskScheduler repositoryTaskScheduler;
+ protected RepositoryArchivaTaskScheduler repositoryTaskScheduler;
@Inject
}
}
- protected List<Artifact> buildArtifacts( List<ArtifactMetadata> artifactMetadatas, String repositoryId )
+ protected List<Artifact> buildArtifacts( Collection<ArtifactMetadata> artifactMetadatas, String repositoryId )
throws ArchivaRestServiceException
{
try
task.setOnlyUpdate( !fullScan );
archivaIndexingTaskExecutor.executeTask( task );
+
+ scheduler.queueTask( new RepositoryTask( repositoryId, fullScan ) );
+
return Boolean.TRUE;
}
catch ( Exception e )
import org.apache.archiva.indexer.search.SearchResultLimits;
import org.apache.archiva.indexer.search.SearchResults;
import org.apache.archiva.maven2.model.Artifact;
-import org.apache.archiva.rest.api.model.Dependency;
+import org.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.archiva.metadata.repository.MetadataRepositoryException;
+import org.apache.archiva.metadata.repository.RepositorySession;
+import org.apache.archiva.metadata.repository.RepositorySessionFactory;
+import org.apache.archiva.rest.api.model.ChecksumSearch;
import org.apache.archiva.rest.api.model.GroupIdList;
import org.apache.archiva.rest.api.model.SearchRequest;
import org.apache.archiva.rest.api.model.StringList;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import java.util.TreeMap;
/**
@Inject
private RepositorySearch repositorySearch;
+ @Inject
+ private RepositorySessionFactory repositorySessionFactory;
+
@Override
public List<Artifact> quickSearch( String queryString )
throws ArchivaRestServiceException
}
- public List<Dependency> getDependencies( String groupId, String artifactId, String version )
- throws ArchivaRestServiceException
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
- public List<Artifact> getArtifactByChecksum( String checksum )
+ public List<Artifact> getArtifactByChecksum( ChecksumSearch checksumSearch )
throws ArchivaRestServiceException
{
- return null; //To change body of implemented methods use File | Settings | File Templates.
+
+ // if no repos set we use ones available for the user
+ if ( checksumSearch.getRepositories() == null || checksumSearch.getRepositories().isEmpty() )
+ {
+ checksumSearch.setRepositories( getObservableRepos() );
+ }
+
+ RepositorySession repositorySession = repositorySessionFactory.createSession();
+
+ MetadataRepository metadataRepository = repositorySession.getRepository();
+
+ Set<Artifact> artifactSet = new HashSet<>();
+
+ try
+ {
+ for ( String repoId : checksumSearch.getRepositories() )
+ {
+ Collection<ArtifactMetadata> artifactMetadatas =
+ metadataRepository.getArtifactsByChecksum( repoId, checksumSearch.getChecksum() );
+ artifactSet.addAll( buildArtifacts( artifactMetadatas, repoId ) );
+ }
+
+ return new ArrayList<>( artifactSet );
+
+ }
+ catch ( MetadataRepositoryException e )
+ {
+ log.error( e.getMessage(), e );
+ throw new ArchivaRestServiceException( e.getMessage(), e );
+ }
+ finally
+ {
+ repositorySession.closeQuietly();
+ }
+
+
}
@Override
}
}
+
//-------------------------------------
// internal
//-------------------------------------
import org.apache.archiva.admin.model.beans.UiConfiguration;
import org.apache.archiva.maven2.model.Artifact;
+import org.apache.archiva.rest.api.model.ChecksumSearch;
import org.apache.archiva.rest.api.model.SearchRequest;
import org.apache.archiva.rest.api.services.SearchService;
import org.assertj.core.api.Assertions;
assertNotNull( artifacts );
assertTrue(
" not 1 results for Bundle Symbolic Name org.apache.karaf.features.command but " + artifacts.size() + ":"
- + artifacts, artifacts.size() == 1
- );
+ + artifacts, artifacts.size() == 1 );
}
@Test
@Test
/**
* ensure we don't return response for an unknown repo
- */
- public void searchWithSearchUnknwownRepoId()
+ */ public void searchWithSearchUnknwownRepoId()
throws Exception
{
SearchService searchService = getSearchService( authorizationHeader );
@Test
/**
* ensure we revert to all observable repos in case of no repo in the request
- */
- public void searchWithSearchNoRepos()
+ */ public void searchWithSearchNoRepos()
throws Exception
{
SearchService searchService = getSearchService( authorizationHeader );
@Test
/**
* test we don't return 2 artifacts pom + zip one
- */
- public void getSearchArtifactsWithOnlyClassifier()
+ */ public void getSearchArtifactsWithOnlyClassifier()
throws Exception
{
// force guest user creation if not exists
assertEquals( 1, artifacts.size() );
}
+ /**
+ * sha1 commons-logging 1.1 ba24d5de831911b684c92cd289ed5ff826271824
+ */
+ @Test
+ public void search_with_sha1()
+ throws Exception
+ {
+ SearchService searchService = getSearchService( authorizationHeader );
+
+ List<Artifact> artifacts = searchService.getArtifactByChecksum(
+ new ChecksumSearch( null, "ba24d5de831911b684c92cd289ed5ff826271824" ) );
+
+ Assertions.assertThat( artifacts ).isNotNull().isNotEmpty().hasSize( 1 );
+
+ }
+
+
+ /**
+ * md5 commons-logging 1.1 6b62417e77b000a87de66ee3935edbf5
+ */
+ @Test
+ public void search_with_md5()
+ throws Exception
+ {
+ SearchService searchService = getSearchService( authorizationHeader );
+
+ List<Artifact> artifacts = searchService.getArtifactByChecksum(
+ new ChecksumSearch( null, "6b62417e77b000a87de66ee3935edbf5" ) );
+
+ Assertions.assertThat( artifacts ).isNotNull().isNotEmpty().hasSize( 1 );
+
+ }
+
@Before
public void createRepo()
throws Exception