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.apache.maven.archiva.repository.audit.AuditEvent;
28 import org.codehaus.plexus.redback.role.RoleManagerException;
29 import org.codehaus.plexus.scheduler.CronExpressionValidator;
31 import java.io.IOException;
34 * AddManagedRepositoryAction
38 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="addManagedRepositoryAction" instantiation-strategy="per-lookup"
40 public class AddManagedRepositoryAction
41 extends AbstractManagedRepositoriesAction
42 implements Preparable, Validateable
45 * The model for this action.
47 private ManagedRepositoryConfiguration repository;
49 private String action = "addRepository";
53 this.repository = new ManagedRepositoryConfiguration();
54 this.repository.setReleases( false );
55 this.repository.setScanned( false );
56 this.repository.setBlockRedeployments( false );
61 this.repository.setReleases( true );
62 this.repository.setScanned( true );
63 this.repository.setBlockRedeployments( true );
68 public String confirmAdd()
73 public String commit()
75 File location = new File( repository.getLocation() );
76 if( location.exists() )
86 Configuration configuration = archivaConfiguration.getConfiguration();
91 addRepository( repository, configuration );
92 triggerAuditEvent( repository.getId(), null, AuditEvent.ADD_MANAGED_REPO );
93 addRepositoryRoles( repository );
94 result = saveConfiguration( configuration );
96 catch ( RoleManagerException e )
98 addActionError( "Role Manager Exception: " + e.getMessage() );
101 catch ( IOException e )
103 addActionError( "Role Manager Exception: " + e.getMessage() );
111 public void validate()
113 Configuration config = archivaConfiguration.getConfiguration();
115 CronExpressionValidator validator = new CronExpressionValidator();
116 String repoId = repository.getId();
118 if ( config.getManagedRepositoriesAsMap().containsKey( repoId ) )
120 addFieldError( "repository.id", "Unable to add new repository with id [" + repoId
121 + "], that id already exists as a managed repository." );
123 else if ( config.getRemoteRepositoriesAsMap().containsKey( repoId ) )
125 addFieldError( "repository.id", "Unable to add new repository with id [" + repoId
126 + "], that id already exists as a remote repository." );
128 else if( config.getRepositoryGroupsAsMap().containsKey( repoId ) )
130 addFieldError( "repository.id", "Unable to add new repository with id [" + repoId
131 + "], that id already exists as a repository group." );
134 if ( !validator.validate( repository.getRefreshCronExpression() ) )
136 addFieldError( "repository.refreshCronExpression", "Invalid cron expression." );
140 public ManagedRepositoryConfiguration getRepository()
145 public void setRepository( ManagedRepositoryConfiguration repository )
147 this.repository = repository;
150 public String getAction()