From 8b54c2ee99731b9a20b68f3811cd170044296985 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 6 Sep 2011 21:05:02 +0000 Subject: [PATCH] [MRM-1504] new repository admin : more use of new api in webapp : in the repositories index action git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1165842 13f79535-47bb-0310-9956-ffa450edef68 --- .../utils/RepositoryComparator.java | 51 +++++++++++++++ .../repositories/RepositoriesAction.java | 64 ++++++++++++++----- .../webapp/WEB-INF/jsp/admin/repositories.jsp | 6 +- 3 files changed, 101 insertions(+), 20 deletions(-) create mode 100644 archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/utils/RepositoryComparator.java diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/utils/RepositoryComparator.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/utils/RepositoryComparator.java new file mode 100644 index 000000000..f9b93697a --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/utils/RepositoryComparator.java @@ -0,0 +1,51 @@ +package org.apache.archiva.admin.repository.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.repository.AbstractRepository; + +import java.util.Comparator; + +/** + * @author Olivier Lamy + * @since 1.4 + */ +public class RepositoryComparator + implements Comparator +{ + public int compare( AbstractRepository o1, AbstractRepository o2 ) + { + if ( o1 == null && o2 == null ) + { + return 0; + } + + if ( o1 == null ) + { + return -1; + } + + if ( o2 == null ) + { + return 1; + } + + return o1.getId().compareToIgnoreCase( o2.getId() ); + } +} diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesAction.java index b2cc64618..1975b097f 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesAction.java @@ -20,19 +20,22 @@ package org.apache.maven.archiva.web.action.admin.repositories; */ import com.opensymphony.xwork2.Preparable; +import org.apache.archiva.admin.repository.RepositoryAdminException; +import org.apache.archiva.admin.repository.managed.ManagedRepository; +import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin; +import org.apache.archiva.admin.repository.remote.RemoteRepository; +import org.apache.archiva.admin.repository.remote.RemoteRepositoryAdmin; +import org.apache.archiva.admin.repository.utils.RepositoryComparator; import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.MetadataRepositoryException; import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.metadata.repository.stats.RepositoryStatistics; import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager; import org.apache.archiva.security.common.ArchivaRoleConstants; +import org.apache.archiva.web.util.ContextUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; -import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; -import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; -import org.apache.maven.archiva.configuration.functors.RepositoryConfigurationComparator; import org.apache.maven.archiva.web.action.AbstractActionSupport; -import org.apache.archiva.web.util.ContextUtils; import org.apache.struts2.interceptor.ServletRequestAware; import org.codehaus.plexus.redback.rbac.Resource; import org.codehaus.redback.integration.interceptor.SecureAction; @@ -41,13 +44,13 @@ import org.codehaus.redback.integration.interceptor.SecureActionException; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; +import javax.inject.Inject; +import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.inject.Inject; -import javax.servlet.http.HttpServletRequest; /** * Shows the Repositories Tab for the administrator. @@ -64,9 +67,15 @@ public class RepositoriesAction @Inject private ArchivaConfiguration archivaConfiguration; - private List managedRepositories; + @Inject + private ManagedRepositoryAdmin managedRepositoryAdmin; + + @Inject + private RemoteRepositoryAdmin remoteRepositoryAdmin; - private List remoteRepositories; + private List managedRepositories; + + private List remoteRepositories; private Map repositoryStatistics; @@ -100,22 +109,23 @@ public class RepositoriesAction @SuppressWarnings( "unchecked" ) public void prepare() + throws RepositoryAdminException { Configuration config = archivaConfiguration.getConfiguration(); - remoteRepositories = new ArrayList( config.getRemoteRepositories() ); - managedRepositories = new ArrayList( config.getManagedRepositories() ); + remoteRepositories = new ArrayList( getRemoteRepositoryAdmin().getRemoteRepositories() ); + managedRepositories = new ArrayList( getManagedRepositoryAdmin().getManagedRepositories() ); repositoryToGroupMap = config.getRepositoryToGroupMap(); - Collections.sort( managedRepositories, new RepositoryConfigurationComparator() ); - Collections.sort( remoteRepositories, new RepositoryConfigurationComparator() ); + Collections.sort( managedRepositories, new RepositoryComparator() ); + Collections.sort( remoteRepositories, new RepositoryComparator() ); repositoryStatistics = new HashMap(); RepositorySession repositorySession = repositorySessionFactory.createSession(); try { MetadataRepository metadataRepository = repositorySession.getRepository(); - for ( ManagedRepositoryConfiguration repo : managedRepositories ) + for ( ManagedRepository repo : managedRepositories ) { RepositoryStatistics stats = null; try @@ -140,10 +150,10 @@ public class RepositoriesAction } } - public List getManagedRepositories() + public List getManagedRepositories() { - List managedRepositoriesList = new ArrayList(); - for ( ManagedRepositoryConfiguration repoConfig : managedRepositories ) + List managedRepositoriesList = new ArrayList(); + for ( ManagedRepository repoConfig : managedRepositories ) { if ( !repoConfig.getId().endsWith( "-stage" ) ) { @@ -153,7 +163,7 @@ public class RepositoriesAction return managedRepositoriesList; } - public List getRemoteRepositories() + public List getRemoteRepositories() { return remoteRepositories; } @@ -172,4 +182,24 @@ public class RepositoriesAction { return repositoryToGroupMap; } + + public ManagedRepositoryAdmin getManagedRepositoryAdmin() + { + return managedRepositoryAdmin; + } + + public void setManagedRepositoryAdmin( ManagedRepositoryAdmin managedRepositoryAdmin ) + { + this.managedRepositoryAdmin = managedRepositoryAdmin; + } + + public RemoteRepositoryAdmin getRemoteRepositoryAdmin() + { + return remoteRepositoryAdmin; + } + + public void setRemoteRepositoryAdmin( RemoteRepositoryAdmin remoteRepositoryAdmin ) + { + this.remoteRepositoryAdmin = remoteRepositoryAdmin; + } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositories.jsp b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositories.jsp index 46fa53d01..deafa6fbc 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositories.jsp +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositories.jsp @@ -148,10 +148,10 @@ Directory - + Index Directory - + @@ -211,7 +211,7 @@ Scanning Cron - + -- 2.39.5