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.archiva.security.common.ArchivaRoleConstants;
29 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
30 import org.apache.maven.archiva.configuration.Configuration;
31 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
32 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
33 import org.apache.maven.archiva.configuration.functors.RepositoryConfigurationComparator;
34 import org.apache.maven.archiva.web.action.AbstractActionSupport;
35 import org.apache.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;
41 import org.springframework.context.annotation.Scope;
42 import org.springframework.stereotype.Controller;
44 import java.util.ArrayList;
45 import java.util.Collections;
46 import java.util.HashMap;
47 import java.util.List;
49 import javax.inject.Inject;
50 import javax.servlet.http.HttpServletRequest;
53 * Shows the Repositories Tab for the administrator.
57 @Controller( "repositoriesAction" )
59 public class RepositoriesAction
60 extends AbstractActionSupport
61 implements SecureAction, ServletRequestAware, Preparable
65 private ArchivaConfiguration archivaConfiguration;
67 private List<ManagedRepositoryConfiguration> managedRepositories;
69 private List<RemoteRepositoryConfiguration> remoteRepositories;
71 private Map<String, RepositoryStatistics> repositoryStatistics;
73 private Map<String, List<String>> repositoryToGroupMap;
76 * Used to construct the repository WebDAV URL in the repository action.
78 private String baseUrl;
82 private RepositoryStatisticsManager repositoryStatisticsManager;
84 public void setServletRequest( HttpServletRequest request )
86 // TODO: is there a better way to do this?
87 this.baseUrl = ContextUtils.getBaseURL( request, "repository" );
90 public SecureActionBundle getSecureActionBundle()
91 throws SecureActionException
93 SecureActionBundle bundle = new SecureActionBundle();
95 bundle.setRequiresAuthentication( true );
96 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
101 @SuppressWarnings( "unchecked" )
102 public void prepare()
104 Configuration config = archivaConfiguration.getConfiguration();
106 remoteRepositories = new ArrayList<RemoteRepositoryConfiguration>( config.getRemoteRepositories() );
107 managedRepositories = new ArrayList<ManagedRepositoryConfiguration>( config.getManagedRepositories() );
108 repositoryToGroupMap = config.getRepositoryToGroupMap();
110 Collections.sort( managedRepositories, new RepositoryConfigurationComparator() );
111 Collections.sort( remoteRepositories, new RepositoryConfigurationComparator() );
113 repositoryStatistics = new HashMap<String, RepositoryStatistics>();
114 RepositorySession repositorySession = repositorySessionFactory.createSession();
117 MetadataRepository metadataRepository = repositorySession.getRepository();
118 for ( ManagedRepositoryConfiguration repo : managedRepositories )
120 RepositoryStatistics stats = null;
123 stats = repositoryStatisticsManager.getLastStatistics( metadataRepository, repo.getId() );
125 catch ( MetadataRepositoryException e )
128 "Error retrieving statistics for repository " + repo.getId() + " - consult application logs" );
129 log.warn( "Error retrieving repository statistics: " + e.getMessage(), e );
133 repositoryStatistics.put( repo.getId(), stats );
139 repositorySession.close();
143 public List<ManagedRepositoryConfiguration> getManagedRepositories()
145 List<ManagedRepositoryConfiguration> managedRepositoriesList = new ArrayList<ManagedRepositoryConfiguration>();
146 for ( ManagedRepositoryConfiguration repoConfig : managedRepositories )
148 if ( !repoConfig.getId().endsWith( "-stage" ) )
150 managedRepositoriesList.add( repoConfig );
153 return managedRepositoriesList;
156 public List<RemoteRepositoryConfiguration> getRemoteRepositories()
158 return remoteRepositories;
161 public Map<String, RepositoryStatistics> getRepositoryStatistics()
163 return repositoryStatistics;
166 public String getBaseUrl()
171 public Map<String, List<String>> getRepositoryToGroupMap()
173 return repositoryToGroupMap;