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.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
39 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="editManagedRepositoryAction"
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";
56 if ( StringUtils.isNotBlank( repoid ) )
58 repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoid );
60 else if ( repository != null )
62 repository.setReleases( false );
63 repository.setScanned( false );
69 if ( repository == null )
71 addActionError( "Edit failure, unable to edit a repository with a blank repository id." );
78 public String confirmUpdate()
83 public String commit()
85 ManagedRepositoryConfiguration existingConfig =
86 archivaConfiguration.getConfiguration().findManagedRepositoryById( repository.getId() );
88 // check if the location was changed
89 if( !StringUtils.equalsIgnoreCase( existingConfig.getLocation().trim(), repository.getLocation().trim() ) )
91 File dir = new File( repository.getLocation() );
101 private String save()
103 // Ensure that the fields are valid.
104 Configuration configuration = archivaConfiguration.getConfiguration();
106 // We are in edit mode, remove the old repository configuration.
107 removeRepository( repository.getId(), configuration );
109 // Save the repository configuration.
113 addRepository( repository, configuration );
114 addRepositoryRoles( repository );
115 result = saveConfiguration( configuration );
117 catch ( IOException e )
119 addActionError( "I/O Exception: " + e.getMessage() );
122 catch ( RoleManagerException e )
124 addActionError( "Role Manager Exception: " + e.getMessage() );
132 public void validate()
134 CronExpressionValidator validator = new CronExpressionValidator();
136 if ( !validator.validate( repository.getRefreshCronExpression() ) )
138 addFieldError( "repository.refreshCronExpression", "Invalid cron expression." );
142 public String getRepoid()
147 public void setRepoid( String repoid )
149 this.repoid = repoid;
152 public ManagedRepositoryConfiguration getRepository()
157 public void setRepository( ManagedRepositoryConfiguration repository )
159 this.repository = repository;
162 public String getAction()