]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1681] addProxy Connectors Rules screen
authorOlivier Lamy <olamy@apache.org>
Tue, 2 Oct 2012 15:12:47 +0000 (15:12 +0000)
committerOlivier Lamy <olamy@apache.org>
Tue, 2 Oct 2012 15:12:47 +0000 (15:12 +0000)
add REST services.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1392952 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ProxyConnectorRuleService.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultProxyConnectorRuleService.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/ProxyConnectorRuleServiceTest.java [new file with mode: 0644]

diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ProxyConnectorRuleService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ProxyConnectorRuleService.java
new file mode 100644 (file)
index 0000000..d57fed3
--- /dev/null
@@ -0,0 +1,76 @@
+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.model.beans.ProxyConnectorRule;
+import org.apache.archiva.redback.authorization.RedbackAuthorization;
+import org.apache.archiva.security.common.ArchivaRoleConstants;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import java.util.List;
+
+/**
+ * <b>No update method for changing pattern as id is pattern, use delete then add.</b>
+ *
+ * @author Olivier Lamy
+ * @since 1.4-M3
+ */
+@Path ( "/proxyConnectorRuleService/" )
+public interface ProxyConnectorRuleService
+{
+    @Path ( "proxyConnectorRules" )
+    @GET
+    @Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+    @RedbackAuthorization ( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+    List<ProxyConnectorRule> getProxyConnectorRules()
+        throws ArchivaRestServiceException;
+
+    @Path ( "proxyConnectorRule" )
+    @PUT
+    @Consumes ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+    @Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+    @RedbackAuthorization ( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+    Boolean addProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
+        throws ArchivaRestServiceException;
+
+    @Path ( "deleteProxyConnectorRule" )
+    @POST
+    @Consumes ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+    @Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+    @RedbackAuthorization ( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+    Boolean deleteProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
+        throws ArchivaRestServiceException;
+
+    /**
+     * <b>only to update attached proxy connectors to update pattern use delete then add</b>
+     */
+    @Path ( "updateProxyConnectorRule" )
+    @POST
+    @Consumes ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+    @Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+    @RedbackAuthorization ( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+    Boolean updateProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
+        throws ArchivaRestServiceException;
+}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultProxyConnectorRuleService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultProxyConnectorRuleService.java
new file mode 100644 (file)
index 0000000..fd74d15
--- /dev/null
@@ -0,0 +1,97 @@
+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.apache.archiva.admin.model.RepositoryAdminException;
+import org.apache.archiva.admin.model.beans.ProxyConnectorRule;
+import org.apache.archiva.admin.model.proxyconnectorrule.ProxyConnectorRuleAdmin;
+import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
+import org.apache.archiva.rest.api.services.ProxyConnectorRuleService;
+import org.springframework.stereotype.Service;
+
+import javax.inject.Inject;
+import java.util.List;
+
+/**
+ * @author Olivier Lamy
+ */
+@Service ( "proxyConnectorRuleService#rest" )
+public class DefaultProxyConnectorRuleService
+    extends AbstractRestService
+    implements ProxyConnectorRuleService
+{
+
+    @Inject
+    private ProxyConnectorRuleAdmin proxyConnectorRuleAdmin;
+
+    public List<ProxyConnectorRule> getProxyConnectorRules()
+        throws ArchivaRestServiceException
+    {
+        try
+        {
+            return proxyConnectorRuleAdmin.getProxyConnectorRules();
+        }
+        catch ( RepositoryAdminException e )
+        {
+            throw new ArchivaRestServiceException( e.getMessage(), e );
+        }
+    }
+
+    public Boolean addProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
+        throws ArchivaRestServiceException
+    {
+        try
+        {
+            proxyConnectorRuleAdmin.addProxyConnectorRule( proxyConnectorRule, getAuditInformation() );
+            return Boolean.TRUE;
+        }
+        catch ( RepositoryAdminException e )
+        {
+            throw new ArchivaRestServiceException( e.getMessage(), e );
+        }
+    }
+
+    public Boolean deleteProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
+        throws ArchivaRestServiceException
+    {
+        try
+        {
+            proxyConnectorRuleAdmin.deleteProxyConnectorRule( proxyConnectorRule, getAuditInformation() );
+            return Boolean.TRUE;
+        }
+        catch ( RepositoryAdminException e )
+        {
+            throw new ArchivaRestServiceException( e.getMessage(), e );
+        }
+    }
+
+    public Boolean updateProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
+        throws ArchivaRestServiceException
+    {
+        try
+        {
+            proxyConnectorRuleAdmin.updateProxyConnectorRule( proxyConnectorRule, getAuditInformation() );
+            return Boolean.TRUE;
+        }
+        catch ( RepositoryAdminException e )
+        {
+            throw new ArchivaRestServiceException( e.getMessage(), e );
+        }
+    }
+}
index d9468127b1bf4baf1cf51554423add0600193a69..4d0c7fcf35642e9ed9f786472597a24a3675ca5e 100644 (file)
@@ -71,6 +71,7 @@
       <ref bean="systemStatusService#rest"/>
       <ref bean="reportRepositoriesService#rest" />
       <ref bean="mergeRepositoriesService#rest"/>
+      <ref bean="proxyConnectorRuleService#rest"/>
     </jaxrs:serviceBeans>
 
     <jaxrs:outInterceptors>
index d45a9d5221b4f11292f66aae8cad49b30c0b18ed..ee6ff9156a2cd188d21bbf243a766e1a5ccf50c9 100644 (file)
@@ -29,6 +29,7 @@ import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
 import org.apache.archiva.rest.api.services.MergeRepositoriesService;
 import org.apache.archiva.rest.api.services.NetworkProxyService;
 import org.apache.archiva.rest.api.services.PingService;
+import org.apache.archiva.rest.api.services.ProxyConnectorRuleService;
 import org.apache.archiva.rest.api.services.ProxyConnectorService;
 import org.apache.archiva.rest.api.services.RemoteRepositoriesService;
 import org.apache.archiva.rest.api.services.RepositoriesService;
@@ -55,7 +56,7 @@ import java.util.Date;
 /**
  * @author Olivier Lamy
  */
-@RunWith (ArchivaBlockJUnit4ClassRunner.class)
+@RunWith ( ArchivaBlockJUnit4ClassRunner.class )
 public abstract class AbstractArchivaRestTest
     extends AbstractRestServicesTest
 {
@@ -123,12 +124,10 @@ public abstract class AbstractArchivaRestTest
         return getRepositoriesService( null );
     }
 
-    protected MergeRepositoriesService getMergeRepositoriesService( String authzHeader )
+    protected <T> T getService( Class<T> clazz, String authzHeader )
     {
-        MergeRepositoriesService service =
-            JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/",
-                                       MergeRepositoriesService.class,
-                                       Collections.singletonList( new JacksonJaxbJsonProvider() ) );
+        T service = JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/", clazz,
+                                               Collections.singletonList( new JacksonJaxbJsonProvider() ) );
 
         if ( authzHeader != null )
         {
@@ -140,54 +139,35 @@ public abstract class AbstractArchivaRestTest
         return service;
     }
 
-    protected RepositoriesService getRepositoriesService( String authzHeader )
+    protected ProxyConnectorRuleService getProxyConnectorRuleService( String authzHeader )
     {
-        RepositoriesService service =
-            JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/",
-                                       RepositoriesService.class,
-                                       Collections.singletonList( new JacksonJaxbJsonProvider() ) );
-
-        if ( authzHeader != null )
-        {
-            WebClient.client( service ).header( "Authorization", authzHeader );
-        }
-        WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000000 );
-        WebClient.client( service ).accept( MediaType.APPLICATION_JSON_TYPE );
-        WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );
-        return service;
+        return getService( ProxyConnectorRuleService.class, authzHeader );
+    }
 
+    protected MergeRepositoriesService getMergeRepositoriesService( String authzHeader )
+    {
+        return getService( MergeRepositoriesService.class, authzHeader );
     }
 
-    protected ManagedRepositoriesService getManagedRepositoriesService( String authzHeader )
+    protected RepositoriesService getRepositoriesService( String authzHeader )
     {
-        ManagedRepositoriesService service =
-            JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/",
-                                       ManagedRepositoriesService.class,
-                                       Collections.singletonList( new JacksonJaxbJsonProvider() ) );
+        return getService( RepositoriesService.class, authzHeader );
 
-        if ( authzHeader != null )
-        {
-            WebClient.client( service ).header( "Authorization", authzHeader );
-        }
-        WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000000 );
-        WebClient.client( service ).accept( MediaType.APPLICATION_JSON_TYPE );
-        WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );
-        return service;
+    }
 
+    protected ManagedRepositoriesService getManagedRepositoriesService( String authzHeader )
+    {
+        return getService( ManagedRepositoriesService.class, authzHeader );
     }
 
     protected PingService getPingService()
     {
-        return JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/",
-                                          PingService.class,
-                                          Collections.singletonList( new JacksonJaxbJsonProvider() ) );
+        return getService( PingService.class, null );
     }
 
     protected RemoteRepositoriesService getRemoteRepositoriesService()
     {
-        return JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/",
-                                          RemoteRepositoriesService.class,
-                                          Collections.singletonList( new JacksonJaxbJsonProvider() ) );
+        return getService( RemoteRepositoriesService.class, null );
 
 
     }
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ProxyConnectorRuleServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ProxyConnectorRuleServiceTest.java
new file mode 100644 (file)
index 0000000..04d26d0
--- /dev/null
@@ -0,0 +1,76 @@
+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.apache.archiva.admin.model.beans.ProxyConnector;
+import org.apache.archiva.admin.model.beans.ProxyConnectorRule;
+import org.apache.archiva.admin.model.beans.ProxyConnectorRuleType;
+import org.apache.archiva.rest.api.services.ProxyConnectorRuleService;
+import org.junit.Test;
+
+import java.util.Arrays;
+
+/**
+ * @author Olivier Lamy
+ */
+public class ProxyConnectorRuleServiceTest
+    extends AbstractArchivaRestTest
+{
+
+    @Test
+    public void addProxyConnectorRule()
+        throws Exception
+    {
+        ProxyConnector proxyConnector = new ProxyConnector();
+        proxyConnector.setSourceRepoId( "snapshots" );
+        proxyConnector.setTargetRepoId( "central" );
+
+        ProxyConnectorRuleService service = getProxyConnectorRuleService( authorizationHeader );
+
+        ProxyConnectorRule rule = null;
+        try
+        {
+
+            int size = service.getProxyConnectorRules().size();
+            assertEquals( 0, size );
+
+            getProxyConnectorService().addProxyConnector( proxyConnector );
+
+            rule = new ProxyConnectorRule( "org/apache/maven", ProxyConnectorRuleType.BLACK_LIST,
+                                           Arrays.asList( proxyConnector ) );
+
+            service.addProxyConnectorRule( rule );
+            assertEquals( size + 1, service.getProxyConnectorRules().size() );
+
+            rule = service.getProxyConnectorRules().get( 0 );
+
+            assertEquals( "org/apache/maven", rule.getPattern() );
+            assertEquals( 1, rule.getProxyConnectors().size() );
+            assertEquals( "snapshots", rule.getProxyConnectors().get( 0 ).getSourceRepoId() );
+            assertEquals( "central", rule.getProxyConnectors().get( 0 ).getTargetRepoId() );
+            assertEquals( ProxyConnectorRuleType.BLACK_LIST, rule.getProxyConnectorRuleType() );
+        }
+        finally
+        {
+            service.deleteProxyConnectorRule( rule );
+            getProxyConnectorService().deleteProxyConnector( proxyConnector );
+        }
+    }
+}
+