mirror of https://github.com/apache/archiva.git
[MRM-1490] REST services : configure legacy paths tru rest services
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1166884 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
146c63dd72
commit
5b7476e8d6
|
@ -18,6 +18,7 @@ package org.apache.archiva.admin.repository.admin;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.archiva.admin.AuditInformation;
|
||||
import org.apache.archiva.admin.repository.RepositoryAdminException;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -32,9 +33,9 @@ public interface ArchivaAdministration
|
|||
List<LegacyArtifactPath> getLegacyArtifactPaths()
|
||||
throws RepositoryAdminException;
|
||||
|
||||
void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
|
||||
void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath, AuditInformation auditInformation )
|
||||
throws RepositoryAdminException;
|
||||
|
||||
void deleteLegacyArtifactPath( String path )
|
||||
void deleteLegacyArtifactPath( String path, AuditInformation auditInformation )
|
||||
throws RepositoryAdminException;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.archiva.admin.repository.admin;
|
|||
*/
|
||||
|
||||
import net.sf.beanlib.provider.replicator.BeanReplicator;
|
||||
import org.apache.archiva.admin.AuditInformation;
|
||||
import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
|
||||
import org.apache.archiva.admin.repository.RepositoryAdminException;
|
||||
import org.apache.maven.archiva.configuration.Configuration;
|
||||
|
@ -30,7 +31,7 @@ import java.util.List;
|
|||
/**
|
||||
* @author Olivier Lamy
|
||||
*/
|
||||
@Service("archivaAdministration#default")
|
||||
@Service( "archivaAdministration#default" )
|
||||
public class DefaultArchivaAdministration
|
||||
extends AbstractRepositoryAdmin
|
||||
implements ArchivaAdministration
|
||||
|
@ -47,7 +48,7 @@ public class DefaultArchivaAdministration
|
|||
return legacyArtifactPaths;
|
||||
}
|
||||
|
||||
public void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
|
||||
public void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath, AuditInformation auditInformation )
|
||||
throws RepositoryAdminException
|
||||
{
|
||||
Configuration configuration = getArchivaConfiguration().getConfiguration();
|
||||
|
@ -58,7 +59,7 @@ public class DefaultArchivaAdministration
|
|||
saveConfiguration( configuration );
|
||||
}
|
||||
|
||||
public void deleteLegacyArtifactPath( String path )
|
||||
public void deleteLegacyArtifactPath( String path, AuditInformation auditInformation )
|
||||
throws RepositoryAdminException
|
||||
{
|
||||
Configuration configuration = getArchivaConfiguration().getConfiguration();
|
||||
|
|
|
@ -49,12 +49,12 @@ public class ArchivaAdministrationTest
|
|||
int initialSize = archivaAdministration.getLegacyArtifactPaths().size();
|
||||
|
||||
LegacyArtifactPath legacyArtifactPath = new LegacyArtifactPath( "foo", "bar" );
|
||||
archivaAdministration.addLegacyArtifactPath( legacyArtifactPath );
|
||||
archivaAdministration.addLegacyArtifactPath( legacyArtifactPath, getFakeAuditInformation() );
|
||||
|
||||
assertTrue( archivaAdministration.getLegacyArtifactPaths().contains( new LegacyArtifactPath( "foo", "bar" ) ) );
|
||||
assertEquals( initialSize + 1, archivaAdministration.getLegacyArtifactPaths().size() );
|
||||
|
||||
archivaAdministration.deleteLegacyArtifactPath( legacyArtifactPath.getPath() );
|
||||
archivaAdministration.deleteLegacyArtifactPath( legacyArtifactPath.getPath(), getFakeAuditInformation() );
|
||||
|
||||
assertFalse(
|
||||
archivaAdministration.getLegacyArtifactPaths().contains( new LegacyArtifactPath( "foo", "bar" ) ) );
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
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 javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Olivier Lamy
|
||||
* @since 1.4
|
||||
*/
|
||||
@XmlRootElement( name = "legacyArtifactPath" )
|
||||
public class LegacyArtifactPath
|
||||
implements Serializable
|
||||
{
|
||||
/**
|
||||
* The legacy path.
|
||||
*/
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* The artifact reference, as " [groupId] :
|
||||
* [artifactId] : [version] : [classifier] : [type] ".
|
||||
*/
|
||||
private String artifact;
|
||||
|
||||
public LegacyArtifactPath()
|
||||
{
|
||||
// no op
|
||||
}
|
||||
|
||||
public LegacyArtifactPath( String path, String artifact )
|
||||
{
|
||||
this.path = path;
|
||||
this.artifact = artifact;
|
||||
}
|
||||
|
||||
public String getPath()
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath( String path )
|
||||
{
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public String getArtifact()
|
||||
{
|
||||
return artifact;
|
||||
}
|
||||
|
||||
public void setArtifact( String artifact )
|
||||
{
|
||||
this.artifact = artifact;
|
||||
}
|
||||
|
||||
public boolean match( String path )
|
||||
{
|
||||
return path.equals( this.path );
|
||||
}
|
||||
|
||||
public String getGroupId()
|
||||
{
|
||||
return artifact.split( ":" )[0];
|
||||
}
|
||||
|
||||
public String getArtifactId()
|
||||
{
|
||||
return artifact.split( ":" )[1];
|
||||
}
|
||||
|
||||
public String getVersion()
|
||||
{
|
||||
return artifact.split( ":" )[2];
|
||||
}
|
||||
|
||||
public String getClassifier()
|
||||
{
|
||||
String classifier = artifact.split( ":" )[3];
|
||||
return classifier.length() > 0 ? classifier : null;
|
||||
}
|
||||
|
||||
public String getType()
|
||||
{
|
||||
return artifact.split( ":" )[4];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package org.apache.archiva.rest.api.services;
|
||||
/*
|
||||
* 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.archiva.admin.repository.RepositoryAdminException;
|
||||
import org.apache.archiva.rest.api.model.LegacyArtifactPath;
|
||||
import org.apache.archiva.security.common.ArchivaRoleConstants;
|
||||
import org.codehaus.plexus.redback.authorization.RedbackAuthorization;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Olivier Lamy
|
||||
* @since 1.4
|
||||
*/
|
||||
@Path( "/archivaAdministrationService/" )
|
||||
public interface ArchivaAdministrationService
|
||||
{
|
||||
@Path( "getLegacyArtifactPaths" )
|
||||
@GET
|
||||
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
||||
@RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
|
||||
List<LegacyArtifactPath> getLegacyArtifactPaths()
|
||||
throws RepositoryAdminException;
|
||||
|
||||
@Path( "addLegacyArtifactPath" )
|
||||
@POST
|
||||
@Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
||||
@RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
|
||||
void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
|
||||
throws RepositoryAdminException;
|
||||
|
||||
@Path( "deleteLegacyArtifactPath" )
|
||||
@GET
|
||||
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
||||
@RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
|
||||
Boolean deleteLegacyArtifactPath( @QueryParam( "path" ) String path )
|
||||
throws RepositoryAdminException;
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package org.apache.archiva.rest.services;
|
||||
/*
|
||||
* 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 net.sf.beanlib.provider.replicator.BeanReplicator;
|
||||
import org.apache.archiva.admin.repository.RepositoryAdminException;
|
||||
import org.apache.archiva.admin.repository.admin.ArchivaAdministration;
|
||||
import org.apache.archiva.rest.api.model.LegacyArtifactPath;
|
||||
import org.apache.archiva.rest.api.services.ArchivaAdministrationService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Olivier Lamy
|
||||
* @since 1.4
|
||||
*/
|
||||
@Service( "archivaAdministrationService#default" )
|
||||
public class DefaultArchivaAdministrationService
|
||||
extends AbstractRestService
|
||||
implements ArchivaAdministrationService
|
||||
{
|
||||
@Inject
|
||||
private ArchivaAdministration archivaAdministration;
|
||||
|
||||
public List<LegacyArtifactPath> getLegacyArtifactPaths()
|
||||
throws RepositoryAdminException
|
||||
{
|
||||
List<LegacyArtifactPath> legacyArtifactPaths = new ArrayList<LegacyArtifactPath>();
|
||||
for ( org.apache.archiva.admin.repository.admin.LegacyArtifactPath legacyArtifactPath : archivaAdministration.getLegacyArtifactPaths() )
|
||||
{
|
||||
legacyArtifactPaths.add(
|
||||
new BeanReplicator().replicateBean( legacyArtifactPath, LegacyArtifactPath.class ) );
|
||||
}
|
||||
return legacyArtifactPaths;
|
||||
}
|
||||
|
||||
public void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
|
||||
throws RepositoryAdminException
|
||||
{
|
||||
archivaAdministration.addLegacyArtifactPath( new BeanReplicator().replicateBean( legacyArtifactPath,
|
||||
org.apache.archiva.admin.repository.admin.LegacyArtifactPath.class ),
|
||||
getAuditInformation() );
|
||||
}
|
||||
|
||||
public Boolean deleteLegacyArtifactPath( String path )
|
||||
throws RepositoryAdminException
|
||||
{
|
||||
archivaAdministration.deleteLegacyArtifactPath( path, getAuditInformation() );
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
}
|
|
@ -55,6 +55,7 @@
|
|||
<ref bean="repositoryGroupService#rest"/>
|
||||
<ref bean="proxyConnectorService#rest"/>
|
||||
<ref bean="networkProxyService#rest"/>
|
||||
<ref bean="archivaAdministrationService#default"/>
|
||||
</jaxrs:serviceBeans>
|
||||
|
||||
<jaxrs:outInterceptors>
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.archiva.rest.services;
|
|||
|
||||
|
||||
import org.apache.archiva.rest.api.model.ManagedRepository;
|
||||
import org.apache.archiva.rest.api.services.ArchivaAdministrationService;
|
||||
import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
|
||||
import org.apache.archiva.rest.api.services.NetworkProxyService;
|
||||
import org.apache.archiva.rest.api.services.PingService;
|
||||
|
@ -105,6 +106,17 @@ public abstract class AbstractArchivaRestTest
|
|||
return service;
|
||||
}
|
||||
|
||||
protected ArchivaAdministrationService getArchivaAdministrationService()
|
||||
{
|
||||
ArchivaAdministrationService service =
|
||||
JAXRSClientFactory.create( "http://localhost:" + port + "/services/archivaServices/",
|
||||
ArchivaAdministrationService.class );
|
||||
|
||||
WebClient.client( service ).header( "Authorization", authorizationHeader );
|
||||
WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
|
||||
return service;
|
||||
}
|
||||
|
||||
protected ManagedRepository getTestManagedRepository()
|
||||
{
|
||||
String location = new File( FileUtil.getBasedir(), "target/test-repo" ).getAbsolutePath();
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package org.apache.archiva.rest.services;
|
||||
/*
|
||||
* 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.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Olivier Lamy
|
||||
*/
|
||||
public class ArchivaAdministrationServiceTest
|
||||
extends AbstractArchivaRestTest
|
||||
{
|
||||
@Test
|
||||
public void getAllLegacyPaths()
|
||||
throws Exception
|
||||
{
|
||||
assertNotNull( getArchivaAdministrationService().getLegacyArtifactPaths() );
|
||||
assertFalse( getArchivaAdministrationService().getLegacyArtifactPaths().isEmpty() );
|
||||
}
|
||||
}
|
|
@ -100,7 +100,7 @@ public class AddLegacyArtifactPathAction
|
|||
|
||||
try
|
||||
{
|
||||
getArchivaAdministration().addLegacyArtifactPath( legacyArtifactPath );
|
||||
getArchivaAdministration().addLegacyArtifactPath( legacyArtifactPath, getAuditInformation() );
|
||||
}
|
||||
catch ( RepositoryAdminException e )
|
||||
{
|
||||
|
|
|
@ -48,7 +48,7 @@ public class DeleteLegacyArtifactPathAction
|
|||
log.info( "remove [" + path + "] from legacy artifact path resolution" );
|
||||
try
|
||||
{
|
||||
getArchivaAdministration().deleteLegacyArtifactPath( path );
|
||||
getArchivaAdministration().deleteLegacyArtifactPath( path, getAuditInformation() );
|
||||
}
|
||||
catch ( RepositoryAdminException e )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue