]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1681] addProxy Connectors Rules screen
authorOlivier Lamy <olamy@apache.org>
Tue, 2 Oct 2012 15:12:16 +0000 (15:12 +0000)
committerOlivier Lamy <olamy@apache.org>
Tue, 2 Oct 2012 15:12:16 +0000 (15:12 +0000)
implements backend part.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1392951 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ProxyConnectorRule.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/ProxyConnectorRuleType.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/proxyconnector/ProxyConnectorAdmin.java
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/proxyconnectorrule/ProxyConnectorRuleAdmin.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/proxyconnector/DefaultProxyConnectorAdmin.java
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/proxyconnectorrule/DefaultProxyConnectorRuleAdmin.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/proxyconnectorrule/ProxyConnectorRuleAdminTest.java [new file with mode: 0644]
archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/MockRepoAdmin.java

index 3d6365d77f6ae245334c03bbc58cf054a332eadf..447949500c89b92ff3dac644267d7eeb25def619 100644 (file)
             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>
       </codeSegments>
     </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>
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 (file)
index 0000000..f672bee
--- /dev/null
@@ -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 (file)
index 0000000..4eaf6fd
--- /dev/null
@@ -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();
+    }
+}
index f06a1e6eac886fce7b397fa063cc9e9364a20eb6..256633d4964bd705b40080169e58acfdabad8e73 100644 (file)
@@ -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 (file)
index 0000000..d7d7cef
--- /dev/null
@@ -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;
+}
index 525ae7d5632630a00a9f27f50cae3779d09842e8..f7ff3f9d60a298eae49adbfe43fac58f31fe4d56 100644 (file)
@@ -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 (file)
index 0000000..10f954a
--- /dev/null
@@ -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 );
+            }
+        }
+
+    }
+}
index 66ee8acf6e9ec6b0f584f9b1de4c7a7f69d9898d..4a277f0ef23e276d9cd227236127ed97090fca09 100644 (file)
@@ -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 (file)
index 0000000..9a99600
--- /dev/null
@@ -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() );
+        }
+    }
+
+}
index fe6a4a557a379b378a66f6ec489e2d91f1553ec2..3a5e991aa059d508f52471c4a6e398cb6b7e345e 100644 (file)
@@ -24,6 +24,7 @@ import org.apache.archiva.admin.model.RepositoryAdminException;
 import org.apache.archiva.admin.model.beans.ManagedRepository;
 import org.apache.archiva.admin.model.beans.NetworkProxy;
 import org.apache.archiva.admin.model.beans.ProxyConnector;
+import org.apache.archiva.admin.model.beans.ProxyConnectorRule;
 import org.apache.archiva.admin.model.beans.RemoteRepository;
 import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
 import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin;
@@ -51,7 +52,7 @@ public class MockRepoAdmin
     implements RemoteRepositoryAdmin, ManagedRepositoryAdmin, ProxyConnectorAdmin, NetworkProxyAdmin
 {
     @Inject
-    @Named( value = "archivaConfiguration#test" )
+    @Named (value = "archivaConfiguration#test")
     private ArchivaConfiguration archivaConfiguration;
 
     public List<RemoteRepository> getRemoteRepositories()
@@ -280,4 +281,28 @@ public class MockRepoAdmin
             ? null
             : new BeanReplicator().replicateBean( proxyConnectorConfiguration, ProxyConnector.class );
     }
+
+    public List<ProxyConnectorRule> getProxyConnectorRules()
+        throws RepositoryAdminException
+    {
+        return null;
+    }
+
+    public void addProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
+        throws RepositoryAdminException
+    {
+
+    }
+
+    public void deleteProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
+        throws RepositoryAdminException
+    {
+
+    }
+
+    public void updateProxyConnectorRule( ProxyConnectorRule proxyConnectorRule )
+        throws RepositoryAdminException
+    {
+
+    }
 }