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 remoteRepositories = new ArrayList<RemoteRepository>( getRemoteRepositoryAdmin().getRemoteRepositories() );
119 managedRepositories = new ArrayList<ManagedRepository>( getManagedRepositoryAdmin().getManagedRepositories() );
120 repositoryToGroupMap = getRepositoryGroupAdmin().getRepositoryToGroupMap();
122 Collections.sort( managedRepositories, new RepositoryComparator() );
123 Collections.sort( remoteRepositories, new RepositoryComparator() );
125 repositoryStatistics = new HashMap<String, RepositoryStatistics>();
126 RepositorySession repositorySession = repositorySessionFactory.createSession();
129 MetadataRepository metadataRepository = repositorySession.getRepository();
130 for ( ManagedRepository repo : managedRepositories )
132 RepositoryStatistics stats = null;
135 stats = repositoryStatisticsManager.getLastStatistics( metadataRepository, repo.getId() );
137 catch ( MetadataRepositoryException e )
140 "Error retrieving statistics for repository " + repo.getId() + " - consult application logs" );
141 log.warn( "Error retrieving repository statistics: " + e.getMessage(), e );
145 repositoryStatistics.put( repo.getId(), stats );
151 repositorySession.close();
155 public List<ManagedRepository> getManagedRepositories()
157 List<ManagedRepository> managedRepositoriesList = new ArrayList<ManagedRepository>();
158 for ( ManagedRepository repoConfig : managedRepositories )
160 if ( !repoConfig.getId().endsWith( "-stage" ) )
162 managedRepositoriesList.add( repoConfig );
165 return managedRepositoriesList;
168 public List<RemoteRepository> getRemoteRepositories()
170 return remoteRepositories;
173 public Map<String, RepositoryStatistics> getRepositoryStatistics()
175 return repositoryStatistics;
178 public String getBaseUrl()
183 public Map<String, List<String>> getRepositoryToGroupMap()
185 return repositoryToGroupMap;
188 public ManagedRepositoryAdmin getManagedRepositoryAdmin()
190 return managedRepositoryAdmin;
193 public void setManagedRepositoryAdmin( ManagedRepositoryAdmin managedRepositoryAdmin )
195 this.managedRepositoryAdmin = managedRepositoryAdmin;
198 public RemoteRepositoryAdmin getRemoteRepositoryAdmin()
200 return remoteRepositoryAdmin;
203 public void setRemoteRepositoryAdmin( RemoteRepositoryAdmin remoteRepositoryAdmin )
205 this.remoteRepositoryAdmin = remoteRepositoryAdmin;
208 public RepositoryGroupAdmin getRepositoryGroupAdmin()
210 return repositoryGroupAdmin;
213 public void setRepositoryGroupAdmin( RepositoryGroupAdmin repositoryGroupAdmin )
215 this.repositoryGroupAdmin = repositoryGroupAdmin;
218 public RepositoryStatisticsManager getRepositoryStatisticsManager()
220 return repositoryStatisticsManager;
223 public void setRepositoryStatisticsManager( RepositoryStatisticsManager repositoryStatisticsManager )
225 this.repositoryStatisticsManager = repositoryStatisticsManager;