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 java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.HashMap;
25 import java.util.List;
27 import javax.servlet.http.HttpServletRequest;
29 import com.opensymphony.xwork2.Preparable;
30 import org.apache.archiva.metadata.repository.stats.RepositoryStatistics;
31 import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
32 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
33 import org.apache.maven.archiva.configuration.Configuration;
34 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
35 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
36 import org.apache.maven.archiva.configuration.functors.RepositoryConfigurationComparator;
37 import org.apache.maven.archiva.security.ArchivaRoleConstants;
38 import org.apache.maven.archiva.web.action.PlexusActionSupport;
39 import org.apache.maven.archiva.web.util.ContextUtils;
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;
47 * Shows the Repositories Tab for the administrator.
50 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="repositoriesAction" instantiation-strategy="per-lookup"
52 public class RepositoriesAction
53 extends PlexusActionSupport
54 implements SecureAction, ServletRequestAware, Preparable
59 private ArchivaConfiguration archivaConfiguration;
61 private List<ManagedRepositoryConfiguration> managedRepositories;
63 private List<RemoteRepositoryConfiguration> remoteRepositories;
65 private Map<String, RepositoryStatistics> repositoryStatistics;
67 private Map<String, List<String>> repositoryToGroupMap;
70 * Used to construct the repository WebDAV URL in the repository action.
72 private String baseUrl;
77 private RepositoryStatisticsManager repositoryStatisticsManager;
79 public void setServletRequest( HttpServletRequest request )
81 // TODO: is there a better way to do this?
82 this.baseUrl = ContextUtils.getBaseURL( request, "repository" );
85 public SecureActionBundle getSecureActionBundle()
86 throws SecureActionException
88 SecureActionBundle bundle = new SecureActionBundle();
90 bundle.setRequiresAuthentication( true );
91 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
96 @SuppressWarnings("unchecked")
99 Configuration config = archivaConfiguration.getConfiguration();
101 remoteRepositories = new ArrayList<RemoteRepositoryConfiguration>( config.getRemoteRepositories() );
102 managedRepositories = new ArrayList<ManagedRepositoryConfiguration>( config.getManagedRepositories() );
103 repositoryToGroupMap = config.getRepositoryToGroupMap();
105 Collections.sort( managedRepositories, new RepositoryConfigurationComparator() );
106 Collections.sort( remoteRepositories, new RepositoryConfigurationComparator() );
108 repositoryStatistics = new HashMap<String, RepositoryStatistics>();
109 for ( ManagedRepositoryConfiguration repo : managedRepositories )
111 RepositoryStatistics stats = repositoryStatisticsManager.getLastStatistics( repo.getId() );
114 repositoryStatistics.put( repo.getId(), stats );
119 public List<ManagedRepositoryConfiguration> getManagedRepositories()
121 return managedRepositories;
124 public List<RemoteRepositoryConfiguration> getRemoteRepositories()
126 return remoteRepositories;
129 public Map<String, RepositoryStatistics> getRepositoryStatistics()
131 return repositoryStatistics;
134 public String getBaseUrl()
139 public Map<String, List<String>> getRepositoryToGroupMap()
141 return repositoryToGroupMap;