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;
24 import org.apache.archiva.admin.model.RepositoryAdminException;
25 import org.apache.archiva.admin.model.remote.RemoteRepository;
26 import org.apache.maven.archiva.configuration.Configuration;
27 import org.springframework.context.annotation.Scope;
28 import org.springframework.stereotype.Controller;
31 * AddRemoteRepositoryAction
35 @Controller( "addRemoteRepositoryAction" )
37 public class AddRemoteRepositoryAction
38 extends AbstractRemoteRepositoriesAction
39 implements Preparable, Validateable
42 * The model for this action.
44 private RemoteRepository repository;
48 this.repository = new RemoteRepository();
56 public String commit()
59 String result = SUCCESS;
62 getRemoteRepositoryAdmin().addRemoteRepository( repository, getAuditInformation() );
64 catch ( RepositoryAdminException e )
66 addActionError( "RepositoryAdminException: " + e.getMessage() );
73 // FIXME olamy dupe with admin repo component
75 public void validate()
77 Configuration config = archivaConfiguration.getConfiguration();
79 String repoId = repository.getId();
81 if ( config.getManagedRepositoriesAsMap().containsKey( repoId ) )
83 addFieldError( "repository.id", "Unable to add new repository with id [" + repoId
84 + "], that id already exists as a managed repository." );
86 else if ( config.getRemoteRepositoriesAsMap().containsKey( repoId ) )
88 addFieldError( "repository.id", "Unable to add new repository with id [" + repoId
89 + "], that id already exists as a remote repository." );
91 else if ( config.getRepositoryGroupsAsMap().containsKey( repoId ) )
93 addFieldError( "repository.id", "Unable to add new repository with id [" + repoId
94 + "], that id already exists as a repository group." );
98 public RemoteRepository getRepository()
103 public void setRepository( RemoteRepository repository )
105 this.repository = repository;