From: Olivier Lamy Date: Wed, 7 Mar 2012 22:01:51 +0000 (+0000) Subject: [MRM-1579] rewrite repositories scanning admin page X-Git-Tag: archiva-1.4-M3~1100 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1646114f7a0bcee5876dfde694eace48aab964ed;p=archiva.git [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 --- 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-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 index 000000000..e222fbf5a --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/AddAdminRepoConsumerClosure.java @@ -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 list = new ArrayList(); + + private List selectedIds; + + public AddAdminRepoConsumerClosure( List 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 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 index 000000000..500ab7d5e --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/AdminRepositoryConsumerComparator.java @@ -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 +{ + 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 ); + } +} 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/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 index 34023bb21..000000000 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/scanning/AddAdminRepoConsumerClosure.java +++ /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 list = new ArrayList(); - - private List selectedIds; - - public AddAdminRepoConsumerClosure( List 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 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 index 61130e67d..000000000 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/scanning/AdminRepositoryConsumerComparator.java +++ /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 -{ - 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 ); - } -} 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;