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 org.apache.struts2.interceptor.ServletRequestAware;
23 import com.opensymphony.xwork2.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.apache.maven.archiva.web.action.PlexusActionSupport;
35 import org.codehaus.plexus.redback.rbac.Resource;
36 import org.codehaus.redback.integration.interceptor.SecureAction;
37 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
38 import org.codehaus.redback.integration.interceptor.SecureActionException;
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.
51 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="repositoriesAction" instantiation-strategy="per-lookup"
53 public class RepositoriesAction
54 extends PlexusActionSupport
55 implements SecureAction, ServletRequestAware, Preparable
60 private ArchivaConfiguration archivaConfiguration;
62 private List<ManagedRepositoryConfiguration> managedRepositories;
64 private List<RemoteRepositoryConfiguration> remoteRepositories;
66 private Map<String, RepositoryContentStatistics> repositoryStatistics;
68 private Map<String, List<String>> repositoryToGroupMap;
71 * @plexus.requirement role-hint="jdo"
73 private ArchivaDAO dao;
76 * Used to construct the repository WebDAV URL in the repository action.
78 private String baseUrl;
80 public void setServletRequest( HttpServletRequest request )
82 // TODO: is there a better way to do this?
83 this.baseUrl = ContextUtils.getBaseURL( request, "repository" );
86 public SecureActionBundle getSecureActionBundle()
87 throws SecureActionException
89 SecureActionBundle bundle = new SecureActionBundle();
91 bundle.setRequiresAuthentication( true );
92 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
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, RepositoryContentStatistics>();
109 for ( ManagedRepositoryConfiguration repo : managedRepositories )
111 List<RepositoryContentStatistics> results =
112 dao.query( new MostRecentRepositoryScanStatistics( repo.getId() ) );
113 if ( !results.isEmpty() )
115 repositoryStatistics.put( repo.getId(), results.get( 0 ) );
120 public List<ManagedRepositoryConfiguration> getManagedRepositories()
122 return managedRepositories;
125 public List<RemoteRepositoryConfiguration> getRemoteRepositories()
127 return remoteRepositories;
130 public Map<String, RepositoryContentStatistics> getRepositoryStatistics()
132 return repositoryStatistics;
135 public String getBaseUrl()
140 public Map<String, List<String>> getRepositoryToGroupMap()
142 return repositoryToGroupMap;