]> source.dussan.org Git - archiva.git/commitdiff
start work on proxy connector screen
authorOlivier Lamy <olamy@apache.org>
Mon, 30 Jan 2012 09:47:16 +0000 (09:47 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 30 Jan 2012 09:47:16 +0000 (09:47 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1237580 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ProxyConnectorService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultProxyConnectorService.java

index af32d2d5666782793397542ec4fb4d69ba74bba3..818529b022e023f9b20315813b6526f3203ca55a 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.archiva.rest.api.services;
  */
 
 import org.apache.archiva.admin.model.beans.ProxyConnector;
+import org.apache.archiva.rest.api.model.PolicyInformation;
 import org.apache.archiva.security.common.ArchivaRoleConstants;
 import org.codehaus.plexus.redback.authorization.RedbackAuthorization;
 
@@ -85,5 +86,13 @@ public interface ProxyConnectorService
     Boolean updateProxyConnector( ProxyConnector proxyConnector )
         throws ArchivaRestServiceException;
 
+    @Path( "allPolicies" )
+    @GET
+    @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+    @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+    List<PolicyInformation> getAllPolicyInformations()
+        throws ArchivaRestServiceException;
+
 
 }
index ef29d3886ff53d97495bed4a51c61a0394328d19..5a252633cc1085b47a1b9c917c34d15531079071 100644 (file)
@@ -20,17 +20,21 @@ package org.apache.archiva.rest.services;
 
 import org.apache.archiva.admin.model.AuditInformation;
 import org.apache.archiva.audit.AuditListener;
+import org.apache.commons.lang.StringUtils;
 import org.codehaus.plexus.redback.users.User;
 import org.codehaus.redback.rest.services.RedbackAuthenticationThreadLocal;
 import org.codehaus.redback.rest.services.RedbackRequestInformation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.context.ApplicationContext;
 
 import javax.inject.Inject;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.Context;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * abstract class with common utilities methods
@@ -73,4 +77,21 @@ public abstract class AbstractRestService
             ? ""
             : ":" + req.getServerPort() ) + req.getContextPath();
     }
+
+    protected <T> Map<String, T> getBeansOfType( ApplicationContext applicationContext, Class<T> clazz )
+    {
+        //TODO do some caching here !!!
+        // olamy : with plexus we get only roleHint
+        // as per convention we named spring bean role#hint remove role# if exists
+        Map<String, T> springBeans = applicationContext.getBeansOfType( clazz );
+
+        Map<String, T> beans = new HashMap<String, T>( springBeans.size() );
+
+        for ( Map.Entry<String, T> entry : springBeans.entrySet() )
+        {
+            String key = StringUtils.substringAfterLast( entry.getKey(), "#" );
+            beans.put( key, entry.getValue() );
+        }
+        return beans;
+    }
 }
index 0b704919ad2fc7ed57ea5561602349561a704be6..72aa4424131b04285135ac5983a724f769f1bc38 100644 (file)
@@ -21,11 +21,15 @@ package org.apache.archiva.rest.services;
 import org.apache.archiva.admin.model.RepositoryAdminException;
 import org.apache.archiva.admin.model.beans.ProxyConnector;
 import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin;
+import org.apache.archiva.policies.Policy;
+import org.apache.archiva.rest.api.model.PolicyInformation;
 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
 import org.apache.archiva.rest.api.services.ProxyConnectorService;
+import org.springframework.context.ApplicationContext;
 import org.springframework.stereotype.Service;
 
 import javax.inject.Inject;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
@@ -40,6 +44,14 @@ public class DefaultProxyConnectorService
     @Inject
     private ProxyConnectorAdmin proxyConnectorAdmin;
 
+    private List<Policy> allPolicies;
+
+    @Inject
+    public DefaultProxyConnectorService( ApplicationContext applicationContext )
+    {
+        allPolicies = new ArrayList<Policy>( getBeansOfType( applicationContext, Policy.class ).values() );
+    }
+
     public List<ProxyConnector> getProxyConnectors()
         throws ArchivaRestServiceException
     {
@@ -118,6 +130,21 @@ public class DefaultProxyConnectorService
         }
     }
 
+    public List<PolicyInformation> getAllPolicyInformations()
+        throws ArchivaRestServiceException
+    {
+        List<PolicyInformation> policyInformations = new ArrayList<PolicyInformation>( allPolicies.size() );
+
+        for ( Policy policy : allPolicies )
+        {
+            policyInformations.add(
+                new PolicyInformation( policy.getOptions(), policy.getDefaultOption(), policy.getId(),
+                                       policy.getName() ) );
+        }
+
+        return policyInformations;
+    }
+
     public ProxyConnectorAdmin getProxyConnectorAdmin()
     {
         return proxyConnectorAdmin;