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.webwork.interceptor.ServletRequestAware;
23 import com.opensymphony.xwork.Preparable;
24 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
25 import org.apache.maven.archiva.configuration.Configuration;
26 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
27 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
28 import org.apache.maven.archiva.configuration.functors.RepositoryConfigurationComparator;
29 import org.apache.maven.archiva.database.ArchivaDAO;
30 import org.apache.maven.archiva.database.constraints.MostRecentRepositoryScanStatistics;
31 import org.apache.maven.archiva.model.RepositoryContentStatistics;
32 import org.apache.maven.archiva.security.ArchivaRoleConstants;
33 import org.apache.maven.archiva.web.util.ContextUtils;
34 import org.codehaus.plexus.redback.rbac.Resource;
35 import org.codehaus.plexus.redback.xwork.interceptor.SecureAction;
36 import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle;
37 import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException;
38 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
40 import javax.servlet.http.HttpServletRequest;
41 import java.util.ArrayList;
42 import java.util.Collections;
43 import java.util.HashMap;
44 import java.util.List;
48 * Shows the Repositories Tab for the administrator.
50 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
52 * @plexus.component role="com.opensymphony.xwork.Action" role-hint="repositoriesAction"
54 public class RepositoriesAction
55 extends PlexusActionSupport
56 implements SecureAction, ServletRequestAware, Preparable
61 private ArchivaConfiguration archivaConfiguration;
63 private List<ManagedRepositoryConfiguration> managedRepositories;
65 private List<RemoteRepositoryConfiguration> remoteRepositories;
67 private Map<String, RepositoryContentStatistics> repositoryStatistics;
69 private Map<String, List<String>> repositoryToGroupMap;
72 * @plexus.requirement role-hint="jdo"
74 private ArchivaDAO dao;
77 * Used to construct the repository WebDAV URL in the repository action.
79 private String baseUrl;
81 public void setServletRequest( HttpServletRequest request )
83 // TODO: is there a better way to do this?
84 this.baseUrl = ContextUtils.getBaseURL( request, "repository" );
87 public SecureActionBundle getSecureActionBundle()
88 throws SecureActionException
90 SecureActionBundle bundle = new SecureActionBundle();
92 bundle.setRequiresAuthentication( true );
93 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
100 Configuration config = archivaConfiguration.getConfiguration();
102 remoteRepositories = new ArrayList<RemoteRepositoryConfiguration>( config.getRemoteRepositories() );
103 managedRepositories = new ArrayList<ManagedRepositoryConfiguration>( config.getManagedRepositories() );
104 repositoryToGroupMap = config.getRepositoryToGroupMap();
106 Collections.sort( managedRepositories, new RepositoryConfigurationComparator() );
107 Collections.sort( remoteRepositories, new RepositoryConfigurationComparator() );
109 repositoryStatistics = new HashMap<String, RepositoryContentStatistics>();
110 for ( ManagedRepositoryConfiguration repo : managedRepositories )
112 List<RepositoryContentStatistics> results =
113 dao.query( new MostRecentRepositoryScanStatistics( repo.getId() ) );
114 if ( !results.isEmpty() )
116 repositoryStatistics.put( repo.getId(), results.get( 0 ) );
121 public List<ManagedRepositoryConfiguration> getManagedRepositories()
123 return managedRepositories;
126 public List<RemoteRepositoryConfiguration> getRemoteRepositories()
128 return remoteRepositories;
131 public Map<String, RepositoryContentStatistics> getRepositoryStatistics()
133 return repositoryStatistics;
136 public String getBaseUrl()
141 public Map<String, List<String>> getRepositoryToGroupMap()
143 return repositoryToGroupMap;