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.ManagedRepositoryConfiguration;
27 import org.codehaus.plexus.redback.role.RoleManagerException;
28 import org.codehaus.plexus.scheduler.CronExpressionValidator;
30 import java.io.IOException;
33 * AddManagedRepositoryAction
37 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="addManagedRepositoryAction"
39 public class AddManagedRepositoryAction
40 extends AbstractManagedRepositoriesAction
41 implements Preparable, Validateable
44 * The model for this action.
46 private ManagedRepositoryConfiguration repository;
48 private String action = "addRepository";
52 this.repository = new ManagedRepositoryConfiguration();
53 this.repository.setReleases( false );
54 this.repository.setScanned( false );
59 this.repository.setReleases( true );
60 this.repository.setScanned( true );
65 public String confirmAdd()
70 public String commit()
72 File location = new File( repository.getLocation() );
73 if( location.exists() )
83 Configuration configuration = archivaConfiguration.getConfiguration();
88 addRepository( repository, configuration );
89 addRepositoryRoles( repository );
90 result = saveConfiguration( configuration );
92 catch ( RoleManagerException e )
94 addActionError( "Role Manager Exception: " + e.getMessage() );
97 catch ( IOException e )
99 addActionError( "Role Manager Exception: " + e.getMessage() );
107 public void validate()
109 Configuration config = archivaConfiguration.getConfiguration();
111 CronExpressionValidator validator = new CronExpressionValidator();
112 String repoId = repository.getId();
114 if ( config.getManagedRepositoriesAsMap().containsKey( repoId ) )
116 addFieldError( "repository.id", "Unable to add new repository with id [" + repoId
117 + "], that id already exists as a managed repository." );
119 else if ( config.getRemoteRepositoriesAsMap().containsKey( repoId ) )
121 addFieldError( "repository.id", "Unable to add new repository with id [" + repoId
122 + "], that id already exists as a remote repository." );
124 else if( config.getRepositoryGroupsAsMap().containsKey( repoId ) )
126 addFieldError( "repository.id", "Unable to add new repository with id [" + repoId
127 + "], that id already exists as a repository group." );
130 if ( !validator.validate( repository.getRefreshCronExpression() ) )
132 addFieldError( "repository.refreshCronExpression", "Invalid cron expression." );
136 public ManagedRepositoryConfiguration getRepository()
141 public void setRepository( ManagedRepositoryConfiguration repository )
143 this.repository = repository;
146 public String getAction()