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.List;
25 import javax.servlet.http.HttpServletRequest;
27 import com.opensymphony.webwork.interceptor.ServletRequestAware;
28 import com.opensymphony.xwork.Preparable;
30 import org.apache.commons.lang.StringUtils;
31 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
32 import org.apache.maven.archiva.configuration.Configuration;
33 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
34 import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration;
35 import org.apache.maven.archiva.security.ArchivaRoleConstants;
36 import org.apache.maven.archiva.web.util.ContextUtils;
39 * RepositoryGroupsAction
43 * @plexus.component role="com.opensymphony.xwork.Action" role-hint="repositoryGroupsAction"
45 public class RepositoryGroupsAction
46 extends AbstractRepositoriesAdminAction
47 implements ServletRequestAware, Preparable
49 private RepositoryGroupConfiguration repositoryGroup;
51 private Map<String, RepositoryGroupConfiguration> repositoryGroups;
53 private Map<String, ManagedRepositoryConfiguration> managedRepositories;
55 private Map<String, List<String>> groupToRepositoryMap;
57 private String repoGroupId;
59 private String repoId;
62 * Used to construct the repository WebDAV URL in the repository action.
64 private String baseUrl;
66 public void setServletRequest( HttpServletRequest request )
68 this.baseUrl = ContextUtils.getBaseURL( request, "repository" );
73 Configuration config = archivaConfiguration.getConfiguration();
75 repositoryGroup = new RepositoryGroupConfiguration();
76 repositoryGroups = config.getRepositoryGroupsAsMap();
77 managedRepositories = config.getManagedRepositoriesAsMap();
78 groupToRepositoryMap = config.getGroupToRepositoryMap();
81 public String addRepositoryGroup()
83 Configuration configuration = archivaConfiguration.getConfiguration();
85 String repoGroupId = repositoryGroup.getId();
87 if ( StringUtils.isBlank( repoGroupId ) )
89 addActionError( "You must enter a repository group id." );
93 if ( configuration.getRepositoryGroupsAsMap().containsKey( repoGroupId ) )
95 addActionError( "Unable to add new repository group with id [" + repoGroupId
96 + "], that id already exists as a repository group." );
99 else if ( configuration.getManagedRepositoriesAsMap().containsKey( repoGroupId ) )
101 addActionError( "Unable to add new repository group with id [" + repoGroupId
102 + "], that id already exists as a managed repository." );
105 else if ( configuration.getRemoteRepositoriesAsMap().containsKey( repoGroupId ) )
107 addActionError( "Unable to add new repository group with id [" + repoGroupId
108 + "], that id already exists as a remote repository." );
112 if( repoGroupId.length() > 100 )
114 addActionError( "Identifier [" + repoGroupId + "] is over the maximum limit of 100 characters" );
118 configuration.addRepositoryGroup( repositoryGroup );
119 return saveConfiguration( configuration );
122 public String addRepositoryToGroup()
124 Configuration config = archivaConfiguration.getConfiguration();
125 RepositoryGroupConfiguration group = config.findRepositoryGroupById( repoGroupId );
127 validateRepository();
134 if ( group.getRepositories().contains( repoId ) )
136 addActionError( "Repository with id [" + repoId + "] is already in the group" );
140 // remove the old repository group configuration
141 config.removeRepositoryGroup( group );
143 // save repository group configuration
144 group.addRepository( repoId );
145 config.addRepositoryGroup( group );
147 return saveConfiguration( config );
150 public String removeRepositoryFromGroup()
152 Configuration config = archivaConfiguration.getConfiguration();
153 RepositoryGroupConfiguration group = config.findRepositoryGroupById( repoGroupId );
155 validateRepository();
162 if ( !group.getRepositories().contains( repoId ) )
164 addActionError( "No repository with id[" + repoId + "] found in the group" );
168 // remove the old repository group configuration
169 config.removeRepositoryGroup( group );
171 // save repository group configuration
172 group.removeRepository( repoId );
173 config.addRepositoryGroup( group );
175 return saveConfiguration( config );
178 public void validateRepository()
180 Configuration config = archivaConfiguration.getConfiguration();
181 RepositoryGroupConfiguration group = config.findRepositoryGroupById( repoGroupId );
182 ManagedRepositoryConfiguration repo = config.findManagedRepositoryById( repoId );
186 addActionError( "A repository group with that id does not exist." );
191 addActionError( "A repository with that id does not exist." );
195 public RepositoryGroupConfiguration getRepositoryGroup()
197 return repositoryGroup;
200 public void setRepositoryGroup( RepositoryGroupConfiguration repositoryGroup )
202 this.repositoryGroup = repositoryGroup;
205 public Map<String, RepositoryGroupConfiguration> getRepositoryGroups()
207 return repositoryGroups;
210 public void setRepositoryGroups( Map<String, RepositoryGroupConfiguration> repositoryGroups )
212 this.repositoryGroups = repositoryGroups;
215 public Map<String, ManagedRepositoryConfiguration> getManagedRepositories()
217 return managedRepositories;
220 public Map<String, List<String>> getGroupToRepositoryMap()
222 return this.groupToRepositoryMap;
225 public String getRepoGroupId()
230 public void setRepoGroupId( String repoGroupId )
232 this.repoGroupId = repoGroupId;
235 public String getRepoId()
240 public void setRepoId( String repoId )
242 this.repoId = repoId;
245 public String getBaseUrl()