1 package org.apache.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.model.RepositoryAdminException;
24 import org.apache.archiva.admin.model.beans.ManagedRepository;
25 import org.apache.archiva.admin.model.beans.RemoteRepository;
26 import org.apache.archiva.admin.model.group.RepositoryGroupAdmin;
27 import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
28 import org.apache.archiva.admin.model.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.redback.rbac.Resource;
36 import org.apache.archiva.security.common.ArchivaRoleConstants;
37 import org.apache.archiva.web.util.ContextUtils;
38 import org.apache.archiva.web.action.AbstractActionSupport;
39 import org.apache.struts2.interceptor.ServletRequestAware;
40 import org.apache.archiva.redback.integration.interceptor.SecureAction;
41 import org.apache.archiva.redback.integration.interceptor.SecureActionBundle;
42 import org.apache.archiva.redback.integration.interceptor.SecureActionException;
43 import org.springframework.context.annotation.Scope;
44 import org.springframework.stereotype.Controller;
46 import javax.inject.Inject;
47 import javax.servlet.http.HttpServletRequest;
48 import java.util.ArrayList;
49 import java.util.Collections;
50 import java.util.HashMap;
51 import java.util.List;
55 * Shows the Repositories Tab for the administrator.
59 @Controller( "repositoriesAction" )
61 public class RepositoriesAction
62 extends AbstractActionSupport
63 implements SecureAction, ServletRequestAware, Preparable
67 private ManagedRepositoryAdmin managedRepositoryAdmin;
70 private RemoteRepositoryAdmin remoteRepositoryAdmin;
73 private RepositoryGroupAdmin repositoryGroupAdmin;
75 private List<ManagedRepository> managedRepositories;
77 private List<RemoteRepository> remoteRepositories;
79 private Map<String, RepositoryStatistics> repositoryStatistics;
81 private Map<String, List<String>> repositoryToGroupMap;
84 * Used to construct the repository WebDAV URL in the repository action.
86 private String baseUrl;
90 private RepositoryStatisticsManager repositoryStatisticsManager;
92 public void setServletRequest( HttpServletRequest request )
94 // TODO: is there a better way to do this?
95 this.baseUrl = ContextUtils.getBaseURL( request, "repository" );
98 public SecureActionBundle getSecureActionBundle()
99 throws SecureActionException
101 SecureActionBundle bundle = new SecureActionBundle();
103 bundle.setRequiresAuthentication( true );
104 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
109 @SuppressWarnings( "unchecked" )
110 public void prepare()
111 throws RepositoryAdminException
113 remoteRepositories = new ArrayList<RemoteRepository>( getRemoteRepositoryAdmin().getRemoteRepositories() );
114 managedRepositories = new ArrayList<ManagedRepository>( getManagedRepositoryAdmin().getManagedRepositories() );
115 repositoryToGroupMap = getRepositoryGroupAdmin().getRepositoryToGroupMap();
117 Collections.sort( managedRepositories, new RepositoryComparator() );
118 Collections.sort( remoteRepositories, new RepositoryComparator() );
120 repositoryStatistics = new HashMap<String, RepositoryStatistics>();
121 RepositorySession repositorySession = repositorySessionFactory.createSession();
124 MetadataRepository metadataRepository = repositorySession.getRepository();
125 for ( ManagedRepository repo : managedRepositories )
127 RepositoryStatistics stats = null;
130 stats = repositoryStatisticsManager.getLastStatistics( metadataRepository, repo.getId() );
132 catch ( MetadataRepositoryException e )
135 "Error retrieving statistics for repository " + repo.getId() + " - consult application logs" );
136 log.warn( "Error retrieving repository statistics: " + e.getMessage(), e );
140 repositoryStatistics.put( repo.getId(), stats );
146 repositorySession.close();
150 public List<ManagedRepository> getManagedRepositories()
152 List<ManagedRepository> managedRepositoriesList = new ArrayList<ManagedRepository>();
153 for ( ManagedRepository repoConfig : managedRepositories )
155 if ( !repoConfig.getId().endsWith( "-stage" ) )
157 managedRepositoriesList.add( repoConfig );
160 return managedRepositoriesList;
163 public List<RemoteRepository> getRemoteRepositories()
165 return remoteRepositories;
168 public Map<String, RepositoryStatistics> getRepositoryStatistics()
170 return repositoryStatistics;
173 public String getBaseUrl()
178 public Map<String, List<String>> getRepositoryToGroupMap()
180 return repositoryToGroupMap;
183 public ManagedRepositoryAdmin getManagedRepositoryAdmin()
185 return managedRepositoryAdmin;
188 public void setManagedRepositoryAdmin( ManagedRepositoryAdmin managedRepositoryAdmin )
190 this.managedRepositoryAdmin = managedRepositoryAdmin;
193 public RemoteRepositoryAdmin getRemoteRepositoryAdmin()
195 return remoteRepositoryAdmin;
198 public void setRemoteRepositoryAdmin( RemoteRepositoryAdmin remoteRepositoryAdmin )
200 this.remoteRepositoryAdmin = remoteRepositoryAdmin;
203 public RepositoryGroupAdmin getRepositoryGroupAdmin()
205 return repositoryGroupAdmin;
208 public void setRepositoryGroupAdmin( RepositoryGroupAdmin repositoryGroupAdmin )
210 this.repositoryGroupAdmin = repositoryGroupAdmin;
213 public RepositoryStatisticsManager getRepositoryStatisticsManager()
215 return repositoryStatisticsManager;
218 public void setRepositoryStatisticsManager( RepositoryStatisticsManager repositoryStatisticsManager )
220 this.repositoryStatisticsManager = repositoryStatisticsManager;