]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1490] REST services : configure legacy paths tru rest services
authorOlivier Lamy <olamy@apache.org>
Thu, 8 Sep 2011 20:17:04 +0000 (20:17 +0000)
committerOlivier Lamy <olamy@apache.org>
Thu, 8 Sep 2011 20:17:04 +0000 (20:17 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1166884 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/ArchivaAdministration.java
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java
archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/LegacyArtifactPath.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ArchivaAdministrationService.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/legacy/AddLegacyArtifactPathAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/legacy/DeleteLegacyArtifactPathAction.java

index 589e9a78c49f23c662b223cc8b42fbfb32d2ed15..61fc21ba88a5584650c4f7e85982babe05fd17b9 100644 (file)
@@ -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;
 }
index ac2b89e568da4ab58180eb0518f85ea2957be455..ec07874c3a67d967004081d06e78cbfbb3202552 100644 (file)
@@ -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();
index 76f283c3f6a976caa7279730a29a92761d6c1808..8e1afed25d48bf239d637d08c1bb8c8562a48f22 100644 (file)
@@ -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 (file)
index 0000000..ce4ac95
--- /dev/null
@@ -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 (file)
index 0000000..2099638
--- /dev/null
@@ -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;
+}
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 (file)
index 0000000..8d19a27
--- /dev/null
@@ -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;
+    }
+}
index 678c39cdbb6db3026f8fd23be69f216041c12589..9dbc8e6773d0376787210a3c091a5ab8a9e81493 100644 (file)
@@ -55,6 +55,7 @@
       <ref bean="repositoryGroupService#rest"/>
       <ref bean="proxyConnectorService#rest"/>
       <ref bean="networkProxyService#rest"/>
+      <ref bean="archivaAdministrationService#default"/>
     </jaxrs:serviceBeans>
 
     <jaxrs:outInterceptors>
index 361db4b71f0af674173d596e915fbeef26cfab54..79a3e82231c5fa168bbc2f19d4cb0720e9d2cf31 100644 (file)
@@ -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 (file)
index 0000000..ea7c91c
--- /dev/null
@@ -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() );
+    }
+}
index 998e96eb1159de0639d23468fd3f2087edcf0bc8..5986630c430c89011d188952258047a125a02a02 100644 (file)
@@ -100,7 +100,7 @@ public class AddLegacyArtifactPathAction
 
         try
         {
-            getArchivaAdministration().addLegacyArtifactPath( legacyArtifactPath );
+            getArchivaAdministration().addLegacyArtifactPath( legacyArtifactPath, getAuditInformation() );
         }
         catch ( RepositoryAdminException e )
         {
index a40ce1c6ffb748462573946393539b57184cb0d7..220d7b145b797d04c535a6d60e368c0100ce922e 100644 (file)
@@ -48,7 +48,7 @@ public class DeleteLegacyArtifactPathAction
         log.info( "remove [" + path + "] from legacy artifact path resolution" );\r
         try\r
         {\r
-            getArchivaAdministration().deleteLegacyArtifactPath( path );\r
+            getArchivaAdministration().deleteLegacyArtifactPath( path, getAuditInformation() );\r
         }\r
         catch ( RepositoryAdminException e )\r
         {\r