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.xwork2.Preparable;
23 import com.opensymphony.xwork2.Validateable;
25 import org.apache.maven.archiva.configuration.Configuration;
26 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
27 import org.apache.maven.archiva.repository.audit.AuditEvent;
28 import org.codehaus.plexus.redback.role.RoleManagerException;
30 import java.io.IOException;
33 * AddRemoteRepositoryAction
37 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="addRemoteRepositoryAction" instantiation-strategy="per-lookup"
39 public class AddRemoteRepositoryAction
40 extends AbstractRemoteRepositoriesAction
41 implements Preparable, Validateable
44 * The model for this action.
46 private RemoteRepositoryConfiguration repository;
50 this.repository = new RemoteRepositoryConfiguration();
58 public String commit()
60 Configuration configuration = archivaConfiguration.getConfiguration();
62 //MRM-752 - url needs trimming
63 repository.setUrl(repository.getUrl().trim());
65 // Save the repository configuration.
69 addRepository( repository, configuration );
70 triggerAuditEvent( repository.getId(), null, AuditEvent.ADD_REMOTE_REPO );
71 result = saveConfiguration( configuration );
73 catch ( IOException e )
75 addActionError( "I/O Exception: " + e.getMessage() );
78 catch ( RoleManagerException e )
80 addActionError( "Role Manager Exception: " + e.getMessage() );
88 public void validate()
90 Configuration config = archivaConfiguration.getConfiguration();
92 String repoId = repository.getId();
94 if ( config.getManagedRepositoriesAsMap().containsKey( repoId ) )
96 addFieldError( "repository.id", "Unable to add new repository with id [" + repoId
97 + "], that id already exists as a managed repository." );
99 else if ( config.getRemoteRepositoriesAsMap().containsKey( repoId ) )
101 addFieldError( "repository.id", "Unable to add new repository with id [" + repoId
102 + "], that id already exists as a remote repository." );
104 else if( config.getRepositoryGroupsAsMap().containsKey( repoId ) )
106 addFieldError( "repository.id", "Unable to add new repository with id [" + repoId
107 + "], that id already exists as a repository group." );
111 public RemoteRepositoryConfiguration getRepository()
116 public void setRepository( RemoteRepositoryConfiguration repository )
118 this.repository = repository;