mirror of https://github.com/apache/archiva.git
[MRM-326]
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
This commit is contained in:
parent
488303a9e8
commit
baa1c8af97
|
@ -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 ) )
|
||||
{
|
||||
addFieldError( "id", "A repository with a blank id cannot be saved." );
|
||||
return SUCCESS;
|
||||
return INPUT;
|
||||
}
|
||||
else if ( containsError && StringUtils.equalsIgnoreCase( "edit", mode ))
|
||||
{
|
||||
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;
|
||||
|
|
|
@ -258,6 +258,8 @@
|
|||
|
||||
<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>
|
||||
|
||||
|
|
Loading…
Reference in New Issue