From 1646114f7a0bcee5876dfde694eace48aab964ed Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 7 Mar 2012 22:01:51 +0000 Subject: [PATCH] [MRM-1579] rewrite repositories scanning admin page improve rest services to ease screen implementation. git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1298149 13f79535-47bb-0310-9956-ffa450edef68 --- .../ArchivaAdministrationService.java | 21 ++++ .../DefaultArchivaAdministrationService.java | 44 +++++++ .../utils}/AddAdminRepoConsumerClosure.java | 2 +- .../AdminRepositoryConsumerComparator.java | 2 +- .../ArchivaAdministrationServiceTest.java | 52 +++++++++ .../MockInvalidRepositoryContentConsumer.java | 110 ++++++++++++++++++ .../scanning/RepositoryScanningAction.java | 2 + 7 files changed, 231 insertions(+), 2 deletions(-) rename archiva-modules/archiva-web/{archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/scanning => archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils}/AddAdminRepoConsumerClosure.java (97%) rename archiva-modules/archiva-web/{archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/scanning => archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils}/AdminRepositoryConsumerComparator.java (96%) create mode 100644 archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/utils/MockInvalidRepositoryContentConsumer.java diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ArchivaAdministrationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ArchivaAdministrationService.java index 13dc7339d..a8f7f1165 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ArchivaAdministrationService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ArchivaAdministrationService.java @@ -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 getKnownContentConsumers() throws ArchivaRestServiceException; + @Path( "getKnownContentAdminRepositoryConsumers" ) + @GET + @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) + @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION ) + /** + * @since 1.4-M3 + */ + List getKnownContentAdminRepositoryConsumers() + throws ArchivaRestServiceException; + + @Path( "getInvalidContentAdminRepositoryConsumers" ) + @GET + @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) + @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION ) + /** + * @since 1.4-M3 + */ + List getInvalidContentAdminRepositoryConsumers() + throws ArchivaRestServiceException; + @Path( "getInvalidContentConsumers" ) @GET @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java index 0d5a82172..743939431 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java @@ -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 getLegacyArtifactPaths() throws ArchivaRestServiceException { @@ -386,4 +394,40 @@ public class DefaultArchivaAdministrationService throw new ArchivaRestServiceException( e.getMessage() ); } } + + public List getKnownContentAdminRepositoryConsumers() + throws ArchivaRestServiceException + { + try + { + AddAdminRepoConsumerClosure addAdminRepoConsumer = + new AddAdminRepoConsumerClosure( archivaAdministration.getKnownContentConsumers() ); + CollectionUtils.forAllDo( repoConsumerUtil.getAvailableKnownConsumers(), addAdminRepoConsumer ); + List knownContentConsumers = addAdminRepoConsumer.getList(); + Collections.sort( knownContentConsumers, AdminRepositoryConsumerComparator.getInstance() ); + return knownContentConsumers; + } + catch ( RepositoryAdminException e ) + { + throw new ArchivaRestServiceException( e.getMessage() ); + } + } + + public List getInvalidContentAdminRepositoryConsumers() + throws ArchivaRestServiceException + { + try + { + AddAdminRepoConsumerClosure addAdminRepoConsumer = + new AddAdminRepoConsumerClosure( archivaAdministration.getInvalidContentConsumers() ); + CollectionUtils.forAllDo( repoConsumerUtil.getAvailableInvalidConsumers(), addAdminRepoConsumer ); + List 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-webapp/src/main/java/org/apache/archiva/web/action/admin/scanning/AddAdminRepoConsumerClosure.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/AddAdminRepoConsumerClosure.java similarity index 97% rename from archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/scanning/AddAdminRepoConsumerClosure.java rename to archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/AddAdminRepoConsumerClosure.java index 34023bb21..e222fbf5a 100644 --- 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-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/AddAdminRepoConsumerClosure.java @@ -1,4 +1,4 @@ -package org.apache.archiva.web.action.admin.scanning; +package org.apache.archiva.rest.services.utils; /* * Licensed to the Apache Software Foundation (ASF) under one 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-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/AdminRepositoryConsumerComparator.java similarity index 96% rename from archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/scanning/AdminRepositoryConsumerComparator.java rename to archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/AdminRepositoryConsumerComparator.java index 61130e67d..500ab7d5e 100644 --- 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-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/AdminRepositoryConsumerComparator.java @@ -1,4 +1,4 @@ -package org.apache.archiva.web.action.admin.scanning; +package org.apache.archiva.rest.services.utils; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java index a7d0c301a..f3dea9ecf 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java @@ -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 consumers = + getArchivaAdministrationService().getKnownContentAdminRepositoryConsumers(); + assertFalse( consumers.isEmpty() ); + } + + @Test + public void getInvalidContentAdminRepositoryConsumer() + throws Exception + { + List 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 consumers ) + { + for ( AdminRepositoryConsumer consumer : consumers ) + { + assertTrue( consumer.isEnabled() ); + } + } + + private void assertAllDisabled( List 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 index 000000000..f5107a36c --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/utils/MockInvalidRepositoryContentConsumer.java @@ -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 getIncludes() + { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public List 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/RepositoryScanningAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/scanning/RepositoryScanningAction.java index 36117aeef..587493d5f 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/scanning/RepositoryScanningAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/scanning/RepositoryScanningAction.java @@ -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; -- 2.39.5