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.admin.repository.RepositoryAdminException;
24 import org.apache.archiva.admin.repository.group.RepositoryGroupAdmin;
25 import org.apache.archiva.admin.repository.managed.ManagedRepository;
26 import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin;
27 import org.apache.archiva.admin.repository.remote.RemoteRepository;
28 import org.apache.archiva.admin.repository.remote.RemoteRepositoryAdmin;
29 import org.apache.archiva.admin.repository.utils.RepositoryComparator;
30 import org.apache.archiva.metadata.repository.MetadataRepository;
31 import org.apache.archiva.metadata.repository.MetadataRepositoryException;
32 import org.apache.archiva.metadata.repository.RepositorySession;
33 import org.apache.archiva.metadata.repository.stats.RepositoryStatistics;
34 import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
35 import org.apache.archiva.security.common.ArchivaRoleConstants;
36 import org.apache.archiva.web.util.ContextUtils;
37 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
38 import org.apache.maven.archiva.configuration.Configuration;
39 import org.apache.maven.archiva.web.action.AbstractActionSupport;
40 import org.apache.struts2.interceptor.ServletRequestAware;
41 import org.codehaus.plexus.redback.rbac.Resource;
42 import org.codehaus.redback.integration.interceptor.SecureAction;
43 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
44 import org.codehaus.redback.integration.interceptor.SecureActionException;
45 import org.springframework.context.annotation.Scope;
46 import org.springframework.stereotype.Controller;
48 import javax.inject.Inject;
49 import javax.servlet.http.HttpServletRequest;
50 import java.util.ArrayList;
51 import java.util.Collections;
52 import java.util.HashMap;
53 import java.util.List;
57 * Shows the Repositories Tab for the administrator.
61 @Controller( "repositoriesAction" )
63 public class RepositoriesAction
64 extends AbstractActionSupport
65 implements SecureAction, ServletRequestAware, Preparable
69 private ArchivaConfiguration archivaConfiguration;
72 private ManagedRepositoryAdmin managedRepositoryAdmin;
75 private RemoteRepositoryAdmin remoteRepositoryAdmin;
78 private RepositoryGroupAdmin repositoryGroupAdmin;
80 private List<ManagedRepository> managedRepositories;
82 private List<RemoteRepository> remoteRepositories;
84 private Map<String, RepositoryStatistics> repositoryStatistics;
86 private Map<String, List<String>> repositoryToGroupMap;
89 * Used to construct the repository WebDAV URL in the repository action.
91 private String baseUrl;
95 private RepositoryStatisticsManager repositoryStatisticsManager;
97 public void setServletRequest( HttpServletRequest request )
99 // TODO: is there a better way to do this?
100 this.baseUrl = ContextUtils.getBaseURL( request, "repository" );
103 public SecureActionBundle getSecureActionBundle()
104 throws SecureActionException
106 SecureActionBundle bundle = new SecureActionBundle();
108 bundle.setRequiresAuthentication( true );
109 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
114 @SuppressWarnings( "unchecked" )
115 public void prepare()
116 throws RepositoryAdminException
118 Configuration config = archivaConfiguration.getConfiguration();
120 remoteRepositories = new ArrayList<RemoteRepository>( getRemoteRepositoryAdmin().getRemoteRepositories() );
121 managedRepositories = new ArrayList<ManagedRepository>( getManagedRepositoryAdmin().getManagedRepositories() );
122 repositoryToGroupMap = getRepositoryGroupAdmin().getRepositoryToGroupMap();
124 Collections.sort( managedRepositories, new RepositoryComparator() );
125 Collections.sort( remoteRepositories, new RepositoryComparator() );
127 repositoryStatistics = new HashMap<String, RepositoryStatistics>();
128 RepositorySession repositorySession = repositorySessionFactory.createSession();
131 MetadataRepository metadataRepository = repositorySession.getRepository();
132 for ( ManagedRepository repo : managedRepositories )
134 RepositoryStatistics stats = null;
137 stats = repositoryStatisticsManager.getLastStatistics( metadataRepository, repo.getId() );
139 catch ( MetadataRepositoryException e )
142 "Error retrieving statistics for repository " + repo.getId() + " - consult application logs" );
143 log.warn( "Error retrieving repository statistics: " + e.getMessage(), e );
147 repositoryStatistics.put( repo.getId(), stats );
153 repositorySession.close();
157 public List<ManagedRepository> getManagedRepositories()
159 List<ManagedRepository> managedRepositoriesList = new ArrayList<ManagedRepository>();
160 for ( ManagedRepository repoConfig : managedRepositories )
162 if ( !repoConfig.getId().endsWith( "-stage" ) )
164 managedRepositoriesList.add( repoConfig );
167 return managedRepositoriesList;
170 public List<RemoteRepository> getRemoteRepositories()
172 return remoteRepositories;
175 public Map<String, RepositoryStatistics> getRepositoryStatistics()
177 return repositoryStatistics;
180 public String getBaseUrl()
185 public Map<String, List<String>> getRepositoryToGroupMap()
187 return repositoryToGroupMap;
190 public ManagedRepositoryAdmin getManagedRepositoryAdmin()
192 return managedRepositoryAdmin;
195 public void setManagedRepositoryAdmin( ManagedRepositoryAdmin managedRepositoryAdmin )
197 this.managedRepositoryAdmin = managedRepositoryAdmin;
200 public RemoteRepositoryAdmin getRemoteRepositoryAdmin()
202 return remoteRepositoryAdmin;
205 public void setRemoteRepositoryAdmin( RemoteRepositoryAdmin remoteRepositoryAdmin )
207 this.remoteRepositoryAdmin = remoteRepositoryAdmin;
210 public RepositoryGroupAdmin getRepositoryGroupAdmin()
212 return repositoryGroupAdmin;
215 public void setRepositoryGroupAdmin( RepositoryGroupAdmin repositoryGroupAdmin )
217 this.repositoryGroupAdmin = repositoryGroupAdmin;
220 public RepositoryStatisticsManager getRepositoryStatisticsManager()
222 return repositoryStatisticsManager;
225 public void setRepositoryStatisticsManager( RepositoryStatisticsManager repositoryStatisticsManager )
227 this.repositoryStatisticsManager = repositoryStatisticsManager;