diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ProxyConnectorService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ProxyConnectorService.java index af32d2d56..818529b02 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ProxyConnectorService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ProxyConnectorService.java @@ -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 getAllPolicyInformations() + throws ArchivaRestServiceException; + } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java index ef29d3886..5a252633c 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java @@ -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 Map getBeansOfType( ApplicationContext applicationContext, Class 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 springBeans = applicationContext.getBeansOfType( clazz ); + + Map beans = new HashMap( springBeans.size() ); + + for ( Map.Entry entry : springBeans.entrySet() ) + { + String key = StringUtils.substringAfterLast( entry.getKey(), "#" ); + beans.put( key, entry.getValue() ); + } + return beans; + } } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultProxyConnectorService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultProxyConnectorService.java index 0b704919a..72aa44241 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultProxyConnectorService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultProxyConnectorService.java @@ -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 allPolicies; + + @Inject + public DefaultProxyConnectorService( ApplicationContext applicationContext ) + { + allPolicies = new ArrayList( getBeansOfType( applicationContext, Policy.class ).values() ); + } + public List getProxyConnectors() throws ArchivaRestServiceException { @@ -118,6 +130,21 @@ public class DefaultProxyConnectorService } } + public List getAllPolicyInformations() + throws ArchivaRestServiceException + { + List policyInformations = new ArrayList( 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;