mirror of https://github.com/apache/archiva.git
more cleanup and fix a TODO :-)
This commit is contained in:
parent
2c09abccbc
commit
511858d4ab
|
@ -22,6 +22,7 @@ package org.apache.archiva.rest.services;
|
|||
import org.apache.archiva.admin.model.AuditInformation;
|
||||
import org.apache.archiva.admin.model.RepositoryAdminException;
|
||||
import org.apache.archiva.admin.model.admin.ArchivaAdministration;
|
||||
import org.apache.archiva.admin.model.beans.ProxyConnector;
|
||||
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
|
||||
import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin;
|
||||
import org.apache.archiva.audit.AuditEvent;
|
||||
|
@ -244,7 +245,27 @@ public abstract class AbstractRestService
|
|||
// we must replace it with a valid managed one available for the user.
|
||||
if ( StringUtils.isEmpty( repositoryId ) )
|
||||
{
|
||||
sb.append( '/' ).append( artifact.getContext() );
|
||||
List<String> userRepos = userRepositories.getObservableRepositoryIds( getPrincipal() );
|
||||
// is it a good one? if yes nothing to
|
||||
// if not search the repo who is proxy for this remote
|
||||
if ( !userRepos.contains( artifact.getContext() ) )
|
||||
{
|
||||
for ( Map.Entry<String, List<ProxyConnector>> entry : proxyConnectorAdmin.getProxyConnectorAsMap().entrySet() )
|
||||
{
|
||||
for ( ProxyConnector proxyConnector : entry.getValue() )
|
||||
{
|
||||
if ( StringUtils.equals( "remote-" + proxyConnector.getTargetRepoId(),
|
||||
artifact.getContext() ) //
|
||||
&& userRepos.contains( entry.getKey() ) )
|
||||
{
|
||||
sb.append( '/' ).append( entry.getKey() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -279,7 +300,7 @@ public abstract class AbstractRestService
|
|||
|
||||
return sb.toString();
|
||||
}
|
||||
catch ( RepositoryAdminException e )
|
||||
catch ( Exception e )
|
||||
{
|
||||
throw new ArchivaRestServiceException( e.getMessage(),
|
||||
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
|
||||
|
@ -301,7 +322,7 @@ public abstract class AbstractRestService
|
|||
new ArtifactBuilder().forArtifactMetadata( artifact ).withManagedRepositoryContent(
|
||||
repositoryContentFactory.getManagedRepositoryContent( repositoryId ) );
|
||||
Artifact art = builder.build();
|
||||
art.setUrl( getArtifactUrl( art ) );
|
||||
art.setUrl( getArtifactUrl( art, repositoryId ) );
|
||||
artifacts.add( art );
|
||||
}
|
||||
return artifacts;
|
||||
|
|
|
@ -19,7 +19,6 @@ package org.apache.archiva.rest.services;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.archiva.admin.model.beans.ProxyConnector;
|
||||
import org.apache.archiva.indexer.search.RepositorySearch;
|
||||
import org.apache.archiva.indexer.search.RepositorySearchException;
|
||||
import org.apache.archiva.indexer.search.SearchFields;
|
||||
|
@ -44,7 +43,6 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Olivier Lamy
|
||||
|
@ -369,40 +367,9 @@ public class DefaultSearchService
|
|||
} ).build();
|
||||
}
|
||||
|
||||
String artifactUrl = null;
|
||||
|
||||
Artifact artifact = artifacts.get( 0 );
|
||||
|
||||
// we need to configure correctly the repositoryId
|
||||
if ( StringUtils.isEmpty( repositoryId ) )
|
||||
{
|
||||
// is it a good one? if yes nothing to
|
||||
// if not search the repo who is proxy for this remote
|
||||
if ( !userRepos.contains( artifact.getContext() ) )
|
||||
{
|
||||
for ( Map.Entry<String, List<ProxyConnector>> entry : proxyConnectorAdmin.getProxyConnectorAsMap().entrySet() )
|
||||
{
|
||||
for ( ProxyConnector proxyConnector : entry.getValue() )
|
||||
{
|
||||
if ( StringUtils.equals( "remote-" + proxyConnector.getTargetRepoId(),
|
||||
artifact.getContext() ) //
|
||||
&& userRepos.contains( entry.getKey() ) )
|
||||
{
|
||||
return Response.temporaryRedirect(
|
||||
new URI( getArtifactUrl( artifact, entry.getKey() ) ) ).build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
artifactUrl = getArtifactUrl( artifact, repositoryId );
|
||||
}
|
||||
|
||||
return Response.temporaryRedirect( new URI( artifactUrl ) ).build();
|
||||
return Response.temporaryRedirect( new URI( artifact.getUrl() ) ).build();
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue