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.MetadataRepository;
24 import org.apache.archiva.metadata.repository.MetadataRepositoryException;
25 import org.apache.archiva.metadata.repository.RepositorySession;
26 import org.apache.archiva.metadata.repository.stats.RepositoryStatistics;
27 import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
28 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
29 import org.apache.maven.archiva.configuration.Configuration;
30 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
31 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
32 import org.apache.maven.archiva.configuration.functors.RepositoryConfigurationComparator;
33 import org.apache.maven.archiva.security.ArchivaRoleConstants;
34 import org.apache.maven.archiva.web.action.PlexusActionSupport;
35 import org.apache.maven.archiva.web.util.ContextUtils;
36 import org.apache.struts2.interceptor.ServletRequestAware;
37 import org.codehaus.plexus.redback.rbac.Resource;
38 import org.codehaus.redback.integration.interceptor.SecureAction;
39 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
40 import org.codehaus.redback.integration.interceptor.SecureActionException;
42 import java.util.ArrayList;
43 import java.util.Collections;
44 import java.util.HashMap;
45 import java.util.List;
47 import javax.servlet.http.HttpServletRequest;
50 * Shows the Repositories Tab for the administrator.
53 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="repositoriesAction" instantiation-strategy="per-lookup"
55 public class RepositoriesAction
56 extends PlexusActionSupport
57 implements SecureAction, ServletRequestAware, Preparable
62 private ArchivaConfiguration archivaConfiguration;
64 private List<ManagedRepositoryConfiguration> managedRepositories;
66 private List<RemoteRepositoryConfiguration> remoteRepositories;
68 private Map<String, RepositoryStatistics> repositoryStatistics;
70 private Map<String, List<String>> repositoryToGroupMap;
73 * Used to construct the repository WebDAV URL in the repository action.
75 private String baseUrl;
80 private RepositoryStatisticsManager repositoryStatisticsManager;
82 public void setServletRequest( HttpServletRequest request )
84 // TODO: is there a better way to do this?
85 this.baseUrl = ContextUtils.getBaseURL( request, "repository" );
88 public SecureActionBundle getSecureActionBundle()
89 throws SecureActionException
91 SecureActionBundle bundle = new SecureActionBundle();
93 bundle.setRequiresAuthentication( true );
94 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
99 @SuppressWarnings( "unchecked" )
100 public void prepare()
102 Configuration config = archivaConfiguration.getConfiguration();
104 remoteRepositories = new ArrayList<RemoteRepositoryConfiguration>( config.getRemoteRepositories() );
105 managedRepositories = new ArrayList<ManagedRepositoryConfiguration>( config.getManagedRepositories() );
106 repositoryToGroupMap = config.getRepositoryToGroupMap();
108 Collections.sort( managedRepositories, new RepositoryConfigurationComparator() );
109 Collections.sort( remoteRepositories, new RepositoryConfigurationComparator() );
111 repositoryStatistics = new HashMap<String, RepositoryStatistics>();
112 RepositorySession repositorySession = repositorySessionFactory.createSession();
115 MetadataRepository metadataRepository = repositorySession.getRepository();
116 for ( ManagedRepositoryConfiguration repo : managedRepositories )
118 RepositoryStatistics stats = null;
121 stats = repositoryStatisticsManager.getLastStatistics( metadataRepository, repo.getId() );
123 catch ( MetadataRepositoryException e )
126 "Error retrieving statistics for repository " + repo.getId() + " - consult application logs" );
127 log.warn( "Error retrieving repository statistics: " + e.getMessage(), e );
131 repositoryStatistics.put( repo.getId(), stats );
137 repositorySession.close();
141 public List<ManagedRepositoryConfiguration> getManagedRepositories()
143 List<ManagedRepositoryConfiguration> managedRepositoriesList = new ArrayList<ManagedRepositoryConfiguration>();
144 for ( ManagedRepositoryConfiguration repoConfig : managedRepositories )
146 if ( !repoConfig.getId().contains( "stage" ) )
148 managedRepositoriesList.add( repoConfig );
151 return managedRepositoriesList;
154 public List<RemoteRepositoryConfiguration> getRemoteRepositories()
156 return remoteRepositories;
159 public Map<String, RepositoryStatistics> getRepositoryStatistics()
161 return repositoryStatistics;
164 public String getBaseUrl()
169 public Map<String, List<String>> getRepositoryToGroupMap()
171 return repositoryToGroupMap;