import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.Validateable;
+import org.apache.archiva.admin.repository.RepositoryAdminException;
+import org.apache.archiva.admin.repository.networkproxy.NetworkProxy;
+import org.apache.archiva.admin.repository.networkproxy.NetworkProxyAdmin;
import org.apache.archiva.security.common.ArchivaRoleConstants;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.functors.NotPredicate;
import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.configuration.ArchivaConfiguration;
-import org.apache.maven.archiva.configuration.Configuration;
-import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
-import org.apache.maven.archiva.configuration.NetworkProxyConfiguration;
-import org.apache.maven.archiva.configuration.functors.NetworkProxySelectionPredicate;
import org.apache.maven.archiva.web.action.AbstractActionSupport;
import org.codehaus.plexus.redback.rbac.Resource;
-import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.redback.integration.interceptor.SecureAction;
import org.codehaus.redback.integration.interceptor.SecureActionBundle;
import org.codehaus.redback.integration.interceptor.SecureActionException;
{
@Inject
- private ArchivaConfiguration archivaConfiguration;
+ private NetworkProxyAdmin networkProxyAdmin;
private String mode;
private String proxyid;
- private NetworkProxyConfiguration proxy;
+ private NetworkProxy proxy;
public String add()
{
}
public String delete()
+ throws RepositoryAdminException
{
- Configuration config = archivaConfiguration.getConfiguration();
String id = getProxyid();
if ( StringUtils.isBlank( id ) )
return SUCCESS;
}
- NetworkProxySelectionPredicate networkProxySelection = new NetworkProxySelectionPredicate( id );
- NetworkProxyConfiguration proxyConfig =
- (NetworkProxyConfiguration) CollectionUtils.find( config.getNetworkProxies(), networkProxySelection );
- if ( proxyConfig == null )
+ NetworkProxy networkProxy = getNetworkProxyAdmin().getNetworkProxy( id );
+ if ( networkProxy == null )
{
addActionError( "Unable to remove network proxy, proxy with id [" + id + "] not found." );
return SUCCESS;
}
- archivaConfiguration.getConfiguration().removeNetworkProxy( proxyConfig );
+ getNetworkProxyAdmin().deleteNetworkProxy( id, getAuditInformation() );
addActionMessage( "Successfully removed network proxy [" + id + "]" );
- return saveConfiguration();
+ return SUCCESS;
}
public String edit()
return mode;
}
- public NetworkProxyConfiguration getProxy()
+ public NetworkProxy getProxy()
{
return proxy;
}
if ( proxy == null )
{
- proxy = new NetworkProxyConfiguration();
+ proxy = new NetworkProxy();
}
}
public String save()
+ throws RepositoryAdminException
{
String mode = getMode();
if ( StringUtils.equalsIgnoreCase( "edit", mode ) )
{
- removeNetworkProxy( id );
+ getNetworkProxyAdmin().updateNetworkProxy( proxy, getAuditInformation() );
}
else
{
- if ( findNetworkProxy( id ) != null )
- {
- addActionError( "Unable to add new repository with id [" + id + "], that id already exists." );
- return INPUT;
- }
+ getNetworkProxyAdmin().addNetworkProxy( proxy, getAuditInformation() );
}
- addNetworkProxy( getProxy() );
- return saveConfiguration();
+ return SUCCESS;
}
public void validate()
this.mode = mode;
}
- public void setProxy( NetworkProxyConfiguration proxy )
+ public void setProxy( NetworkProxy proxy )
{
this.proxy = proxy;
}
this.proxyid = proxyid;
}
- private void addNetworkProxy( NetworkProxyConfiguration proxy )
- {
- archivaConfiguration.getConfiguration().addNetworkProxy( proxy );
- }
- private NetworkProxyConfiguration findNetworkProxy( String id )
+ private NetworkProxy findNetworkProxy( String id )
+ throws RepositoryAdminException
{
- Configuration config = archivaConfiguration.getConfiguration();
-
- NetworkProxySelectionPredicate selectedProxy = new NetworkProxySelectionPredicate( id );
-
- return (NetworkProxyConfiguration) CollectionUtils.find( config.getNetworkProxies(), selectedProxy );
+ return getNetworkProxyAdmin().getNetworkProxy( id );
}
private void removeNetworkProxy( String id )
+ throws RepositoryAdminException
{
- NetworkProxySelectionPredicate selectedProxy = new NetworkProxySelectionPredicate( id );
- NotPredicate notSelectedProxy = new NotPredicate( selectedProxy );
- CollectionUtils.filter( archivaConfiguration.getConfiguration().getNetworkProxies(), notSelectedProxy );
+ getNetworkProxyAdmin().deleteNetworkProxy( id, getAuditInformation() );
}
- private String saveConfiguration()
- {
- try
- {
- archivaConfiguration.save( archivaConfiguration.getConfiguration() );
- addActionMessage( "Successfully saved configuration" );
- }
- catch ( RegistryException e )
- {
- addActionError( "Unable to save configuration: " + e.getMessage() );
- return INPUT;
- }
- catch ( IndeterminateConfigurationException e )
- {
- addActionError( e.getMessage() );
- return INPUT;
- }
-
- return SUCCESS;
- }
private void trimAllRequestParameterValues()
{
proxy.setUsername( proxy.getUsername().trim() );
}
}
+
+ public NetworkProxyAdmin getNetworkProxyAdmin()
+ {
+ return networkProxyAdmin;
+ }
+
+ public void setNetworkProxyAdmin( NetworkProxyAdmin networkProxyAdmin )
+ {
+ this.networkProxyAdmin = networkProxyAdmin;
+ }
}
+
import java.util.Map;
import junit.framework.TestCase;
+import org.apache.archiva.admin.repository.networkproxy.NetworkProxy;
import org.apache.maven.archiva.configuration.NetworkProxyConfiguration;
import org.apache.maven.archiva.web.action.admin.repositories.DefaultActionValidatorManagerFactory;
import org.apache.archiva.web.validator.utils.ValidatorUtil;
public void testStruts2ValidationFrameworkWithNullInputs() throws Exception
{
// prep
- NetworkProxyConfiguration networkProxyConfiguration = createNetworkProxyConfiguration(null, null, null, null);
- configureNetworkProxyAction.setProxy(networkProxyConfiguration);
+ NetworkProxy networkProxy = createNetworkProxy(null, null, null, null);
+ configureNetworkProxyAction.setProxy(networkProxy);
// test
actionValidatorManager.validate(configureNetworkProxyAction, VALIDATION_CONTEXT);
public void testStruts2ValidationFrameworkWithBlankInputs() throws Exception
{
// prep
- NetworkProxyConfiguration networkProxyConfiguration = createNetworkProxyConfiguration(EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING);
- configureNetworkProxyAction.setProxy(networkProxyConfiguration);
+ NetworkProxy networkProxy = createNetworkProxy(EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING);
+ configureNetworkProxyAction.setProxy(networkProxy);
// test
actionValidatorManager.validate(configureNetworkProxyAction, VALIDATION_CONTEXT);
public void testStruts2ValidationFrameworkWithInvalidInputs() throws Exception
{
// prep
- NetworkProxyConfiguration networkProxyConfiguration = createNetworkProxyConfiguration(PROXY_ID_INVALID_INPUT, PROXY_HOST_INVALID_INPUT, PROXY_PORT_INVALID_INPUT, PROXY_PROTOCOL_INVALID_INPUT, PROXY_USERNAME_INVALID_INPUT);
- configureNetworkProxyAction.setProxy(networkProxyConfiguration);
+ NetworkProxy networkProxy = createNetworkProxy( PROXY_ID_INVALID_INPUT, PROXY_HOST_INVALID_INPUT,
+ PROXY_PORT_INVALID_INPUT, PROXY_PROTOCOL_INVALID_INPUT,
+ PROXY_USERNAME_INVALID_INPUT );
+ configureNetworkProxyAction.setProxy(networkProxy);
// test
actionValidatorManager.validate(configureNetworkProxyAction, VALIDATION_CONTEXT);
public void testStruts2ValidationFrameworkWithValidInputs() throws Exception
{
// prep
- NetworkProxyConfiguration networkProxyConfiguration = createNetworkProxyConfiguration(PROXY_ID_VALID_INPUT, PROXY_HOST_VALID_INPUT, PROXY_PORT_VALID_INPUT, PROXY_PROTOCOL_VALID_INPUT, PROXY_USERNAME_VALID_INPUT);
- configureNetworkProxyAction.setProxy(networkProxyConfiguration);
+ NetworkProxy networkProxy = createNetworkProxy(PROXY_ID_VALID_INPUT, PROXY_HOST_VALID_INPUT, PROXY_PORT_VALID_INPUT, PROXY_PROTOCOL_VALID_INPUT, PROXY_USERNAME_VALID_INPUT);
+ configureNetworkProxyAction.setProxy(networkProxy);
// test
actionValidatorManager.validate(configureNetworkProxyAction, VALIDATION_CONTEXT);
assertFalse(configureNetworkProxyAction.hasFieldErrors());
}
- private NetworkProxyConfiguration createNetworkProxyConfiguration(String id, String host, int port, String protocol, String username)
+ private NetworkProxy createNetworkProxy(String id, String host, int port, String protocol, String username)
{
- NetworkProxyConfiguration networkProxyConfiguration = new NetworkProxyConfiguration();
- networkProxyConfiguration.setId(id);
- networkProxyConfiguration.setHost(host);
- networkProxyConfiguration.setPort(port);
- networkProxyConfiguration.setProtocol(protocol);
- networkProxyConfiguration.setUsername(username);
- return networkProxyConfiguration;
+ NetworkProxy networkProxy = new NetworkProxy();
+ networkProxy.setId( id );
+ networkProxy.setHost( host );
+ networkProxy.setPort( port );
+ networkProxy.setProtocol( protocol );
+ networkProxy.setUsername( username );
+ return networkProxy;
}
// over-loaded
// for simulating empty/null form purposes; excluding primitive data-typed values
- private NetworkProxyConfiguration createNetworkProxyConfiguration(String id, String host, String protocol, String username)
+ private NetworkProxy createNetworkProxy(String id, String host, String protocol, String username)
{
- NetworkProxyConfiguration networkProxyConfiguration = new NetworkProxyConfiguration();
- networkProxyConfiguration.setId(id);
- networkProxyConfiguration.setHost(host);
- networkProxyConfiguration.setProtocol(protocol);
- networkProxyConfiguration.setUsername(username);
- return networkProxyConfiguration;
+ NetworkProxy networkProxy = new NetworkProxy();
+ networkProxy.setId( id );
+ networkProxy.setHost( host );
+ networkProxy.setProtocol( protocol );
+ networkProxy.setUsername( username );
+ return networkProxy;
}
}