1 package org.apache.maven.archiva.web.action.admin.repositories;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import com.opensymphony.xwork2.Preparable;
23 import org.apache.archiva.metadata.repository.MetadataRepositoryException;
24 import org.apache.archiva.metadata.repository.stats.RepositoryStatistics;
25 import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
26 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
27 import org.apache.maven.archiva.configuration.Configuration;
28 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
29 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
30 import org.apache.maven.archiva.configuration.functors.RepositoryConfigurationComparator;
31 import org.apache.maven.archiva.security.ArchivaRoleConstants;
32 import org.apache.maven.archiva.web.action.PlexusActionSupport;
33 import org.apache.maven.archiva.web.util.ContextUtils;
34 import org.apache.struts2.interceptor.ServletRequestAware;
35 import org.codehaus.plexus.redback.rbac.Resource;
36 import org.codehaus.redback.integration.interceptor.SecureAction;
37 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
38 import org.codehaus.redback.integration.interceptor.SecureActionException;
40 import java.util.ArrayList;
41 import java.util.Collections;
42 import java.util.HashMap;
43 import java.util.List;
45 import javax.servlet.http.HttpServletRequest;
48 * Shows the Repositories Tab for the administrator.
51 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="repositoriesAction" instantiation-strategy="per-lookup"
53 public class RepositoriesAction
54 extends PlexusActionSupport
55 implements SecureAction, ServletRequestAware, Preparable
60 private ArchivaConfiguration archivaConfiguration;
62 private List<ManagedRepositoryConfiguration> managedRepositories;
64 private List<RemoteRepositoryConfiguration> remoteRepositories;
66 private Map<String, RepositoryStatistics> repositoryStatistics;
68 private Map<String, List<String>> repositoryToGroupMap;
71 * Used to construct the repository WebDAV URL in the repository action.
73 private String baseUrl;
78 private RepositoryStatisticsManager repositoryStatisticsManager;
80 public void setServletRequest( HttpServletRequest request )
82 // TODO: is there a better way to do this?
83 this.baseUrl = ContextUtils.getBaseURL( request, "repository" );
86 public SecureActionBundle getSecureActionBundle()
87 throws SecureActionException
89 SecureActionBundle bundle = new SecureActionBundle();
91 bundle.setRequiresAuthentication( true );
92 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
97 @SuppressWarnings( "unchecked" )
100 Configuration config = archivaConfiguration.getConfiguration();
102 remoteRepositories = new ArrayList<RemoteRepositoryConfiguration>( config.getRemoteRepositories() );
103 managedRepositories = new ArrayList<ManagedRepositoryConfiguration>( config.getManagedRepositories() );
104 repositoryToGroupMap = config.getRepositoryToGroupMap();
106 Collections.sort( managedRepositories, new RepositoryConfigurationComparator() );
107 Collections.sort( remoteRepositories, new RepositoryConfigurationComparator() );
109 repositoryStatistics = new HashMap<String, RepositoryStatistics>();
110 for ( ManagedRepositoryConfiguration repo : managedRepositories )
112 RepositoryStatistics stats = null;
115 stats = repositoryStatisticsManager.getLastStatistics( repo.getId() );
117 catch ( MetadataRepositoryException e )
120 "Error retrieving statistics for repository " + repo.getId() + " - consult application logs" );
121 log.warn( "Error retrieving repository statistics: " + e.getMessage(), e );
125 repositoryStatistics.put( repo.getId(), stats );
130 public List<ManagedRepositoryConfiguration> getManagedRepositories()
132 List<ManagedRepositoryConfiguration> managedRepositoriesList = new ArrayList<ManagedRepositoryConfiguration>();
133 for ( ManagedRepositoryConfiguration repoConfig : managedRepositories )
135 if ( !repoConfig.getId().contains( "stage" ) )
137 managedRepositoriesList.add( repoConfig );
140 return managedRepositoriesList;
143 public List<RemoteRepositoryConfiguration> getRemoteRepositories()
145 return remoteRepositories;
148 public Map<String, RepositoryStatistics> getRepositoryStatistics()
150 return repositoryStatistics;
153 public String getBaseUrl()
158 public Map<String, List<String>> getRepositoryToGroupMap()
160 return repositoryToGroupMap;