mirror of https://github.com/apache/archiva.git
[MRM-1504] new repository admin module : start using it in webapp module for add.
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1163258 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c23eed84a3
commit
415ba43b68
|
@ -415,6 +415,37 @@
|
|||
<defaultValue>default</defaultValue>
|
||||
</field>
|
||||
</fields>
|
||||
<codeSegments>
|
||||
<codeSegment>
|
||||
<version>1.0.0+</version>
|
||||
<code><![CDATA[
|
||||
public int hashCode()
|
||||
{
|
||||
int result = 17;
|
||||
result = 37 * result + ( id != null ? id.hashCode() : 0 );
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean equals( Object other )
|
||||
{
|
||||
if ( this == other )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( !( other instanceof AbstractRepositoryConfiguration ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
AbstractRepositoryConfiguration that = (AbstractRepositoryConfiguration) other;
|
||||
boolean result = true;
|
||||
result = result && ( getId() == null ? that.getId() == null : getId().equals( that.getId() ) );
|
||||
return result;
|
||||
}
|
||||
]]></code>
|
||||
</codeSegment>
|
||||
</codeSegments>
|
||||
</class>
|
||||
<class>
|
||||
<name>RemoteRepositoryConfiguration</name>
|
||||
|
|
|
@ -108,7 +108,7 @@ public class DefaultManagedRepositoryAdmin
|
|||
|
||||
for ( ManagedRepositoryConfiguration repoConfig : managedRepoConfigs )
|
||||
{
|
||||
// TODO staging repo too
|
||||
// TODO add staging repo too
|
||||
ManagedRepository repo =
|
||||
new ManagedRepository( repoConfig.getId(), repoConfig.getName(), repoConfig.getLocation(),
|
||||
repoConfig.getLayout(), repoConfig.isSnapshots(), repoConfig.isReleases(),
|
||||
|
@ -179,7 +179,7 @@ public class DefaultManagedRepositoryAdmin
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME checKid non empty
|
||||
// FIXME checkId non empty
|
||||
|
||||
if ( !GenericValidator.matchRegexp( repoId, REPOSITORY_ID_VALID_EXPRESSION ) )
|
||||
{
|
||||
|
@ -583,4 +583,25 @@ public class DefaultManagedRepositoryAdmin
|
|||
|
||||
log.debug( "removed user roles associated with repository {}", repoId );
|
||||
}
|
||||
|
||||
|
||||
public ArchivaConfiguration getArchivaConfiguration()
|
||||
{
|
||||
return archivaConfiguration;
|
||||
}
|
||||
|
||||
public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
|
||||
{
|
||||
this.archivaConfiguration = archivaConfiguration;
|
||||
}
|
||||
|
||||
public RoleManager getRoleManager()
|
||||
{
|
||||
return roleManager;
|
||||
}
|
||||
|
||||
public void setRoleManager( RoleManager roleManager )
|
||||
{
|
||||
this.roleManager = roleManager;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.apache.archiva.admin.repository.managed;
|
|||
|
||||
import org.apache.archiva.admin.AuditInformation;
|
||||
import org.apache.archiva.admin.repository.RepositoryAdminException;
|
||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -48,5 +49,4 @@ public interface ManagedRepositoryAdmin
|
|||
AuditInformation auditInformation )
|
||||
throws RepositoryAdminException;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -276,7 +276,6 @@
|
|||
<dependency>
|
||||
<groupId>org.codehaus.redback</groupId>
|
||||
<artifactId>redback-rest-services</artifactId>
|
||||
<scope>runtime</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
|
|
|
@ -19,6 +19,8 @@ package org.apache.maven.archiva.web.action.admin.repositories;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.archiva.admin.AuditInformation;
|
||||
import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin;
|
||||
import org.apache.archiva.audit.Auditable;
|
||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||
import org.apache.maven.archiva.configuration.Configuration;
|
||||
|
@ -28,10 +30,13 @@ import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
|
|||
import org.apache.maven.archiva.security.ArchivaRoleConstants;
|
||||
import org.apache.maven.archiva.web.action.AbstractActionSupport;
|
||||
import org.codehaus.plexus.redback.rbac.Resource;
|
||||
import org.codehaus.plexus.redback.users.User;
|
||||
import org.codehaus.plexus.registry.RegistryException;
|
||||
import org.codehaus.redback.integration.interceptor.SecureAction;
|
||||
import org.codehaus.redback.integration.interceptor.SecureActionBundle;
|
||||
import org.codehaus.redback.integration.interceptor.SecureActionException;
|
||||
import org.codehaus.redback.rest.services.RedbackAuthenticationThreadLocal;
|
||||
import org.codehaus.redback.rest.services.RedbackRequestInformation;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.IOException;
|
||||
|
@ -56,6 +61,9 @@ public abstract class AbstractRepositoriesAdminAction
|
|||
@Inject
|
||||
protected ArchivaConfiguration archivaConfiguration;
|
||||
|
||||
@Inject
|
||||
private ManagedRepositoryAdmin managedRepositoryAdmin;
|
||||
|
||||
public ArchivaConfiguration getArchivaConfiguration()
|
||||
{
|
||||
return archivaConfiguration;
|
||||
|
@ -117,4 +125,25 @@ public abstract class AbstractRepositoriesAdminAction
|
|||
return new ArrayList<ProxyConnectorConfiguration>(
|
||||
archivaConfiguration.getConfiguration().getProxyConnectors() );
|
||||
}
|
||||
|
||||
|
||||
protected AuditInformation getAuditInformation()
|
||||
{
|
||||
RedbackRequestInformation redbackRequestInformation = RedbackAuthenticationThreadLocal.get();
|
||||
User user = redbackRequestInformation == null ? null : redbackRequestInformation.getUser();
|
||||
String remoteAddr = redbackRequestInformation == null ? "null" : redbackRequestInformation.getRemoteAddr();
|
||||
AuditInformation auditInformation = new AuditInformation( user, remoteAddr);
|
||||
|
||||
return auditInformation;
|
||||
}
|
||||
|
||||
public ManagedRepositoryAdmin getManagedRepositoryAdmin()
|
||||
{
|
||||
return managedRepositoryAdmin;
|
||||
}
|
||||
|
||||
public void setManagedRepositoryAdmin( ManagedRepositoryAdmin managedRepositoryAdmin )
|
||||
{
|
||||
this.managedRepositoryAdmin = managedRepositoryAdmin;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,25 +21,23 @@ package org.apache.maven.archiva.web.action.admin.repositories;
|
|||
|
||||
import com.opensymphony.xwork2.Preparable;
|
||||
import com.opensymphony.xwork2.Validateable;
|
||||
import org.apache.archiva.audit.AuditEvent;
|
||||
import org.apache.archiva.admin.repository.RepositoryAdminException;
|
||||
import org.apache.archiva.admin.repository.managed.ManagedRepository;
|
||||
import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.maven.archiva.configuration.Configuration;
|
||||
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
||||
import org.codehaus.plexus.redback.role.RoleManagerException;
|
||||
import org.codehaus.plexus.taskqueue.TaskQueueException;
|
||||
import org.codehaus.redback.components.scheduler.CronExpressionValidator;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* AddManagedRepositoryAction
|
||||
*
|
||||
* @version $Id$
|
||||
* <p/>
|
||||
* plexus.component role="com.opensymphony.xwork2.Action" role-hint="addManagedRepositoryAction" instantiation-strategy="per-lookup"
|
||||
*/
|
||||
@Controller( "addManagedRepositoryAction" )
|
||||
@Scope( "prototype" )
|
||||
|
@ -48,6 +46,7 @@ public class AddManagedRepositoryAction
|
|||
implements Preparable, Validateable
|
||||
{
|
||||
/**
|
||||
* FIXME we must manipulate beans from repo admin api
|
||||
* The model for this action.
|
||||
*/
|
||||
private ManagedRepositoryConfiguration repository;
|
||||
|
@ -93,56 +92,18 @@ public class AddManagedRepositoryAction
|
|||
|
||||
private String save()
|
||||
{
|
||||
Configuration configuration = archivaConfiguration.getConfiguration();
|
||||
|
||||
String result;
|
||||
String result = SUCCESS;
|
||||
try
|
||||
{
|
||||
addRepository( repository, configuration );
|
||||
triggerAuditEvent( repository.getId(), null, AuditEvent.ADD_MANAGED_REPO );
|
||||
addRepositoryRoles( repository );
|
||||
|
||||
if ( stageNeeded )
|
||||
{
|
||||
ManagedRepositoryConfiguration stagingRepository = getStageRepoConfig();
|
||||
|
||||
addRepository( stagingRepository, configuration );
|
||||
triggerAuditEvent( stagingRepository.getId(), null, AuditEvent.ADD_MANAGED_REPO );
|
||||
addRepositoryRoles( stagingRepository );
|
||||
|
||||
}
|
||||
|
||||
result = saveConfiguration( configuration );
|
||||
|
||||
//MRM-1342 Repository statistics report doesn't appear to be working correctly
|
||||
//scan repository when adding of repository is successful
|
||||
if ( result.equals( SUCCESS ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
executeRepositoryScanner( repository.getId() );
|
||||
|
||||
if ( stageNeeded )
|
||||
{
|
||||
ManagedRepositoryConfiguration stagingRepository = getStageRepoConfig();
|
||||
executeRepositoryScanner( stagingRepository.getId() );
|
||||
}
|
||||
}
|
||||
catch ( TaskQueueException e )
|
||||
{
|
||||
log.warn( new StringBuilder( "Unable to scan repository [" ).append( repository.getId() ).append( "]: " ).append(
|
||||
e.getMessage() ).toString(), e );
|
||||
}
|
||||
}
|
||||
ManagedRepository managedRepository =
|
||||
new ManagedRepository( repository.getId(), repository.getName(), repository.getLocation(),
|
||||
repository.getLayout(), repository.isSnapshots(), repository.isReleases(),
|
||||
repository.isBlockRedeployments(), repository.getRefreshCronExpression() );
|
||||
getManagedRepositoryAdmin().addManagedRepository( managedRepository, stageNeeded, getAuditInformation() );
|
||||
}
|
||||
catch ( RoleManagerException e )
|
||||
catch ( RepositoryAdminException e )
|
||||
{
|
||||
addActionError( "Role Manager Exception: " + e.getMessage() );
|
||||
result = INPUT;
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
addActionError( "Role Manager Exception: " + e.getMessage() );
|
||||
addActionError( "Repository Administration Exception: " + e.getMessage() );
|
||||
result = INPUT;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.apache.maven.archiva.web.action.admin.repositories;
|
|||
import com.opensymphony.xwork2.validator.ActionValidatorManager;
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin;
|
||||
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
|
||||
import org.apache.struts2.StrutsSpringTestCase;
|
||||
|
||||
|
@ -121,4 +122,9 @@ public abstract class AbstractManagedRepositoryActionTest
|
|||
|
||||
return managedRepositoryConfiguration;
|
||||
}
|
||||
|
||||
protected ManagedRepositoryAdmin getManagedRepositoryAdmin()
|
||||
{
|
||||
return applicationContext.getBean( ManagedRepositoryAdmin.class );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.maven.archiva.web.action.admin.repositories;
|
|||
*/
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
|
||||
import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
|
||||
import org.apache.archiva.scheduler.repository.RepositoryTask;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
@ -63,11 +64,12 @@ public class AddManagedRepositoryActionTest
|
|||
private MockControl registryControl;
|
||||
|
||||
private ArchivaConfiguration archivaConfiguration;
|
||||
|
||||
|
||||
private MockControl repositoryTaskSchedulerControl;
|
||||
|
||||
|
||||
private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
|
||||
|
||||
|
||||
@Override
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
|
@ -89,10 +91,14 @@ public class AddManagedRepositoryActionTest
|
|||
action.setRegistry( registry );
|
||||
|
||||
repositoryTaskSchedulerControl = MockClassControl.createControl( RepositoryArchivaTaskScheduler.class );
|
||||
repositoryTaskScheduler = ( RepositoryArchivaTaskScheduler ) repositoryTaskSchedulerControl.getMock();
|
||||
repositoryTaskScheduler = (RepositoryArchivaTaskScheduler) repositoryTaskSchedulerControl.getMock();
|
||||
action.setRepositoryTaskScheduler( repositoryTaskScheduler );
|
||||
|
||||
|
||||
location = new File( "target/test/location" );
|
||||
( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setArchivaConfiguration( archivaConfiguration );
|
||||
( (DefaultManagedRepositoryAdmin) getManagedRepositoryAdmin() ).setRoleManager( roleManager );
|
||||
action.setManagedRepositoryAdmin( getManagedRepositoryAdmin() );
|
||||
|
||||
}
|
||||
|
||||
public void testSecureActionBundle()
|
||||
|
@ -157,7 +163,7 @@ public class AddManagedRepositoryActionTest
|
|||
registryControl.setReturnValue( "target/test" );
|
||||
|
||||
registryControl.replay();
|
||||
|
||||
|
||||
RepositoryTask task = new RepositoryTask();
|
||||
task.setRepositoryId( REPO_ID );
|
||||
repositoryTaskScheduler.isProcessingRepositoryTask( REPO_ID );
|
||||
|
|
Loading…
Reference in New Issue