*/
import com.opensymphony.xwork.Preparable;
+
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.Configuration;
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"
*/
*/
protected RoleManager roleManager;
+ private static final List<String> VALID_MODES;
+
+ static
+ {
+ VALID_MODES = new ArrayList<String>();
+ VALID_MODES.add( "add" );
+ VALID_MODES.add( "edit" );
+ }
+
public String add()
{
this.mode = "add";
this.repository.setReleases( true );
this.repository.setScanned( true );
- return INPUT;
+ return this.mode;
}
public String delete()
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;
}
}
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
{
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;
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() ) )