From: Joakim Erdfelt Date: Mon, 24 Sep 2007 23:16:50 +0000 (+0000) Subject: [MRM-494] leaving repository ID blank on the add repository page goes to the edit... X-Git-Tag: archiva-1.0-beta-3~154 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=503001adf39651bd1c39c9ea1f35fe1ec8b7f494;p=archiva.git [MRM-494] leaving repository ID blank on the add repository page goes to the edit page where ID cannot be edited Spliting webwork definition of INPUT into ADD/EDIT, and correcting validations. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@579016 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRepositoryAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRepositoryAction.java index d09f762fc..d004cdd82 100644 --- a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRepositoryAction.java +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRepositoryAction.java @@ -20,6 +20,7 @@ package org.apache.maven.archiva.web.action.admin.repositories; */ import com.opensymphony.xwork.Preparable; + import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.Configuration; @@ -32,9 +33,11 @@ import org.codehaus.plexus.scheduler.CronExpressionValidator; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; /** - * Configures the application repositories. + * Configures the managed repositories. * * @plexus.component role="com.opensymphony.xwork.Action" role-hint="configureRepositoryAction" */ @@ -52,6 +55,15 @@ public class ConfigureRepositoryAction */ protected RoleManager roleManager; + private static final List VALID_MODES; + + static + { + VALID_MODES = new ArrayList(); + VALID_MODES.add( "add" ); + VALID_MODES.add( "edit" ); + } + public String add() { this.mode = "add"; @@ -59,7 +71,7 @@ public class ConfigureRepositoryAction this.repository.setReleases( true ); this.repository.setScanned( true ); - return INPUT; + return this.mode; } public String delete() @@ -92,22 +104,22 @@ public class ConfigureRepositoryAction catch ( IOException e ) { addActionError( "Unable to delete repository: " + e.getMessage() ); - result = INPUT; + result = ERROR; } catch ( RoleManagerException e ) { addActionError( "Unable to delete repository: " + e.getMessage() ); - result = INPUT; + result = ERROR; } catch ( InvalidConfigurationException e ) { addActionError( "Unable to delete repository: " + e.getMessage() ); - result = INPUT; + result = ERROR; } catch ( RegistryException e ) { addActionError( "Unable to delete repository: " + e.getMessage() ); - result = INPUT; + result = ERROR; } } @@ -136,25 +148,35 @@ public class ConfigureRepositoryAction public String save() { - String repoId = repository.getId(); + // Ensure a proper mode is set. + if ( StringUtils.isBlank( this.mode ) ) + { + addActionError( "Unable to process save request. edit mode undefined. " ); + return ERROR; + } + + if ( !VALID_MODES.contains( this.mode.toLowerCase() ) ) + { + addActionError( "Unable to process save request. edit mode is invalid." ); + return ERROR; + } + // Ensure that the fields are valid. Configuration configuration = archivaConfiguration.getConfiguration(); boolean containsError = validateFields( configuration ); - if ( containsError && StringUtils.equalsIgnoreCase( "add", mode ) ) - { - return INPUT; - } - else if ( containsError && StringUtils.equalsIgnoreCase( "edit", this.mode ) ) + if ( containsError ) { - return ERROR; + return this.mode.toLowerCase(); } + // If we are in edit mode, then remove the old repository configuration. if ( StringUtils.equalsIgnoreCase( "edit", this.mode ) ) { - removeRepository( repoId, configuration ); + removeRepository( repository.getId(), configuration ); } + // Save the repository configuration. String result; try { @@ -164,22 +186,22 @@ public class ConfigureRepositoryAction catch ( IOException e ) { addActionError( "I/O Exception: " + e.getMessage() ); - result = INPUT; + result = ERROR; } catch ( RoleManagerException e ) { addActionError( "Role Manager Exception: " + e.getMessage() ); - result = INPUT; + result = ERROR; } catch ( InvalidConfigurationException e ) { addActionError( "Invalid Configuration Exception: " + e.getMessage() ); - result = INPUT; + result = ERROR; } catch ( RegistryException e ) { addActionError( "Configuration Registry Exception: " + e.getMessage() ); - result = INPUT; + result = ERROR; } return result; @@ -196,14 +218,22 @@ public class ConfigureRepositoryAction addFieldError( "repository.id", "You must enter a repository identifier." ); containsError = true; } - //if edit mode, do not validate existence of repoId - else if ( ( config.getManagedRepositoriesAsMap().containsKey( repoId ) || - config.getRemoteRepositoriesAsMap().containsKey( repoId ) ) && - !StringUtils.equalsIgnoreCase( mode, "edit" ) ) + // Validate the existance of the repository id, but not in edit mode. + else if ( !StringUtils.equalsIgnoreCase( mode, "edit" ) ) { - addFieldError( "repository.id", - "Unable to add new repository with id [" + repoId + "], that id already exists." ); - containsError = true; + if ( config.getManagedRepositoriesAsMap().containsKey( repoId ) ) + { + addFieldError( "repository.id", "Unable to add new repository with id [" + repoId + + "], that id already exists as a managed repository." ); + containsError = true; + } + + if ( config.getRemoteRepositoriesAsMap().containsKey( repoId ) ) + { + addFieldError( "repository.id", "Unable to add new repository with id [" + repoId + + "], that id already exists as a remote repository." ); + containsError = true; + } } if ( StringUtils.isBlank( repository.getLocation() ) ) diff --git a/archiva-web/archiva-webapp/src/main/resources/xwork.xml b/archiva-web/archiva-webapp/src/main/resources/xwork.xml index 556120b19..11df48425 100644 --- a/archiva-web/archiva-webapp/src/main/resources/xwork.xml +++ b/archiva-web/archiva-webapp/src/main/resources/xwork.xml @@ -243,8 +243,10 @@ repositories + /WEB-INF/jsp/admin/addRepository.jsp + /WEB-INF/jsp/admin/editRepository.jsp /WEB-INF/jsp/admin/editRepository.jsp - /WEB-INF/jsp/admin/editRepository.jsp + repositories