]> source.dussan.org Git - archiva.git/commitdiff
[MRM-326]
authorMaria Odea B. Ching <oching@apache.org>
Tue, 24 Jul 2007 01:06:56 +0000 (01:06 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Tue, 24 Jul 2007 01:06:56 +0000 (01:06 +0000)
Submitted by Jan Ancajas

- Added validation in ConfigureRepositoryAction
- Added input and error results in saveRepository (xwork.xml)

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@558904 13f79535-47bb-0310-9956-ffa450edef68

archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRepositoryAction.java
archiva-web/archiva-webapp/src/main/resources/xwork.xml

index b86f7bf174a4d2e412f6d7aa06f370ca88e7f2a1..621d0e5ad9b63f3e492d2b385993675b198ed0da 100644 (file)
@@ -26,6 +26,7 @@ import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.common.utils.PathUtil;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+import org.apache.maven.archiva.configuration.Configuration;
 import org.apache.maven.archiva.configuration.InvalidConfigurationException;
 import org.apache.maven.archiva.configuration.RepositoryConfiguration;
 import org.apache.maven.archiva.security.ArchivaRoleConstants;
@@ -40,6 +41,7 @@ import org.codehaus.plexus.redback.xwork.interceptor.SecureAction;
 import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle;
 import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException;
 import org.codehaus.plexus.registry.RegistryException;
+import org.codehaus.plexus.scheduler.CronExpressionValidator;
 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
 
 import java.io.File;
@@ -212,13 +214,19 @@ public class ConfigureRepositoryAction
     {
         String mode = getMode();
         String repoId = getRepository().getId();
+        boolean containsError = false;
 
         getLogger().info( ".save(" + mode + ":" + repoId + ")" );
 
-        if ( StringUtils.isBlank( repository.getId() ) )
+        containsError = validateFields(mode);
+
+        if ( containsError && StringUtils.equalsIgnoreCase( "add", mode ) )
+        {            
+            return INPUT;
+        }
+        else if ( containsError && StringUtils.equalsIgnoreCase( "edit", mode )) 
         {
-            addFieldError( "id", "A repository with a blank id cannot be saved." );
-            return SUCCESS;
+            return ERROR;
         }
 
         if ( StringUtils.equalsIgnoreCase( "edit", mode ) )
@@ -251,6 +259,45 @@ public class ConfigureRepositoryAction
         return SUCCESS;
     }
 
+    private boolean validateFields(String mode)
+    {
+        boolean containsError = false;
+        CronExpressionValidator validator = new CronExpressionValidator();
+        Configuration config = archivaConfiguration.getConfiguration();
+        String repoId = getRepository().getId();
+
+        if ( StringUtils.isBlank( repoId ) )
+        {   
+            addFieldError( "repository.id", "You must enter a repository identifier." );
+            containsError = true;
+        }
+        //if edit mode, do not validate existence of repoId
+        else if ( config.findRepositoryById( repoId ) != null && !StringUtils.equalsIgnoreCase( mode, "edit" )  )
+        {
+            addFieldError( "repository.id", "Unable to add new repository with id [" + repoId + "], that id already exists." );
+            containsError = true;
+        }
+
+        if ( StringUtils.isBlank( repository.getUrl() ) )
+        {   
+            
+            addFieldError( "repository.url", "You must enter a directory or url." );
+            containsError = true;
+        }
+        if ( StringUtils.isBlank( repository.getName() ) )
+        {
+            addFieldError( "repository.name", "You must enter a repository name." );
+            containsError = true;
+        }
+        if ( !validator.validate( repository.getRefreshCronExpression() ) )
+        {
+            addFieldError( "repository.refreshCronExpression", "Invalid cron expression." );
+            containsError = true;
+        }
+
+        return containsError;
+    }
+
     public void setMode( String mode )
     {
         this.mode = mode;
index 1cbd63a755f8d81649e27607881210692b1db806..fd9c989a4591e6d520e56a23c1745eebb86bd32e 100644 (file)
     
     <action name="saveRepository" class="configureRepositoryAction" method="save">
       <result name="success" type="redirect-action">repositories</result>
+      <result name="input">/WEB-INF/jsp/admin/addRepository.jsp</result>
+      <result name="error">/WEB-INF/jsp/admin/editRepository.jsp</result>
       <interceptor-ref name="configuredPrepareParamsStack"/>
     </action>