]> source.dussan.org Git - archiva.git/commitdiff
use beanlib for wrappers constructions
authorOlivier Lamy <olamy@apache.org>
Wed, 7 Sep 2011 20:33:48 +0000 (20:33 +0000)
committerOlivier Lamy <olamy@apache.org>
Wed, 7 Sep 2011 20:33:48 +0000 (20:33 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1166391 13f79535-47bb-0310-9956-ffa450edef68

13 files changed:
archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/ProxyConnectorConfigurationOrderComparator.java
archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/ProxyConnectorSelectionPredicate.java
archiva-modules/archiva-base/archiva-repository-admin/pom.xml
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/DefaultProxyConnectorAdmin.java
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorAdmin.java
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorOrderComparator.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorSelectionPredicate.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/remote/RemoteRepositoryAdmin.java
archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorAdminTest.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorFormAction.java
pom.xml

index 6d5923446fc1df3dca47943bd7bd82ccb35a0832..2f7deddeeb6df2e67e541b2dbd4ca3160ebdc45e 100644 (file)
@@ -24,8 +24,7 @@ import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
 
 /**
- * ProxyConnectorPredicate 
- *
+ * ProxyConnectorPredicate
  * @version $Id$
  */
 public class ProxyConnectorSelectionPredicate
index 43abeecdc59a2464e5eff2cfae9b5a93aa85f78a..2efa25bd26e333e73182f976af1a5b8b4b8483cd 100644 (file)
     <dependency>
       <groupId>javax.inject</groupId>
       <artifactId>javax.inject</artifactId>
-      <version>1</version>
+    </dependency>
+    <dependency>
+      <groupId>net.sf.beanlib</groupId>
+      <artifactId>beanlib</artifactId>
     </dependency>
     <dependency>
       <groupId>org.springframework</groupId>
index 03ae1dfb92220906bb1fd1cb482704829cc176f9..d49e807441ef184685df6d6d27d3a6e9ed575974 100644 (file)
@@ -18,6 +18,7 @@ package org.apache.archiva.admin.repository.proxyconnector;
  * under the License.
  */
 
+import net.sf.beanlib.provider.replicator.BeanReplicator;
 import org.apache.archiva.admin.AuditInformation;
 import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
 import org.apache.archiva.admin.repository.RepositoryAdminException;
@@ -33,8 +34,11 @@ import org.springframework.stereotype.Service;
 
 import javax.inject.Inject;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author Olivier Lamy
@@ -150,8 +154,42 @@ public class DefaultProxyConnectorAdmin
         return rawPatterns;
     }
 
-    protected ProxyConnectorConfiguration findProxyConnector( String sourceId, String targetId,
-                                                              Configuration configuration )
+    public Map<String, List<ProxyConnector>> getProxyConnectorAsMap()
+        throws RepositoryAdminException
+    {
+        java.util.Map<String, List<ProxyConnector>> proxyConnectorMap =
+            new HashMap<String, java.util.List<ProxyConnector>>();
+
+        Iterator<ProxyConnector> it = getProxyConnectors().iterator();
+        while ( it.hasNext() )
+        {
+            ProxyConnector proxyConfig = it.next();
+            String key = proxyConfig.getSourceRepoId();
+
+            java.util.List<ProxyConnector> connectors = proxyConnectorMap.get( key );
+            if ( connectors == null )
+            {
+                connectors = new ArrayList<ProxyConnector>();
+                proxyConnectorMap.put( key, connectors );
+            }
+
+            connectors.add( proxyConfig );
+
+            Collections.sort( connectors, ProxyConnectorOrderComparator.getInstance() );
+        }
+
+        return proxyConnectorMap;
+    }
+
+    public ProxyConnector findProxyConnector( String sourceId, String targetId )
+        throws RepositoryAdminException
+    {
+        return getProxyConnector(
+            findProxyConnector( sourceId, targetId, getArchivaConfiguration().getConfiguration() ) );
+    }
+
+    private ProxyConnectorConfiguration findProxyConnector( String sourceId, String targetId,
+                                                            Configuration configuration )
     {
         if ( StringUtils.isBlank( sourceId ) )
         {
@@ -169,6 +207,7 @@ public class DefaultProxyConnectorAdmin
 
     protected ProxyConnectorConfiguration getProxyConnectorConfiguration( ProxyConnector proxyConnector )
     {
+        /*
         ProxyConnectorConfiguration proxyConnectorConfiguration = new ProxyConnectorConfiguration();
         proxyConnectorConfiguration.setOrder( proxyConnector.getOrder() );
         proxyConnectorConfiguration.setBlackListPatterns(
@@ -181,7 +220,13 @@ public class DefaultProxyConnectorAdmin
         proxyConnectorConfiguration.setProxyId( proxyConnector.getProxyId() );
         proxyConnectorConfiguration.setSourceRepoId( proxyConnector.getSourceRepoId() );
         proxyConnectorConfiguration.setTargetRepoId( proxyConnector.getTargetRepoId() );
-        return proxyConnectorConfiguration;
+        return proxyConnectorConfiguration;*/
+        return new BeanReplicator().replicateBean( proxyConnector, ProxyConnectorConfiguration.class );
+    }
+
+    protected ProxyConnector getProxyConnector( ProxyConnectorConfiguration proxyConnectorConfiguration )
+    {
+        return new BeanReplicator().replicateBean( proxyConnectorConfiguration, ProxyConnector.class );
     }
 
     protected void validateProxyConnector( ProxyConnector proxyConnector )
index e598eb28f9868f486033b72085356f7912969c4e..2eae5da1f8fe6d0528e969876da823aad73302fe 100644 (file)
@@ -22,6 +22,7 @@ import org.apache.archiva.admin.AuditInformation;
 import org.apache.archiva.admin.repository.RepositoryAdminException;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * No update method here as id is : sourceRepoId and targetRepoId, use delete then add.
@@ -43,4 +44,10 @@ public interface ProxyConnectorAdmin
     Boolean deleteProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation )
         throws RepositoryAdminException;
 
+    Map<String, List<ProxyConnector>> getProxyConnectorAsMap()
+        throws RepositoryAdminException;
+
+    ProxyConnector findProxyConnector( String sourceId, String targetId )
+        throws RepositoryAdminException;
+
 }
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorOrderComparator.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorOrderComparator.java
new file mode 100644 (file)
index 0000000..3f8b0d0
--- /dev/null
@@ -0,0 +1,68 @@
+package org.apache.archiva.admin.repository.proxyconnector;
+/*
+ * 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 java.util.Comparator;
+
+/**
+ * @author Olivier Lamy
+ * @since 1.4
+ */
+public class ProxyConnectorOrderComparator
+    implements Comparator<ProxyConnector>
+{
+    private static ProxyConnectorOrderComparator INSTANCE = new ProxyConnectorOrderComparator();
+
+    public int compare( ProxyConnector o1, ProxyConnector o2 )
+    {
+        if ( o1 == null && o2 == null )
+        {
+            return 0;
+        }
+
+        // Ensure null goes to end of list.
+        if ( o1 == null && o2 != null )
+        {
+            return 1;
+        }
+
+        if ( o1 != null && o2 == null )
+        {
+            return -1;
+        }
+
+        // Ensure 0 (unordered) goes to end of list.
+        if ( o1.getOrder() == 0 && o2.getOrder() != 0 )
+        {
+            return 1;
+        }
+
+        if ( o1.getOrder() != 0 && o2.getOrder() == 0 )
+        {
+            return -1;
+        }
+
+        return o1.getOrder() - o2.getOrder();
+    }
+
+    public static ProxyConnectorOrderComparator getInstance()
+    {
+        return INSTANCE;
+    }
+}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorSelectionPredicate.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/proxyconnector/ProxyConnectorSelectionPredicate.java
new file mode 100644 (file)
index 0000000..01983b7
--- /dev/null
@@ -0,0 +1,54 @@
+package org.apache.archiva.admin.repository.proxyconnector;
+/*
+ * 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.commons.collections.Predicate;
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * @author Olivier Lamy
+ * @since 1.4
+ */
+public class ProxyConnectorSelectionPredicate
+    implements Predicate
+{
+    private String sourceId;
+
+    private String targetId;
+
+    public ProxyConnectorSelectionPredicate( String sourceId, String targetId )
+    {
+        this.sourceId = sourceId;
+        this.targetId = targetId;
+    }
+
+    public boolean evaluate( Object object )
+    {
+        boolean satisfies = false;
+
+        if ( object instanceof ProxyConnector )
+        {
+            ProxyConnector connector = (ProxyConnector) object;
+            return ( StringUtils.equals( sourceId, connector.getSourceRepoId() ) && StringUtils.equals( targetId,
+                                                                                                        connector.getTargetRepoId() ) );
+        }
+
+        return satisfies;
+    }
+}
index 732a479a01db7579983ebd72895b59698abf30eb..a2c83a4739672c9947f80e0db31c54ace0e6ad44 100644 (file)
@@ -29,7 +29,9 @@ import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author Olivier Lamy
@@ -159,6 +161,19 @@ public class DefaultRemoteRepositoryAdmin
         return Boolean.TRUE;
     }
 
+    public Map<String, RemoteRepository> getRemoteRepositoriesAsMap()
+        throws RepositoryAdminException
+    {
+        java.util.Map<String, RemoteRepository> map = new HashMap<String, RemoteRepository>();
+
+        for ( RemoteRepository repo : getRemoteRepositories() )
+        {
+            map.put( repo.getId(), repo );
+        }
+
+        return map;
+    }
+
     private RemoteRepositoryConfiguration getRemoteRepositoryConfiguration( RemoteRepository remoteRepository )
     {
         RemoteRepositoryConfiguration remoteRepositoryConfiguration = new RemoteRepositoryConfiguration();
index 3adde318ff92d85a3d40ffe1aa651a0b15f7418d..15218ba8d60f905314fb494b975fecb69b83e271 100644 (file)
@@ -23,6 +23,7 @@ import org.apache.archiva.admin.AuditInformation;
 import org.apache.archiva.admin.repository.RepositoryAdminException;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author Olivier Lamy
@@ -44,4 +45,7 @@ public interface RemoteRepositoryAdmin
 
     Boolean updateRemoteRepository( RemoteRepository remoteRepository, AuditInformation auditInformation )
         throws RepositoryAdminException;
+
+    Map<String, RemoteRepository> getRemoteRepositoriesAsMap()
+        throws RepositoryAdminException;
 }
index 4cedef2b0e74821748df8a42a8aee3c7bbcc69eb..97b0b12d3916fe31b821493078849879dab92215 100644 (file)
@@ -23,6 +23,8 @@ import org.apache.archiva.admin.repository.remote.RemoteRepository;
 import org.apache.archiva.audit.AuditEvent;
 import org.junit.Test;
 
+import java.util.Arrays;
+
 /**
  * @author Olivier Lamy
  */
@@ -81,12 +83,15 @@ public class ProxyConnectorAdminTest
         ProxyConnector proxyConnector = new ProxyConnector();
         proxyConnector.setSourceRepoId( "snapshots" );
         proxyConnector.setTargetRepoId( "central" );
+        proxyConnector.setWhiteListPatterns( Arrays.asList( "foo", "bar" ) );
         proxyConnectorAdmin.addProxyConnector( proxyConnector, getFakeAuditInformation() );
 
         assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
         assertEquals( 3, proxyConnectorAdmin.getProxyConnectors().size() );
 
         assertNotNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
+        assertEquals( Arrays.asList( "foo", "bar" ),
+                      proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ).getWhiteListPatterns() );
 
         proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getFakeAuditInformation() );
 
@@ -123,4 +128,12 @@ public class ProxyConnectorAdminTest
         mockAuditListener.clearEvents();
     }
 
+    @Test
+    public void findProxyConnector()
+        throws Exception
+    {
+        ProxyConnector proxyConnector = proxyConnectorAdmin.findProxyConnector( "internal", "central" );
+        assertNotNull( proxyConnector );
+    }
+
 }
index 979c6b88fd0766dfc4d68cd5b43a51a70ff14a95..bf5729cff77ef5c87da5344d799336262dc2ee79 100644 (file)
@@ -19,29 +19,25 @@ package org.apache.maven.archiva.web.action.admin.connectors.proxy;
  * under the License.
  */
 
+import org.apache.archiva.admin.repository.RepositoryAdminException;
+import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin;
+import org.apache.archiva.admin.repository.proxyconnector.ProxyConnector;
+import org.apache.archiva.admin.repository.proxyconnector.ProxyConnectorAdmin;
+import org.apache.archiva.admin.repository.remote.RemoteRepositoryAdmin;
 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.ProxyConnectorConfiguration;
-import org.apache.maven.archiva.configuration.functors.ProxyConnectorSelectionPredicate;
 import org.apache.maven.archiva.web.action.AbstractActionSupport;
 import org.codehaus.plexus.redback.rbac.Resource;
-import org.codehaus.plexus.registry.RegistryException;
-
-import java.util.List;
-import java.util.Map;
 import org.codehaus.redback.integration.interceptor.SecureAction;
 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
 import org.codehaus.redback.integration.interceptor.SecureActionException;
 
 import javax.inject.Inject;
+import java.util.List;
+import java.util.Map;
 
 /**
- * AbstractProxyConnectorAction 
+ * AbstractProxyConnectorAction
  *
  * @version $Id$
  */
@@ -52,7 +48,13 @@ public abstract class AbstractProxyConnectorAction
     public static final String DIRECT_CONNECTION = "(direct connection)";
 
     @Inject
-    protected ArchivaConfiguration archivaConfiguration;
+    private ProxyConnectorAdmin proxyConnectorAdmin;
+
+    @Inject
+    private RemoteRepositoryAdmin remoteRepositoryAdmin;
+
+    @Inject
+    private ManagedRepositoryAdmin managedRepositoryAdmin;
 
     public SecureActionBundle getSecureActionBundle()
         throws SecureActionException
@@ -65,17 +67,15 @@ public abstract class AbstractProxyConnectorAction
         return bundle;
     }
 
-    public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
-    {
-        this.archivaConfiguration = archivaConfiguration;
-    }
 
-    protected void addProxyConnector( ProxyConnectorConfiguration proxyConnector )
+    protected void addProxyConnector( ProxyConnector proxyConnector )
+        throws RepositoryAdminException
     {
-        getConfig().addProxyConnector( proxyConnector );
+        getProxyConnectorAdmin().addProxyConnector( proxyConnector, getAuditInformation() );
     }
 
-    protected ProxyConnectorConfiguration findProxyConnector( String sourceId, String targetId )
+    protected ProxyConnector findProxyConnector( String sourceId, String targetId )
+        throws RepositoryAdminException
     {
         if ( StringUtils.isBlank( sourceId ) )
         {
@@ -87,50 +87,59 @@ public abstract class AbstractProxyConnectorAction
             return null;
         }
 
-        ProxyConnectorSelectionPredicate selectedProxy = new ProxyConnectorSelectionPredicate( sourceId, targetId );
-        return (ProxyConnectorConfiguration) CollectionUtils.find( getConfig().getProxyConnectors(), selectedProxy );
+        return getProxyConnectorAdmin().findProxyConnector( sourceId, targetId );
     }
 
-    protected Configuration getConfig()
+    protected Map<String, List<ProxyConnector>> createProxyConnectorMap()
+        throws RepositoryAdminException
     {
-        return this.archivaConfiguration.getConfiguration();
+        return getProxyConnectorAdmin().getProxyConnectorAsMap();
     }
 
-    protected Map<String, List<ProxyConnectorConfiguration>> createProxyConnectorMap()
+    protected void removeConnector( String sourceId, String targetId )
+        throws RepositoryAdminException
     {
-        return getConfig().getProxyConnectorAsMap();
+        ProxyConnector proxyConnector = findProxyConnector( sourceId, targetId );
+        if ( proxyConnector != null )
+        {
+            getProxyConnectorAdmin().deleteProxyConnector( proxyConnector, getAuditInformation() );
+        }
     }
 
-    protected void removeConnector( String sourceId, String targetId )
+    protected void removeProxyConnector( ProxyConnector connector )
+        throws RepositoryAdminException
     {
-        ProxyConnectorSelectionPredicate selectedProxy = new ProxyConnectorSelectionPredicate( sourceId, targetId );
-        NotPredicate notSelectedProxy = new NotPredicate( selectedProxy );
-        CollectionUtils.filter( getConfig().getProxyConnectors(), notSelectedProxy );
+        getProxyConnectorAdmin().deleteProxyConnector( connector, getAuditInformation() );
     }
 
-    protected void removeProxyConnector( ProxyConnectorConfiguration connector )
+
+    public ProxyConnectorAdmin getProxyConnectorAdmin()
     {
-        getConfig().removeProxyConnector( connector );
+        return proxyConnectorAdmin;
     }
 
-    protected String saveConfiguration()
+    public void setProxyConnectorAdmin( ProxyConnectorAdmin proxyConnectorAdmin )
     {
-        try
-        {
-            archivaConfiguration.save( getConfig() );
-            addActionMessage( "Successfully saved configuration" );
-        }
-        catch ( RegistryException e )
-        {
-            addActionError( "Unable to save configuration: " + e.getMessage() );
-            return INPUT;
-        }
-        catch ( IndeterminateConfigurationException e )
-        {
-            addActionError( e.getMessage() );
-            return INPUT;
-        }
+        this.proxyConnectorAdmin = proxyConnectorAdmin;
+    }
+
+    public RemoteRepositoryAdmin getRemoteRepositoryAdmin()
+    {
+        return remoteRepositoryAdmin;
+    }
+
+    public void setRemoteRepositoryAdmin( RemoteRepositoryAdmin remoteRepositoryAdmin )
+    {
+        this.remoteRepositoryAdmin = remoteRepositoryAdmin;
+    }
 
-        return SUCCESS;
+    public ManagedRepositoryAdmin getManagedRepositoryAdmin()
+    {
+        return managedRepositoryAdmin;
+    }
+
+    public void setManagedRepositoryAdmin( ManagedRepositoryAdmin managedRepositoryAdmin )
+    {
+        this.managedRepositoryAdmin = managedRepositoryAdmin;
     }
 }
index e5f05fdda4cefa5cc1c675ad712a215f26a91cca..5a44dea368368301a8cd751d59111504fa6a646b 100644 (file)
@@ -19,27 +19,26 @@ package org.apache.maven.archiva.web.action.admin.connectors.proxy;
  * under the License.
  */
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import com.google.common.collect.Lists;
-import org.apache.archiva.audit.AuditListener;
+import com.opensymphony.xwork2.Preparable;
+import org.apache.archiva.admin.repository.RepositoryAdminException;
+import org.apache.archiva.admin.repository.proxyconnector.ProxyConnector;
 import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
+import org.apache.maven.archiva.configuration.ArchivaConfiguration;
 import org.apache.maven.archiva.policies.DownloadErrorPolicy;
 import org.apache.maven.archiva.policies.Policy;
 import org.apache.maven.archiva.policies.PostDownloadPolicy;
 import org.apache.maven.archiva.policies.PreDownloadPolicy;
 
-import com.opensymphony.xwork2.Preparable;
-
 import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
- * AbstractProxyConnectorFormAction - generic fields and methods for either add or edit actions related with the 
- * Proxy Connector. 
+ * AbstractProxyConnectorFormAction - generic fields and methods for either add or edit actions related with the
+ * Proxy Connector.
  *
  * @version $Id$
  */
@@ -94,8 +93,10 @@ public abstract class AbstractProxyConnectorFormAction
     /**
      * The model for this action.
      */
-    protected ProxyConnectorConfiguration connector;
+    protected ProxyConnector connector;
 
+    @Inject
+    private ArchivaConfiguration archivaConfiguration;
 
     @PostConstruct
     public void initialize()
@@ -107,38 +108,38 @@ public abstract class AbstractProxyConnectorFormAction
     }
 
     protected List<String> escapePatterns( List<String> patterns )
-    {   
+    {
         List<String> escapedPatterns = new ArrayList<String>();
-        if( patterns != null )
+        if ( patterns != null )
         {
-            for( String pattern : patterns )
+            for ( String pattern : patterns )
             {
                 escapedPatterns.add( StringUtils.replace( pattern, "\\", "\\\\" ) );
             }
         }
-        
+
         return escapedPatterns;
     }
-    
+
     protected List<String> unescapePatterns( List<String> patterns )
     {
         List<String> rawPatterns = new ArrayList<String>();
-        if( patterns != null )
+        if ( patterns != null )
         {
-            for( String pattern : patterns )
+            for ( String pattern : patterns )
             {
                 rawPatterns.add( StringUtils.replace( pattern, "\\\\", "\\" ) );
             }
         }
-        
+
         return rawPatterns;
     }
-    
+
     private String escapePattern( String pattern )
     {
         return StringUtils.replace( pattern, "\\", "\\\\" );
     }
-        
+
     public String addBlackListPattern()
     {
         String pattern = getBlackListPattern();
@@ -147,17 +148,17 @@ public abstract class AbstractProxyConnectorFormAction
         {
             addActionError( "Cannot add a blank black list pattern." );
         }
-        
+
         if ( !hasActionErrors() )
         {
             getConnector().getBlackListPatterns().add( escapePattern( pattern ) );
             setBlackListPattern( null );
         }
-        
+
         return INPUT;
     }
 
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings( "unchecked" )
     public String addProperty()
     {
         String key = getPropertyKey();
@@ -197,7 +198,7 @@ public abstract class AbstractProxyConnectorFormAction
             getConnector().getWhiteListPatterns().add( escapePattern( pattern ) );
             setWhiteListPattern( null );
         }
-        
+
         return INPUT;
     }
 
@@ -206,7 +207,7 @@ public abstract class AbstractProxyConnectorFormAction
         return blackListPattern;
     }
 
-    public ProxyConnectorConfiguration getConnector()
+    public ProxyConnector getConnector()
     {
         return connector;
     }
@@ -252,6 +253,7 @@ public abstract class AbstractProxyConnectorFormAction
     }
 
     public void prepare()
+        throws RepositoryAdminException
     {
         proxyIdOptions = createNetworkProxyOptions();
         managedRepoIdList = createManagedRepoOptions();
@@ -262,14 +264,14 @@ public abstract class AbstractProxyConnectorFormAction
     public String removeBlackListPattern()
     {
         String pattern = getPattern();
-        
+
         if ( StringUtils.isBlank( pattern ) )
         {
             addActionError( "Cannot remove a blank black list pattern." );
         }
 
-        if ( !getConnector().getBlackListPatterns().contains( pattern ) && 
-            !getConnector().getBlackListPatterns().contains( StringUtils.replace( pattern, "\\", "\\\\" ) ) )
+        if ( !getConnector().getBlackListPatterns().contains( pattern )
+            && !getConnector().getBlackListPatterns().contains( StringUtils.replace( pattern, "\\", "\\\\" ) ) )
         {
             addActionError( "Non-existant black list pattern [" + pattern + "], no black list pattern removed." );
         }
@@ -319,8 +321,8 @@ public abstract class AbstractProxyConnectorFormAction
             addActionError( "Cannot remove a blank white list pattern." );
         }
 
-        if ( !getConnector().getWhiteListPatterns().contains( pattern ) &&
-                !getConnector().getWhiteListPatterns().contains( StringUtils.replace( pattern, "\\", "\\\\" ) ) )
+        if ( !getConnector().getWhiteListPatterns().contains( pattern )
+            && !getConnector().getWhiteListPatterns().contains( StringUtils.replace( pattern, "\\", "\\\\" ) ) )
         {
             addActionError( "Non-existant white list pattern [" + pattern + "], no white list pattern removed." );
         }
@@ -341,7 +343,7 @@ public abstract class AbstractProxyConnectorFormAction
         this.blackListPattern = blackListPattern;
     }
 
-    public void setConnector( ProxyConnectorConfiguration connector )
+    public void setConnector( ProxyConnector connector )
     {
         this.connector = connector;
     }
@@ -387,8 +389,9 @@ public abstract class AbstractProxyConnectorFormAction
     }
 
     protected List<String> createManagedRepoOptions()
+        throws RepositoryAdminException
     {
-        return new ArrayList<String>( getConfig().getManagedRepositoriesAsMap().keySet() );
+        return new ArrayList<String>( getManagedRepositoryAdmin().getManagedRepositoriesAsMap().keySet() );
     }
 
     protected List<String> createNetworkProxyOptions()
@@ -396,7 +399,7 @@ public abstract class AbstractProxyConnectorFormAction
         List<String> options = new ArrayList<String>();
 
         options.add( DIRECT_CONNECTION );
-        options.addAll( getConfig().getNetworkProxiesAsMap().keySet() );
+        options.addAll( archivaConfiguration.getConfiguration().getNetworkProxiesAsMap().keySet() );
 
         return options;
     }
@@ -413,11 +416,12 @@ public abstract class AbstractProxyConnectorFormAction
     }
 
     protected List<String> createRemoteRepoOptions()
+        throws RepositoryAdminException
     {
-        return new ArrayList<String>( getConfig().getRemoteRepositoriesAsMap().keySet() );
+        return new ArrayList<String>( getRemoteRepositoryAdmin().getRemoteRepositoriesAsMap().keySet() );
     }
 
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings( "unchecked" )
     protected void validateConnector()
     {
         if ( connector.getPolicies() == null )
@@ -439,8 +443,8 @@ public abstract class AbstractProxyConnectorFormAction
                     continue;
                 }
 
-                Map<String, Object> properties = connector.getProperties();
-                for ( Map.Entry<String, Object> entry2 : properties.entrySet())
+                Map<String, String> properties = connector.getProperties();
+                for ( Map.Entry<String, String> entry2 : properties.entrySet() )
                 {
                     Object value = entry2.getValue();
                     if ( value.getClass().isArray() )
@@ -473,11 +477,21 @@ public abstract class AbstractProxyConnectorFormAction
 
                 if ( !options.contains( value ) )
                 {
-                    addActionError( "Value of [" + value + "] is invalid for policy [" + policyId + "], valid values: "
-                        + options );
+                    addActionError(
+                        "Value of [" + value + "] is invalid for policy [" + policyId + "], valid values: " + options );
                     continue;
                 }
             }
         }
     }
+
+    public ArchivaConfiguration getArchivaConfiguration()
+    {
+        return archivaConfiguration;
+    }
+
+    public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
+    {
+        this.archivaConfiguration = archivaConfiguration;
+    }
 }
diff --git a/pom.xml b/pom.xml
index bb08b6e55ed190bc0e2e5a5197112341cff4fb91..135ccf5223eda2a916625976a568fcac078ea8e9 100644 (file)
--- a/pom.xml
+++ b/pom.xml
         <artifactId>stax</artifactId>
         <version>1.2.0</version>
       </dependency>
+      <dependency>
+        <groupId>net.sf.beanlib</groupId>
+        <artifactId>beanlib</artifactId>
+        <version>5.0.2beta</version>
+      </dependency>
       <dependency>
         <groupId>commons-codec</groupId>
         <artifactId>commons-codec</artifactId>