summaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2012-10-02 15:12:16 +0000
committerOlivier Lamy <olamy@apache.org>2012-10-02 15:12:16 +0000
commita8c549a9bb88fd2f6abea3435cae7361335811df (patch)
treedc79c17ce8dbda4918984d313c6895623b82c104 /archiva-modules/archiva-base
parent163e2753eb3ec596f5b1a911f4240c9d277fadbc (diff)
downloadarchiva-a8c549a9bb88fd2f6abea3435cae7361335811df.tar.gz
archiva-a8c549a9bb88fd2f6abea3435cae7361335811df.zip
[MRM-1681] addProxy Connectors Rules screen
implements backend part. git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1392951 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-base')
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo43
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ProxyConnectorRule.java133
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ProxyConnectorRuleType.java55
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/proxyconnector/ProxyConnectorAdmin.java1
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/proxyconnectorrule/ProxyConnectorRuleAdmin.java66
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/proxyconnector/DefaultProxyConnectorAdmin.java19
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/proxyconnectorrule/DefaultProxyConnectorRuleAdmin.java170
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java4
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/proxyconnectorrule/ProxyConnectorRuleAdminTest.java180
9 files changed, 655 insertions, 16 deletions
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo
index 3d6365d77..447949500 100644
--- a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo
+++ b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo
@@ -168,6 +168,17 @@
The NetworkConfiguration .
</description>
</field>
+ <field>
+ <name>proxyConnectorRuleConfigurations</name>
+ <version>1.4.0+</version>
+ <association>
+ <type>ProxyConnectorRuleConfiguration</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ <description>
+ The list of ProxyConnectorRuleConfigurations.
+ </description>
+ </field>
</fields>
<codeSegments>
<codeSegment>
@@ -928,6 +939,38 @@
</class>
<class>
+ <name>ProxyConnectorRuleConfiguration</name>
+ <version>1.4.0+</version>
+ <fields>
+ <field>
+ <name>ruleType</name>
+ <version>1.4.0+</version>
+ <type>String</type>
+ <description>
+ The type if this rule: whiteList, blackList etc..
+ </description>
+ </field>
+ <field>
+ <name>pattern</name>
+ <version>1.4.0+</version>
+ <type>String</type>
+ <description>
+ The pattern for this rule: whiteList, blackList etc..
+ </description>
+ </field>
+ <field>
+ <name>proxyConnectors</name>
+ <version>1.4.0+</version>
+ <description>Associated proxyConnectors configuration.</description>
+ <association>
+ <type>ProxyConnectorConfiguration</type>
+ <multiplicity>*</multiplicity>
+ </association>
+ </field>
+ </fields>
+ </class>
+
+ <class>
<superClass>AbstractRepositoryConnectorConfiguration</superClass>
<name>ProxyConnectorConfiguration</name>
<version>1.0.0+</version>
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ProxyConnectorRule.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ProxyConnectorRule.java
new file mode 100644
index 000000000..f672bee4d
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ProxyConnectorRule.java
@@ -0,0 +1,133 @@
+package org.apache.archiva.admin.model.beans;
+/*
+ * 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 javax.xml.bind.annotation.XmlRootElement;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Olivier Lamy
+ * @since 1.4-M3
+ */
+@XmlRootElement ( name = "proxyConnectorRule" )
+public class ProxyConnectorRule
+ implements Serializable
+{
+ private String pattern;
+
+ //FIXME: olamy possible tru rest ? or a String
+ private ProxyConnectorRuleType proxyConnectorRuleType;
+
+ private List<ProxyConnector> proxyConnectors;
+
+ public ProxyConnectorRule()
+ {
+ // no op
+ }
+
+ public ProxyConnectorRule( String pattern, ProxyConnectorRuleType proxyConnectorRuleType,
+ List<ProxyConnector> proxyConnectors )
+ {
+ this.pattern = pattern;
+ this.proxyConnectorRuleType = proxyConnectorRuleType;
+ this.proxyConnectors = proxyConnectors;
+ }
+
+ public String getPattern()
+ {
+ return pattern;
+ }
+
+ public void setPattern( String pattern )
+ {
+ this.pattern = pattern;
+ }
+
+ public ProxyConnectorRuleType getProxyConnectorRuleType()
+ {
+ return proxyConnectorRuleType;
+ }
+
+ public void setProxyConnectorRuleType( ProxyConnectorRuleType proxyConnectorRuleType )
+ {
+ this.proxyConnectorRuleType = proxyConnectorRuleType;
+ }
+
+ public List<ProxyConnector> getProxyConnectors()
+ {
+ if ( this.proxyConnectors == null )
+ {
+ this.proxyConnectors = new ArrayList<ProxyConnector>();
+ }
+ return proxyConnectors;
+ }
+
+ public void setProxyConnectors( List<ProxyConnector> proxyConnectors )
+ {
+ this.proxyConnectors = proxyConnectors;
+ }
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o )
+ {
+ return true;
+ }
+ if ( !( o instanceof ProxyConnectorRule ) )
+ {
+ return false;
+ }
+
+ ProxyConnectorRule that = (ProxyConnectorRule) o;
+
+ if ( !pattern.equals( that.pattern ) )
+ {
+ return false;
+ }
+ if ( proxyConnectorRuleType != that.proxyConnectorRuleType )
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = pattern.hashCode();
+ result = 31 * result + proxyConnectorRuleType.hashCode();
+ return result;
+ }
+
+ @Override
+ public String toString()
+ {
+ final StringBuilder sb = new StringBuilder();
+ sb.append( "ProxyConnectorRule" );
+ sb.append( "{pattern='" ).append( pattern ).append( '\'' );
+ sb.append( ", proxyConnectorRuleType=" ).append( proxyConnectorRuleType );
+ sb.append( ", proxyConnectors=" ).append( proxyConnectors );
+ sb.append( '}' );
+ return sb.toString();
+ }
+}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ProxyConnectorRuleType.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ProxyConnectorRuleType.java
new file mode 100644
index 000000000..4eaf6fdba
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ProxyConnectorRuleType.java
@@ -0,0 +1,55 @@
+package org.apache.archiva.admin.model.beans;
+/*
+ * 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.
+ */
+
+/**
+ * @author Olivier Lamy
+ * @since 1.4-M3
+ */
+public enum ProxyConnectorRuleType
+{
+ WHITE_LIST( "whiteList" ), BLACK_LIST( "blackList" );
+
+ private String ruleType;
+
+ private ProxyConnectorRuleType( String ruleType )
+ {
+ this.ruleType = ruleType;
+ }
+
+ public void setRuleType( String ruleType )
+ {
+ this.ruleType = ruleType;
+ }
+
+ public String getRuleType()
+ {
+ return ruleType;
+ }
+
+ @Override
+ public String toString()
+ {
+ final StringBuilder sb = new StringBuilder();
+ sb.append( "ProxyConnectorRuleType" );
+ sb.append( "{ruleType='" ).append( ruleType ).append( '\'' );
+ sb.append( '}' );
+ return sb.toString();
+ }
+}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/proxyconnector/ProxyConnectorAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/proxyconnector/ProxyConnectorAdmin.java
index f06a1e6ea..256633d49 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/proxyconnector/ProxyConnectorAdmin.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/proxyconnector/ProxyConnectorAdmin.java
@@ -21,6 +21,7 @@ package org.apache.archiva.admin.model.proxyconnector;
import org.apache.archiva.admin.model.AuditInformation;
import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.admin.model.beans.ProxyConnector;
+import org.apache.archiva.admin.model.beans.ProxyConnectorRule;
import java.util.List;
import java.util.Map;
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/proxyconnectorrule/ProxyConnectorRuleAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/proxyconnectorrule/ProxyConnectorRuleAdmin.java
new file mode 100644
index 000000000..d7d7cefc4
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/proxyconnectorrule/ProxyConnectorRuleAdmin.java
@@ -0,0 +1,66 @@
+package org.apache.archiva.admin.model.proxyconnectorrule;
+/*
+ * 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.AuditInformation;
+import org.apache.archiva.admin.model.RepositoryAdminException;
+import org.apache.archiva.admin.model.beans.ProxyConnectorRule;
+
+import java.util.List;
+
+/**
+ * @author Olivier Lamy
+ * @since 1.4-M3
+ */
+public interface ProxyConnectorRuleAdmin
+{
+ /**
+ * @return
+ * @throws org.apache.archiva.admin.model.RepositoryAdminException
+ *
+ * @since 1.4-M3
+ */
+ List<ProxyConnectorRule> getProxyConnectorRules()
+ throws RepositoryAdminException;
+
+ /**
+ * @param proxyConnectorRule
+ * @throws RepositoryAdminException
+ * @since 1.4-M3
+ */
+ void addProxyConnectorRule( ProxyConnectorRule proxyConnectorRule, AuditInformation auditInformation )
+ throws RepositoryAdminException;
+
+ /**
+ * @param proxyConnectorRule
+ * @throws RepositoryAdminException
+ * @since 1.4-M3
+ */
+ void deleteProxyConnectorRule( ProxyConnectorRule proxyConnectorRule, AuditInformation auditInformation )
+ throws RepositoryAdminException;
+
+ /**
+ * <b>only to update attached proxy connectors to update pattern delete then add</b>
+ * @param proxyConnectorRule
+ * @throws RepositoryAdminException
+ * @since 1.4-M3
+ */
+ void updateProxyConnectorRule( ProxyConnectorRule proxyConnectorRule, AuditInformation auditInformation )
+ throws RepositoryAdminException;
+}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/proxyconnector/DefaultProxyConnectorAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/proxyconnector/DefaultProxyConnectorAdmin.java
index 525ae7d56..f7ff3f9d6 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/proxyconnector/DefaultProxyConnectorAdmin.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/proxyconnector/DefaultProxyConnectorAdmin.java
@@ -47,7 +47,7 @@ import java.util.Map;
* @author Olivier Lamy
* @since 1.4-M1
*/
-@Service( "proxyConnectorAdmin#default" )
+@Service ( "proxyConnectorAdmin#default" )
public class DefaultProxyConnectorAdmin
extends AbstractRepositoryAdmin
implements ProxyConnectorAdmin
@@ -114,6 +114,7 @@ public class DefaultProxyConnectorAdmin
}
+ // FIXME take of proxyConnectorRules !
public Boolean deleteProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation )
throws RepositoryAdminException
{
@@ -133,6 +134,7 @@ public class DefaultProxyConnectorAdmin
return Boolean.TRUE;
}
+ // FIXME take of proxyConnectorRules !
public Boolean updateProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation )
throws RepositoryAdminException
{
@@ -206,21 +208,6 @@ public class DefaultProxyConnectorAdmin
protected ProxyConnectorConfiguration getProxyConnectorConfiguration( ProxyConnector proxyConnector )
{
- /*
- ProxyConnectorConfiguration proxyConnectorConfiguration = new ProxyConnectorConfiguration();
- proxyConnectorConfiguration.setOrder( proxyConnector.getOrder() );
- proxyConnectorConfiguration.setBlackListPatterns(
- new ArrayList<String>( proxyConnector.getBlackListPatterns() ) );
- proxyConnectorConfiguration.setWhiteListPatterns(
- new ArrayList<String>( proxyConnector.getWhiteListPatterns() ) );
- proxyConnectorConfiguration.setDisabled( proxyConnector.isDisabled() );
- proxyConnectorConfiguration.setPolicies( new HashMap( proxyConnector.getPolicies() ) );
- proxyConnectorConfiguration.setProperties( new HashMap( proxyConnector.getProperties() ) );
- proxyConnectorConfiguration.setProxyId( proxyConnector.getProxyId() );
- proxyConnectorConfiguration.setSourceRepoId( proxyConnector.getSourceRepoId() );
- proxyConnectorConfiguration.setTargetRepoId( proxyConnector.getTargetRepoId() );
- return proxyConnectorConfiguration;*/
-
return proxyConnector == null
? null
: new BeanReplicator().replicateBean( proxyConnector, ProxyConnectorConfiguration.class );
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/proxyconnectorrule/DefaultProxyConnectorRuleAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/proxyconnectorrule/DefaultProxyConnectorRuleAdmin.java
new file mode 100644
index 000000000..10f954a67
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/proxyconnectorrule/DefaultProxyConnectorRuleAdmin.java
@@ -0,0 +1,170 @@
+package org.apache.archiva.admin.repository.proxyconnectorrule;
+/*
+ * 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.AuditInformation;
+import org.apache.archiva.admin.model.RepositoryAdminException;
+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.admin.model.proxyconnectorrule.ProxyConnectorRuleAdmin;
+import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
+import org.apache.archiva.configuration.Configuration;
+import org.apache.archiva.configuration.ProxyConnectorConfiguration;
+import org.apache.archiva.configuration.ProxyConnectorRuleConfiguration;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author Olivier Lamy
+ * @since 1.4-M3
+ */
+@Service ( "proxyConnectorRuleAdmin#default" )
+public class DefaultProxyConnectorRuleAdmin
+ extends AbstractRepositoryAdmin
+ implements ProxyConnectorRuleAdmin
+{
+ private Logger log = LoggerFactory.getLogger( getClass() );
+
+ public List<ProxyConnectorRule> getProxyConnectorRules()
+ throws RepositoryAdminException
+ {
+ List<ProxyConnectorRuleConfiguration> proxyConnectorRuleConfigurations =
+ getArchivaConfiguration().getConfiguration().getProxyConnectorRuleConfigurations();
+ if ( proxyConnectorRuleConfigurations.isEmpty() )
+ {
+ return Collections.emptyList();
+ }
+ List<ProxyConnectorRule> proxyConnectorRules =
+ new ArrayList<ProxyConnectorRule>( proxyConnectorRuleConfigurations.size() );
+ for ( ProxyConnectorRuleConfiguration proxyConnectorRuleConfiguration : proxyConnectorRuleConfigurations )
+ {
+
+ ProxyConnectorRule proxyConnectorRule = new ProxyConnectorRule();
+ proxyConnectorRule.setPattern( proxyConnectorRuleConfiguration.getPattern() );
+ proxyConnectorRule.setProxyConnectorRuleType(
+ getProxyConnectorRuleType( proxyConnectorRuleConfiguration.getRuleType() ) );
+ for ( ProxyConnectorConfiguration proxyConnectorConfiguration : proxyConnectorRuleConfiguration.getProxyConnectors() )
+ {
+ ProxyConnector proxyConnector = new ProxyConnector();
+ proxyConnector.setSourceRepoId( proxyConnectorConfiguration.getSourceRepoId() );
+ proxyConnector.setTargetRepoId( proxyConnectorConfiguration.getTargetRepoId() );
+ proxyConnectorRule.getProxyConnectors().add( proxyConnector );
+ }
+ proxyConnectorRules.add( proxyConnectorRule );
+ }
+
+ return proxyConnectorRules;
+ }
+
+
+ private ProxyConnectorRuleType getProxyConnectorRuleType( String type )
+ {
+ if ( StringUtils.equals( ProxyConnectorRuleType.WHITE_LIST.getRuleType(), type ) )
+ {
+ return ProxyConnectorRuleType.WHITE_LIST;
+ }
+ if ( StringUtils.equals( ProxyConnectorRuleType.BLACK_LIST.getRuleType(), type ) )
+ {
+ return ProxyConnectorRuleType.BLACK_LIST;
+ }
+ return null;
+ }
+
+ public void addProxyConnectorRule( ProxyConnectorRule proxyConnectorRule, AuditInformation auditInformation )
+ throws RepositoryAdminException
+ {
+ ProxyConnectorRuleConfiguration proxyConnectorRuleConfiguration = new ProxyConnectorRuleConfiguration();
+ proxyConnectorRuleConfiguration.setPattern( proxyConnectorRule.getPattern() );
+ proxyConnectorRuleConfiguration.setRuleType( proxyConnectorRule.getProxyConnectorRuleType().getRuleType() );
+ for ( ProxyConnector proxyConnector : proxyConnectorRule.getProxyConnectors() )
+ {
+ ProxyConnectorConfiguration proxyConnectorConfiguration = new ProxyConnectorConfiguration();
+ proxyConnectorConfiguration.setSourceRepoId( proxyConnector.getSourceRepoId() );
+ proxyConnectorConfiguration.setTargetRepoId( proxyConnector.getTargetRepoId() );
+ proxyConnectorRuleConfiguration.getProxyConnectors().add( proxyConnectorConfiguration );
+ }
+ Configuration configuration = getArchivaConfiguration().getConfiguration();
+ configuration.getProxyConnectorRuleConfigurations().add( proxyConnectorRuleConfiguration );
+ saveConfiguration( configuration );
+ }
+
+ public void deleteProxyConnectorRule( ProxyConnectorRule proxyConnectorRule, AuditInformation auditInformation )
+ throws RepositoryAdminException
+ {
+ Configuration configuration = getArchivaConfiguration().getConfiguration();
+ // key is the pattern !!
+ // recreate a list without the pattern
+
+ boolean toSave = false;
+
+ List<ProxyConnectorRuleConfiguration> proxyConnectorRuleConfigurations =
+ new ArrayList<ProxyConnectorRuleConfiguration>();
+
+ for ( ProxyConnectorRuleConfiguration proxyConnectorRuleConfiguration : configuration.getProxyConnectorRuleConfigurations() )
+ {
+ if ( StringUtils.equals( proxyConnectorRuleConfiguration.getPattern(), proxyConnectorRule.getPattern() ) )
+ {
+ toSave = true;
+ }
+ else
+ {
+ proxyConnectorRuleConfigurations.add( proxyConnectorRuleConfiguration );
+ }
+ }
+
+ if ( toSave )
+ {
+ configuration.setProxyConnectorRuleConfigurations( proxyConnectorRuleConfigurations );
+ saveConfiguration( configuration );
+ }
+
+ }
+
+ public void updateProxyConnectorRule( ProxyConnectorRule proxyConnectorRule, AuditInformation auditInformation )
+ throws RepositoryAdminException
+ {
+ Configuration configuration = getArchivaConfiguration().getConfiguration();
+
+ for ( ProxyConnectorRuleConfiguration proxyConnectorRuleConfiguration : configuration.getProxyConnectorRuleConfigurations() )
+ {
+ if ( StringUtils.equals( proxyConnectorRuleConfiguration.getPattern(), proxyConnectorRule.getPattern() ) )
+ {
+ List<ProxyConnectorConfiguration> proxyConnectors =
+ new ArrayList<ProxyConnectorConfiguration>( proxyConnectorRule.getProxyConnectors().size() );
+ for ( ProxyConnector proxyConnector : proxyConnectorRule.getProxyConnectors() )
+ {
+ ProxyConnectorConfiguration proxyConnectorConfiguration = new ProxyConnectorConfiguration();
+ proxyConnectorConfiguration.setSourceRepoId( proxyConnector.getSourceRepoId() );
+ proxyConnectorConfiguration.setTargetRepoId( proxyConnector.getTargetRepoId() );
+ proxyConnectors.add( proxyConnectorConfiguration );
+ }
+ proxyConnectorRuleConfiguration.setProxyConnectors( proxyConnectors );
+ saveConfiguration( configuration );
+ }
+ }
+
+ }
+}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java
index 66ee8acf6..4a277f0ef 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java
@@ -25,6 +25,7 @@ import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.admin.model.beans.RemoteRepository;
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin;
+import org.apache.archiva.admin.model.proxyconnectorrule.ProxyConnectorRuleAdmin;
import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
import org.apache.archiva.redback.users.User;
import org.apache.commons.io.FileUtils;
@@ -68,6 +69,9 @@ public abstract class AbstractRepositoryAdminTest
@Inject
protected ProxyConnectorAdmin proxyConnectorAdmin;
+ @Inject
+ protected ProxyConnectorRuleAdmin proxyConnectorRuleAdmin;
+
protected AuditInformation getFakeAuditInformation()
{
AuditInformation auditInformation = new AuditInformation( getFakeUser(), "archiva-localhost" );
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/proxyconnectorrule/ProxyConnectorRuleAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/proxyconnectorrule/ProxyConnectorRuleAdminTest.java
new file mode 100644
index 000000000..9a9960059
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/proxyconnectorrule/ProxyConnectorRuleAdminTest.java
@@ -0,0 +1,180 @@
+package org.apache.archiva.admin.repository.proxyconnectorrule;
+/*
+ * 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.admin.model.beans.RemoteRepository;
+import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest;
+import org.junit.Test;
+
+import java.util.Arrays;
+
+/**
+ * @author Olivier Lamy
+ */
+public class ProxyConnectorRuleAdminTest
+ extends AbstractRepositoryAdminTest
+{
+ @Test
+ public void addProxyConnectorRule()
+ throws Exception
+ {
+ ProxyConnector proxyConnector = new ProxyConnector();
+ proxyConnector.setSourceRepoId( "snapshots" );
+ proxyConnector.setTargetRepoId( "central" );
+
+ ProxyConnectorRule rule = null;
+ try
+ {
+ int size = proxyConnectorRuleAdmin.getProxyConnectorRules().size();
+ assertEquals( 0, size );
+
+ proxyConnectorAdmin.addProxyConnector( proxyConnector, getFakeAuditInformation() );
+
+ rule = new ProxyConnectorRule( "org/apache/maven", ProxyConnectorRuleType.BLACK_LIST,
+ Arrays.asList( proxyConnector ) );
+
+ proxyConnectorRuleAdmin.addProxyConnectorRule( rule, getFakeAuditInformation() );
+ assertEquals( size + 1, proxyConnectorRuleAdmin.getProxyConnectorRules().size() );
+
+ rule = proxyConnectorRuleAdmin.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
+ {
+ proxyConnectorRuleAdmin.deleteProxyConnectorRule( rule, getFakeAuditInformation() );
+ proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getFakeAuditInformation() );
+ }
+ }
+
+ @Test
+ public void addProxyConnectorRuleWithTwoProxyConnectors()
+ throws Exception
+ {
+ RemoteRepository remoteRepository = new RemoteRepository();
+ remoteRepository.setId( "archiva" );
+ remoteRepository.setName( "archiva rocks" );
+ remoteRepository.setUrl( "http://wine.org" );
+
+ remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() );
+
+ int size = proxyConnectorRuleAdmin.getProxyConnectorRules().size();
+ assertEquals( 0, size );
+ ProxyConnector proxyConnector1 = new ProxyConnector();
+ proxyConnector1.setSourceRepoId( "snapshots" );
+ proxyConnector1.setTargetRepoId( "central" );
+ proxyConnectorAdmin.addProxyConnector( proxyConnector1, getFakeAuditInformation() );
+
+ ProxyConnector proxyConnector2 = new ProxyConnector();
+ proxyConnector2.setSourceRepoId( "snapshots" );
+ proxyConnector2.setTargetRepoId( "archiva" );
+ proxyConnectorAdmin.addProxyConnector( proxyConnector2, getFakeAuditInformation() );
+
+ ProxyConnectorRule rule = new ProxyConnectorRule( "org/apache/maven", ProxyConnectorRuleType.BLACK_LIST,
+ Arrays.asList( proxyConnector1, proxyConnector2 ) );
+ try
+ {
+ proxyConnectorRuleAdmin.addProxyConnectorRule( rule, getFakeAuditInformation() );
+ assertEquals( size + 1, proxyConnectorRuleAdmin.getProxyConnectorRules().size() );
+
+ rule = proxyConnectorRuleAdmin.getProxyConnectorRules().get( 0 );
+
+ assertEquals( "org/apache/maven", rule.getPattern() );
+ assertEquals( 2, rule.getProxyConnectors().size() );
+ assertEquals( ProxyConnectorRuleType.BLACK_LIST, rule.getProxyConnectorRuleType() );
+ }
+ finally
+ {
+ proxyConnectorRuleAdmin.deleteProxyConnectorRule( rule, getFakeAuditInformation() );
+ proxyConnectorAdmin.deleteProxyConnector( proxyConnector1, getFakeAuditInformation() );
+ proxyConnectorAdmin.deleteProxyConnector( proxyConnector2, getFakeAuditInformation() );
+ remoteRepositoryAdmin.deleteRemoteRepository( remoteRepository.getId(), getFakeAuditInformation() );
+ }
+ }
+
+
+ @Test
+ public void updateProxyConnectorRuleWithTwoProxyConnectors()
+ throws Exception
+ {
+ RemoteRepository remoteRepository = new RemoteRepository();
+ remoteRepository.setId( "archiva" );
+ remoteRepository.setName( "archiva rocks" );
+ remoteRepository.setUrl( "http://wine.org" );
+
+ remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() );
+
+ int size = proxyConnectorRuleAdmin.getProxyConnectorRules().size();
+ assertEquals( 0, size );
+ ProxyConnector proxyConnector1 = new ProxyConnector();
+ proxyConnector1.setSourceRepoId( "snapshots" );
+ proxyConnector1.setTargetRepoId( "central" );
+ proxyConnectorAdmin.addProxyConnector( proxyConnector1, getFakeAuditInformation() );
+
+ ProxyConnector proxyConnector2 = new ProxyConnector();
+ proxyConnector2.setSourceRepoId( "snapshots" );
+ proxyConnector2.setTargetRepoId( "archiva" );
+ proxyConnectorAdmin.addProxyConnector( proxyConnector2, getFakeAuditInformation() );
+
+ ProxyConnectorRule rule = new ProxyConnectorRule( "org/apache/maven", ProxyConnectorRuleType.BLACK_LIST,
+ Arrays.asList( proxyConnector1, proxyConnector2 ) );
+ try
+ {
+ proxyConnectorRuleAdmin.addProxyConnectorRule( rule, getFakeAuditInformation() );
+ assertEquals( size + 1, proxyConnectorRuleAdmin.getProxyConnectorRules().size() );
+
+ rule = proxyConnectorRuleAdmin.getProxyConnectorRules().get( 0 );
+
+ assertEquals( "org/apache/maven", rule.getPattern() );
+ assertEquals( 2, rule.getProxyConnectors().size() );
+ //assertEquals( "snapshots", rule.getProxyConnectors().get( 0 ).getSourceRepoId() );
+ //assertEquals( "central", rule.getProxyConnectors().get( 0 ).getTargetRepoId() );
+ assertEquals( ProxyConnectorRuleType.BLACK_LIST, rule.getProxyConnectorRuleType() );
+
+ rule.setProxyConnectors( Arrays.asList( proxyConnector1 ) );
+
+ proxyConnectorRuleAdmin.updateProxyConnectorRule( rule, getFakeAuditInformation() );
+
+ assertEquals( size + 1, proxyConnectorRuleAdmin.getProxyConnectorRules().size() );
+
+ rule = proxyConnectorRuleAdmin.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() );
+
+ }
+ finally
+ {
+ proxyConnectorRuleAdmin.deleteProxyConnectorRule( rule, getFakeAuditInformation() );
+ proxyConnectorAdmin.deleteProxyConnector( proxyConnector1, getFakeAuditInformation() );
+ proxyConnectorAdmin.deleteProxyConnector( proxyConnector2, getFakeAuditInformation() );
+ remoteRepositoryAdmin.deleteRemoteRepository( remoteRepository.getId(), getFakeAuditInformation() );
+ }
+ }
+
+}