*/
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;
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;
+
}
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
? ""
: ":" + 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;
+ }
}
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;
@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
{
}
}
+ 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;