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
23 import java.io.IOException;
25 import com.opensymphony.xwork2.Preparable;
26 import com.opensymphony.xwork2.Validateable;
27 import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
28 import org.apache.commons.lang.StringUtils;
29 import org.apache.maven.archiva.configuration.Configuration;
30 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
31 import org.apache.maven.archiva.repository.audit.AuditEvent;
32 import org.codehaus.plexus.redback.role.RoleManagerException;
33 import org.codehaus.plexus.scheduler.CronExpressionValidator;
36 * AddManagedRepositoryAction
39 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="editManagedRepositoryAction" instantiation-strategy="per-lookup"
41 public class EditManagedRepositoryAction
42 extends AbstractManagedRepositoriesAction
43 implements Preparable, Validateable
46 * The model for this action.
48 private ManagedRepositoryConfiguration repository;
50 private String repoid;
52 private final String action = "editRepository";
57 private RepositoryStatisticsManager repositoryStatisticsManager;
61 if ( StringUtils.isNotBlank( repoid ) )
63 repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoid );
65 else if ( repository != null )
67 repository.setReleases( false );
68 repository.setScanned( false );
74 if ( repository == null )
76 addActionError( "Edit failure, unable to edit a repository with a blank repository id." );
83 public String confirmUpdate()
85 // location was changed
89 public String commit()
91 ManagedRepositoryConfiguration existingConfig =
92 archivaConfiguration.getConfiguration().findManagedRepositoryById( repository.getId() );
94 boolean resetStats = false;
96 // check if the location was changed
97 if ( !StringUtils.equalsIgnoreCase( existingConfig.getLocation().trim(), repository.getLocation().trim() ) )
101 File dir = new File( repository.getLocation() );
108 return save( resetStats );
111 private String save( boolean resetStats )
113 // Ensure that the fields are valid.
114 Configuration configuration = archivaConfiguration.getConfiguration();
116 // We are in edit mode, remove the old repository configuration.
117 removeRepository( repository.getId(), configuration );
119 // Save the repository configuration.
123 addRepository( repository, configuration );
124 triggerAuditEvent( repository.getId(), null, AuditEvent.MODIFY_MANAGED_REPO );
125 addRepositoryRoles( repository );
126 result = saveConfiguration( configuration );
132 catch ( IOException e )
134 addActionError( "I/O Exception: " + e.getMessage() );
137 catch ( RoleManagerException e )
139 addActionError( "Role Manager Exception: " + e.getMessage() );
147 public void validate()
149 CronExpressionValidator validator = new CronExpressionValidator();
151 if ( !validator.validate( repository.getRefreshCronExpression() ) )
153 addFieldError( "repository.refreshCronExpression", "Invalid cron expression." );
157 private void resetStatistics()
159 repositoryStatisticsManager.deleteStatistics( repository.getId() );
162 public String getRepoid()
167 public void setRepoid( String repoid )
169 this.repoid = repoid;
172 public ManagedRepositoryConfiguration getRepository()
177 public void setRepository( ManagedRepositoryConfiguration repository )
179 this.repository = repository;
182 public String getAction()
187 public void setRepositoryStatisticsManager( RepositoryStatisticsManager repositoryStatisticsManager )
189 this.repositoryStatisticsManager = repositoryStatisticsManager;