]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1579] rewrite repositories scanning admin page
authorOlivier Lamy <olamy@apache.org>
Wed, 7 Mar 2012 22:01:51 +0000 (22:01 +0000)
committerOlivier Lamy <olamy@apache.org>
Wed, 7 Mar 2012 22:01:51 +0000 (22:01 +0000)
improve rest services to ease screen implementation.

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

archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ArchivaAdministrationService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/AddAdminRepoConsumerClosure.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/AdminRepositoryConsumerComparator.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/utils/MockInvalidRepositoryContentConsumer.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/scanning/AddAdminRepoConsumerClosure.java [deleted file]
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/scanning/AdminRepositoryConsumerComparator.java [deleted file]
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/scanning/RepositoryScanningAction.java

index 13dc7339da1a22f00a0ea44102f082af4416a081..a8f7f11658569d4f2abf02ac13ec263e314ebdcf 100644 (file)
@@ -23,6 +23,7 @@ import org.apache.archiva.admin.model.beans.LegacyArtifactPath;
 import org.apache.archiva.admin.model.beans.NetworkConfiguration;
 import org.apache.archiva.admin.model.beans.OrganisationInformation;
 import org.apache.archiva.admin.model.beans.UiConfiguration;
+import org.apache.archiva.rest.api.model.AdminRepositoryConsumer;
 import org.apache.archiva.security.common.ArchivaRoleConstants;
 import org.codehaus.plexus.redback.authorization.RedbackAuthorization;
 
@@ -157,6 +158,26 @@ public interface ArchivaAdministrationService
     List<String> getKnownContentConsumers()
         throws ArchivaRestServiceException;
 
+    @Path( "getKnownContentAdminRepositoryConsumers" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+    @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+    /**
+     * @since 1.4-M3
+     */
+    List<AdminRepositoryConsumer> getKnownContentAdminRepositoryConsumers()
+        throws ArchivaRestServiceException;
+
+    @Path( "getInvalidContentAdminRepositoryConsumers" )
+    @GET
+    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
+    @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+    /**
+     * @since 1.4-M3
+     */
+    List<AdminRepositoryConsumer> getInvalidContentAdminRepositoryConsumers()
+        throws ArchivaRestServiceException;
+
     @Path( "getInvalidContentConsumers" )
     @GET
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
index 0d5a821721114bfda6b12d3b4d2c084b41aa2636..74393943178b080a4d5669c64cd1ef2058f127e6 100644 (file)
@@ -27,8 +27,13 @@ import org.apache.archiva.admin.model.beans.OrganisationInformation;
 import org.apache.archiva.admin.model.beans.UiConfiguration;
 import org.apache.archiva.model.ArtifactReference;
 import org.apache.archiva.repository.ManagedRepositoryContent;
+import org.apache.archiva.repository.scanner.RepositoryContentConsumers;
+import org.apache.archiva.rest.api.model.AdminRepositoryConsumer;
 import org.apache.archiva.rest.api.services.ArchivaAdministrationService;
 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
+import org.apache.archiva.rest.services.utils.AddAdminRepoConsumerClosure;
+import org.apache.archiva.rest.services.utils.AdminRepositoryConsumerComparator;
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.stereotype.Service;
 
@@ -55,6 +60,9 @@ public class DefaultArchivaAdministrationService
     @Named( value = "managedRepositoryContent#legacy" )
     private ManagedRepositoryContent repositoryContent;
 
+    @Inject
+    private RepositoryContentConsumers repoConsumerUtil;
+
     public List<LegacyArtifactPath> getLegacyArtifactPaths()
         throws ArchivaRestServiceException
     {
@@ -386,4 +394,40 @@ public class DefaultArchivaAdministrationService
             throw new ArchivaRestServiceException( e.getMessage() );
         }
     }
+
+    public List<AdminRepositoryConsumer> getKnownContentAdminRepositoryConsumers()
+        throws ArchivaRestServiceException
+    {
+        try
+        {
+            AddAdminRepoConsumerClosure addAdminRepoConsumer =
+                new AddAdminRepoConsumerClosure( archivaAdministration.getKnownContentConsumers() );
+            CollectionUtils.forAllDo( repoConsumerUtil.getAvailableKnownConsumers(), addAdminRepoConsumer );
+            List<AdminRepositoryConsumer> knownContentConsumers = addAdminRepoConsumer.getList();
+            Collections.sort( knownContentConsumers, AdminRepositoryConsumerComparator.getInstance() );
+            return knownContentConsumers;
+        }
+        catch ( RepositoryAdminException e )
+        {
+            throw new ArchivaRestServiceException( e.getMessage() );
+        }
+    }
+
+    public List<AdminRepositoryConsumer> getInvalidContentAdminRepositoryConsumers()
+        throws ArchivaRestServiceException
+    {
+        try
+        {
+            AddAdminRepoConsumerClosure addAdminRepoConsumer =
+                new AddAdminRepoConsumerClosure( archivaAdministration.getInvalidContentConsumers() );
+            CollectionUtils.forAllDo( repoConsumerUtil.getAvailableInvalidConsumers(), addAdminRepoConsumer );
+            List<AdminRepositoryConsumer> invalidContentConsumers = addAdminRepoConsumer.getList();
+            Collections.sort( invalidContentConsumers, AdminRepositoryConsumerComparator.getInstance() );
+            return invalidContentConsumers;
+        }
+        catch ( RepositoryAdminException e )
+        {
+            throw new ArchivaRestServiceException( e.getMessage() );
+        }
+    }
 }
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/AddAdminRepoConsumerClosure.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/AddAdminRepoConsumerClosure.java
new file mode 100644 (file)
index 0000000..e222fbf
--- /dev/null
@@ -0,0 +1,66 @@
+package org.apache.archiva.rest.services.utils;
+
+/*
+ * 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.rest.api.model.AdminRepositoryConsumer;
+import org.apache.commons.collections.Closure;
+import org.apache.archiva.consumers.RepositoryContentConsumer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * AddAdminRepoConsumerClosure 
+ *
+ * @version $Id$
+ */
+public class AddAdminRepoConsumerClosure
+    implements Closure
+{
+    private List<AdminRepositoryConsumer> list = new ArrayList<AdminRepositoryConsumer>();
+
+    private List<String> selectedIds;
+
+    public AddAdminRepoConsumerClosure( List<String> selectedIds )
+    {
+        this.selectedIds = selectedIds;
+    }
+
+    public void execute( Object input )
+    {
+        if ( input instanceof RepositoryContentConsumer )
+        {
+            RepositoryContentConsumer consumer = (RepositoryContentConsumer) input;
+
+            boolean enabled = this.selectedIds.contains( consumer.getId() );
+            AdminRepositoryConsumer adminconsumer = new AdminRepositoryConsumer();
+            adminconsumer.setEnabled( enabled );
+            adminconsumer.setId( consumer.getId() );
+            adminconsumer.setDescription( consumer.getDescription() );
+
+            list.add( adminconsumer );
+        }
+    }
+
+    public List<AdminRepositoryConsumer> getList()
+    {
+        return list;
+    }
+}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/AdminRepositoryConsumerComparator.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/AdminRepositoryConsumerComparator.java
new file mode 100644 (file)
index 0000000..500ab7d
--- /dev/null
@@ -0,0 +1,62 @@
+package org.apache.archiva.rest.services.utils;
+
+/*
+ * 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.rest.api.model.AdminRepositoryConsumer;
+
+import java.util.Comparator;
+
+/**
+ * AdminRepositoryConsumerComparator 
+ *
+ * @version $Id$
+ */
+public class AdminRepositoryConsumerComparator
+    implements Comparator<AdminRepositoryConsumer>
+{
+    private static AdminRepositoryConsumerComparator INSTANCE = new AdminRepositoryConsumerComparator();
+
+    public static AdminRepositoryConsumerComparator getInstance()
+    {
+        return INSTANCE;
+    }
+
+    public int compare( AdminRepositoryConsumer o1, AdminRepositoryConsumer o2 )
+    {
+        if ( o1 == null && o2 == null )
+        {
+            return 0;
+        }
+
+        if ( o1 == null && o2 != null )
+        {
+            return 1;
+        }
+
+        if ( o1 != null && o2 == null )
+        {
+            return -1;
+        }
+
+        String id1 = o1.getId();
+        String id2 = o2.getId();
+        return id1.compareToIgnoreCase( id2 );
+    }
+}
index a7d0c301a7b925ba656f5b6f14604c4fbdba5a49..f3dea9ecffd6ff8c1338d2f12a3a0b8cdf3d6ed1 100644 (file)
@@ -22,10 +22,12 @@ import org.apache.archiva.admin.model.beans.FileType;
 import org.apache.archiva.admin.model.beans.LegacyArtifactPath;
 import org.apache.archiva.admin.model.beans.OrganisationInformation;
 import org.apache.archiva.admin.model.beans.UiConfiguration;
+import org.apache.archiva.rest.api.model.AdminRepositoryConsumer;
 import org.apache.commons.lang.StringUtils;
 import org.junit.Test;
 
 import java.util.Arrays;
+import java.util.List;
 
 /**
  * @author Olivier Lamy
@@ -130,4 +132,54 @@ public class ArchivaAdministrationServiceTest
         assertFalse( ui.isAppletFindEnabled() );
         assertFalse( ui.isShowFindArtifacts() );
     }
+
+    @Test
+    public void getKnownContentAdminRepositoryConsumer()
+        throws Exception
+    {
+        List<AdminRepositoryConsumer> consumers =
+            getArchivaAdministrationService().getKnownContentAdminRepositoryConsumers();
+        assertFalse( consumers.isEmpty() );
+    }
+
+    @Test
+    public void getInvalidContentAdminRepositoryConsumer()
+        throws Exception
+    {
+        List<AdminRepositoryConsumer> consumers =
+            getArchivaAdministrationService().getInvalidContentAdminRepositoryConsumers();
+        assertFalse( consumers.isEmpty() );
+        assertAllDisabled( consumers );
+
+        getArchivaAdministrationService().addInvalidContentConsumer( "foo" );
+
+        consumers = getArchivaAdministrationService().getInvalidContentAdminRepositoryConsumers();
+        assertFalse( consumers.isEmpty() );
+        assertAllEnabled( consumers );
+
+
+        getArchivaAdministrationService().removeInvalidContentConsumer( "foo" );
+
+        consumers = getArchivaAdministrationService().getInvalidContentAdminRepositoryConsumers();
+
+        assertAllDisabled( consumers );
+
+        assertFalse( consumers.isEmpty() );
+    }
+
+    private void assertAllEnabled( List<AdminRepositoryConsumer> consumers )
+    {
+        for ( AdminRepositoryConsumer consumer : consumers )
+        {
+            assertTrue( consumer.isEnabled() );
+        }
+    }
+
+    private void assertAllDisabled( List<AdminRepositoryConsumer> consumers )
+    {
+        for ( AdminRepositoryConsumer consumer : consumers )
+        {
+            assertFalse( consumer.isEnabled() );
+        }
+    }
 }
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/utils/MockInvalidRepositoryContentConsumer.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/utils/MockInvalidRepositoryContentConsumer.java
new file mode 100644 (file)
index 0000000..f5107a3
--- /dev/null
@@ -0,0 +1,110 @@
+package org.apache.archiva.rest.services.utils;
+/*
+ * 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.ManagedRepository;
+import org.apache.archiva.consumers.ConsumerException;
+import org.apache.archiva.consumers.ConsumerMonitor;
+import org.apache.archiva.consumers.InvalidRepositoryContentConsumer;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author Olivier Lamy
+ */
+@Service( "InvalidRepositoryContentConsumer#mock" )
+public class MockInvalidRepositoryContentConsumer
+    implements InvalidRepositoryContentConsumer
+{
+    public String getId()
+    {
+        return "foo";
+    }
+
+    public String getDescription()
+    {
+        return "the foo";
+    }
+
+    public boolean isPermanent()
+    {
+        return false;
+    }
+
+    public void addConsumerMonitor( ConsumerMonitor monitor )
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void removeConsumerMonitor( ConsumerMonitor monitor )
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public List<String> getIncludes()
+    {
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public List<String> getExcludes()
+    {
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void beginScan( ManagedRepository repository, Date whenGathered )
+        throws ConsumerException
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo )
+        throws ConsumerException
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void processFile( String path )
+        throws ConsumerException
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void processFile( String path, boolean executeOnEntireRepo )
+        throws Exception
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void completeScan()
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void completeScan( boolean executeOnEntireRepo )
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public boolean isProcessUnmodified()
+    {
+        return false;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+}
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/scanning/AddAdminRepoConsumerClosure.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/scanning/AddAdminRepoConsumerClosure.java
deleted file mode 100644 (file)
index 34023bb..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-package org.apache.archiva.web.action.admin.scanning;
-
-/*
- * 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.rest.api.model.AdminRepositoryConsumer;
-import org.apache.commons.collections.Closure;
-import org.apache.archiva.consumers.RepositoryContentConsumer;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * AddAdminRepoConsumerClosure 
- *
- * @version $Id$
- */
-public class AddAdminRepoConsumerClosure
-    implements Closure
-{
-    private List<AdminRepositoryConsumer> list = new ArrayList<AdminRepositoryConsumer>();
-
-    private List<String> selectedIds;
-
-    public AddAdminRepoConsumerClosure( List<String> selectedIds )
-    {
-        this.selectedIds = selectedIds;
-    }
-
-    public void execute( Object input )
-    {
-        if ( input instanceof RepositoryContentConsumer )
-        {
-            RepositoryContentConsumer consumer = (RepositoryContentConsumer) input;
-
-            boolean enabled = this.selectedIds.contains( consumer.getId() );
-            AdminRepositoryConsumer adminconsumer = new AdminRepositoryConsumer();
-            adminconsumer.setEnabled( enabled );
-            adminconsumer.setId( consumer.getId() );
-            adminconsumer.setDescription( consumer.getDescription() );
-
-            list.add( adminconsumer );
-        }
-    }
-
-    public List<AdminRepositoryConsumer> getList()
-    {
-        return list;
-    }
-}
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/scanning/AdminRepositoryConsumerComparator.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/scanning/AdminRepositoryConsumerComparator.java
deleted file mode 100644 (file)
index 61130e6..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-package org.apache.archiva.web.action.admin.scanning;
-
-/*
- * 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.rest.api.model.AdminRepositoryConsumer;
-
-import java.util.Comparator;
-
-/**
- * AdminRepositoryConsumerComparator 
- *
- * @version $Id$
- */
-public class AdminRepositoryConsumerComparator
-    implements Comparator<AdminRepositoryConsumer>
-{
-    private static AdminRepositoryConsumerComparator INSTANCE = new AdminRepositoryConsumerComparator();
-
-    public static AdminRepositoryConsumerComparator getInstance()
-    {
-        return INSTANCE;
-    }
-
-    public int compare( AdminRepositoryConsumer o1, AdminRepositoryConsumer o2 )
-    {
-        if ( o1 == null && o2 == null )
-        {
-            return 0;
-        }
-
-        if ( o1 == null && o2 != null )
-        {
-            return 1;
-        }
-
-        if ( o1 != null && o2 == null )
-        {
-            return -1;
-        }
-
-        String id1 = o1.getId();
-        String id2 = o2.getId();
-        return id1.compareToIgnoreCase( id2 );
-    }
-}
index 36117aeeff51bc728701535c92f490f1f421b567..587493d5ff1e2ced094252bc56a7652904818672 100644 (file)
@@ -28,6 +28,8 @@ import org.apache.archiva.admin.repository.admin.FiletypeToMapClosure;
 import org.apache.archiva.audit.Auditable;
 import org.apache.archiva.repository.scanner.RepositoryContentConsumers;
 import org.apache.archiva.rest.api.model.AdminRepositoryConsumer;
+import org.apache.archiva.rest.services.utils.AddAdminRepoConsumerClosure;
+import org.apache.archiva.rest.services.utils.AdminRepositoryConsumerComparator;
 import org.apache.archiva.security.common.ArchivaRoleConstants;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.StringUtils;