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.xwork.Preparable;
23 import com.opensymphony.xwork.Validateable;
25 import org.apache.commons.lang.StringUtils;
26 import org.apache.maven.archiva.configuration.Configuration;
27 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
28 import org.codehaus.plexus.redback.role.RoleManagerException;
29 import org.codehaus.plexus.scheduler.CronExpressionValidator;
32 import java.io.IOException;
35 * AddManagedRepositoryAction
37 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
40 * @plexus.component role="com.opensymphony.xwork.Action" role-hint="editManagedRepositoryAction"
42 public class EditManagedRepositoryAction
43 extends AbstractManagedRepositoriesAction
44 implements Preparable, Validateable
47 * The model for this action.
49 private ManagedRepositoryConfiguration repository;
51 private String repoid;
53 private final String action = "editRepository";
57 if ( StringUtils.isNotBlank( repoid ) )
59 repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoid );
61 else if ( repository != null )
63 repository.setReleases( false );
64 repository.setScanned( false );
70 if ( repository == null )
72 addActionError( "Edit failure, unable to edit a repository with a blank repository id." );
79 public String confirmUpdate()
84 public String commit()
86 ManagedRepositoryConfiguration existingConfig =
87 archivaConfiguration.getConfiguration().findManagedRepositoryById( repository.getId() );
89 // check if the location was changed
90 if( !StringUtils.equalsIgnoreCase( existingConfig.getLocation().trim(), repository.getLocation().trim() ) )
92 File dir = new File( repository.getLocation() );
102 private String save()
104 // Ensure that the fields are valid.
105 Configuration configuration = archivaConfiguration.getConfiguration();
107 // We are in edit mode, remove the old repository configuration.
108 removeRepository( repository.getId(), configuration );
110 // Save the repository configuration.
114 addRepository( repository, configuration );
115 addRepositoryRoles( repository );
116 result = saveConfiguration( configuration );
118 catch ( IOException e )
120 addActionError( "I/O Exception: " + e.getMessage() );
123 catch ( RoleManagerException e )
125 addActionError( "Role Manager Exception: " + e.getMessage() );
133 public void validate()
135 CronExpressionValidator validator = new CronExpressionValidator();
137 if ( !validator.validate( repository.getRefreshCronExpression() ) )
139 addFieldError( "repository.refreshCronExpression", "Invalid cron expression." );
143 public String getRepoid()
148 public void setRepoid( String repoid )
150 this.repoid = repoid;
153 public ManagedRepositoryConfiguration getRepository()
158 public void setRepository( ManagedRepositoryConfiguration repository )
160 this.repository = repository;
163 public String getAction()