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.List;
24 import javax.servlet.http.HttpServletRequest;
26 import com.opensymphony.webwork.interceptor.ServletRequestAware;
27 import com.opensymphony.xwork.Preparable;
29 import org.apache.commons.lang.StringUtils;
30 import org.apache.maven.archiva.configuration.Configuration;
31 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
32 import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration;
33 import org.apache.maven.archiva.web.util.ContextUtils;
36 * RepositoryGroupsAction
40 * @plexus.component role="com.opensymphony.xwork.Action" role-hint="repositoryGroupsAction"
42 public class RepositoryGroupsAction
43 extends AbstractRepositoriesAdminAction
44 implements ServletRequestAware, Preparable
46 private RepositoryGroupConfiguration repositoryGroup;
48 private Map<String, RepositoryGroupConfiguration> repositoryGroups;
50 private Map<String, ManagedRepositoryConfiguration> managedRepositories;
52 private Map<String, List<String>> groupToRepositoryMap;
54 private String repoGroupId;
56 private String repoId;
59 * Used to construct the repository WebDAV URL in the repository action.
61 private String baseUrl;
63 public void setServletRequest( HttpServletRequest request )
65 this.baseUrl = ContextUtils.getBaseURL( request, "repository" );
70 Configuration config = archivaConfiguration.getConfiguration();
72 repositoryGroup = new RepositoryGroupConfiguration();
73 repositoryGroups = config.getRepositoryGroupsAsMap();
74 managedRepositories = config.getManagedRepositoriesAsMap();
75 groupToRepositoryMap = config.getGroupToRepositoryMap();
78 public String addRepositoryGroup()
80 Configuration configuration = archivaConfiguration.getConfiguration();
82 String repoGroupId = repositoryGroup.getId();
84 if ( StringUtils.isBlank( repoGroupId ) )
86 addActionError( "You must enter a repository group id." );
90 if ( configuration.getRepositoryGroupsAsMap().containsKey( repoGroupId ) )
92 addActionError( "Unable to add new repository group with id [" + repoGroupId
93 + "], that id already exists as a repository group." );
96 else if ( configuration.getManagedRepositoriesAsMap().containsKey( repoGroupId ) )
98 addActionError( "Unable to add new repository group with id [" + repoGroupId
99 + "], that id already exists as a managed repository." );
102 else if ( configuration.getRemoteRepositoriesAsMap().containsKey( repoGroupId ) )
104 addActionError( "Unable to add new repository group with id [" + repoGroupId
105 + "], that id already exists as a remote repository." );
109 if( repoGroupId.length() > 100 )
111 addActionError( "Identifier [" + repoGroupId + "] is over the maximum limit of 100 characters" );
115 configuration.addRepositoryGroup( repositoryGroup );
116 return saveConfiguration( configuration );
119 public String addRepositoryToGroup()
121 Configuration config = archivaConfiguration.getConfiguration();
122 RepositoryGroupConfiguration group = config.findRepositoryGroupById( repoGroupId );
124 validateRepository();
131 if ( group.getRepositories().contains( repoId ) )
133 addActionError( "Repository with id [" + repoId + "] is already in the group" );
137 // remove the old repository group configuration
138 config.removeRepositoryGroup( group );
140 // save repository group configuration
141 group.addRepository( repoId );
142 config.addRepositoryGroup( group );
144 return saveConfiguration( config );
147 public String removeRepositoryFromGroup()
149 Configuration config = archivaConfiguration.getConfiguration();
150 RepositoryGroupConfiguration group = config.findRepositoryGroupById( repoGroupId );
152 validateRepository();
159 if ( !group.getRepositories().contains( repoId ) )
161 addActionError( "No repository with id[" + repoId + "] found in the group" );
165 // remove the old repository group configuration
166 config.removeRepositoryGroup( group );
168 // save repository group configuration
169 group.removeRepository( repoId );
170 config.addRepositoryGroup( group );
172 return saveConfiguration( config );
175 public void validateRepository()
177 Configuration config = archivaConfiguration.getConfiguration();
178 RepositoryGroupConfiguration group = config.findRepositoryGroupById( repoGroupId );
179 ManagedRepositoryConfiguration repo = config.findManagedRepositoryById( repoId );
183 addActionError( "A repository group with that id does not exist." );
188 addActionError( "A repository with that id does not exist." );
192 public RepositoryGroupConfiguration getRepositoryGroup()
194 return repositoryGroup;
197 public void setRepositoryGroup( RepositoryGroupConfiguration repositoryGroup )
199 this.repositoryGroup = repositoryGroup;
202 public Map<String, RepositoryGroupConfiguration> getRepositoryGroups()
204 return repositoryGroups;
207 public void setRepositoryGroups( Map<String, RepositoryGroupConfiguration> repositoryGroups )
209 this.repositoryGroups = repositoryGroups;
212 public Map<String, ManagedRepositoryConfiguration> getManagedRepositories()
214 return managedRepositories;
217 public Map<String, List<String>> getGroupToRepositoryMap()
219 return this.groupToRepositoryMap;
222 public String getRepoGroupId()
227 public void setRepoGroupId( String repoGroupId )
229 this.repoGroupId = repoGroupId;
232 public String getRepoId()
237 public void setRepoId( String repoId )
239 this.repoId = repoId;
242 public String getBaseUrl()