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;
70 * @plexus.requirement role-hint="jdo"
72 private ArchivaDAO dao;
75 * Used to construct the repository WebDAV URL in the repository action.
77 private String baseUrl;
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 );
98 Configuration config = archivaConfiguration.getConfiguration();
100 remoteRepositories = new ArrayList<RemoteRepositoryConfiguration>( config.getRemoteRepositories() );
101 managedRepositories = new ArrayList<ManagedRepositoryConfiguration>( config.getManagedRepositories() );
103 Collections.sort( managedRepositories, new RepositoryConfigurationComparator() );
104 Collections.sort( remoteRepositories, new RepositoryConfigurationComparator() );
106 repositoryStatistics = new HashMap<String, RepositoryContentStatistics>();
107 for ( ManagedRepositoryConfiguration repo : managedRepositories )
109 List<RepositoryContentStatistics> results =
110 dao.query( new MostRecentRepositoryScanStatistics( repo.getId() ) );
111 if ( !results.isEmpty() )
113 repositoryStatistics.put( repo.getId(), results.get( 0 ) );
118 public List<ManagedRepositoryConfiguration> getManagedRepositories()
120 return managedRepositories;
123 public List<RemoteRepositoryConfiguration> getRemoteRepositories()
125 return remoteRepositories;
128 public Map<String, RepositoryContentStatistics> getRepositoryStatistics()
130 return repositoryStatistics;
133 public String getBaseUrl()