From: Olivier Lamy Date: Thu, 8 Sep 2011 20:17:04 +0000 (+0000) Subject: [MRM-1490] REST services : configure legacy paths tru rest services X-Git-Tag: archiva-1.4-M1~347 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5b7476e8d6e846222b7264017382e92886b6f8a4;p=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 --- diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/ArchivaAdministration.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/ArchivaAdministration.java index 589e9a78c..61fc21ba8 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/ArchivaAdministration.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/ArchivaAdministration.java @@ -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 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; } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java index ac2b89e56..ec07874c3 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java @@ -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(); diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java index 76f283c3f..8e1afed25 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java @@ -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" ) ) ); diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/LegacyArtifactPath.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/LegacyArtifactPath.java new file mode 100644 index 000000000..ce4ac95c0 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/LegacyArtifactPath.java @@ -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]; + } +} diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ArchivaAdministrationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ArchivaAdministrationService.java new file mode 100644 index 000000000..209963825 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ArchivaAdministrationService.java @@ -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 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; +} diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java new file mode 100644 index 000000000..8d19a274a --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java @@ -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 getLegacyArtifactPaths() + throws RepositoryAdminException + { + List legacyArtifactPaths = new ArrayList(); + 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; + } +} diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml index 678c39cdb..9dbc8e677 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml @@ -55,6 +55,7 @@ + diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java index 361db4b71..79a3e8223 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java @@ -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(); diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java new file mode 100644 index 000000000..ea7c91c16 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java @@ -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() ); + } +} diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/legacy/AddLegacyArtifactPathAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/legacy/AddLegacyArtifactPathAction.java index 998e96eb1..5986630c4 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/legacy/AddLegacyArtifactPathAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/legacy/AddLegacyArtifactPathAction.java @@ -100,7 +100,7 @@ public class AddLegacyArtifactPathAction try { - getArchivaAdministration().addLegacyArtifactPath( legacyArtifactPath ); + getArchivaAdministration().addLegacyArtifactPath( legacyArtifactPath, getAuditInformation() ); } catch ( RepositoryAdminException e ) { diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/legacy/DeleteLegacyArtifactPathAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/legacy/DeleteLegacyArtifactPathAction.java index a40ce1c6f..220d7b145 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/legacy/DeleteLegacyArtifactPathAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/legacy/DeleteLegacyArtifactPathAction.java @@ -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 ) {