[MRM-1514] api to configure OrganisationInfo : use it in webapp

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1167475 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-09-10 08:25:08 +00:00
parent 1f05224168
commit b9ae9f3e79
5 changed files with 41 additions and 42 deletions

View File

@ -20,9 +20,8 @@ package org.apache.maven.archiva.web.action.admin.appearance;
*/ */
import com.opensymphony.xwork2.Preparable; import com.opensymphony.xwork2.Preparable;
import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.admin.repository.admin.ArchivaAdministration;
import org.apache.maven.archiva.configuration.Configuration; import org.apache.archiva.admin.repository.admin.OrganisationInformation;
import org.apache.maven.archiva.configuration.OrganisationInformation;
import org.apache.maven.archiva.web.action.AbstractActionSupport; import org.apache.maven.archiva.web.action.AbstractActionSupport;
import javax.inject.Inject; import javax.inject.Inject;
@ -38,7 +37,7 @@ public abstract class AbstractAppearanceAction
{ {
@Inject @Inject
protected ArchivaConfiguration configuration; protected ArchivaAdministration archivaAdministration;
private String organisationLogo; private String organisationLogo;
@ -46,11 +45,6 @@ public abstract class AbstractAppearanceAction
private String organisationName; private String organisationName;
public void setConfiguration( ArchivaConfiguration configuration )
{
this.configuration = configuration;
}
public String getOrganisationLogo() public String getOrganisationLogo()
{ {
return organisationLogo; return organisationLogo;
@ -84,16 +78,24 @@ public abstract class AbstractAppearanceAction
public void prepare() public void prepare()
throws Exception throws Exception
{ {
Configuration config = configuration.getConfiguration();
if ( config != null ) OrganisationInformation orgInfo = archivaAdministration.getOrganisationInformation();
if ( orgInfo != null )
{ {
OrganisationInformation orgInfo = config.getOrganisationInfo(); setOrganisationLogo( orgInfo.getLogoLocation() );
if ( orgInfo != null ) setOrganisationName( orgInfo.getName() );
{ setOrganisationUrl( orgInfo.getUrl() );
setOrganisationLogo( orgInfo.getLogoLocation() );
setOrganisationName( orgInfo.getName() );
setOrganisationUrl( orgInfo.getUrl() );
}
} }
}
public ArchivaAdministration getArchivaAdministration()
{
return archivaAdministration;
}
public void setArchivaAdministration( ArchivaAdministration archivaAdministration )
{
this.archivaAdministration = archivaAdministration;
} }
} }

View File

@ -20,13 +20,11 @@ package org.apache.maven.archiva.web.action.admin.appearance;
*/ */
import com.opensymphony.xwork2.Validateable; import com.opensymphony.xwork2.Validateable;
import org.apache.archiva.admin.repository.RepositoryAdminException;
import org.apache.archiva.admin.repository.admin.OrganisationInformation;
import org.apache.archiva.security.common.ArchivaRoleConstants; import org.apache.archiva.security.common.ArchivaRoleConstants;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
import org.apache.maven.archiva.configuration.OrganisationInformation;
import org.codehaus.plexus.redback.rbac.Resource; import org.codehaus.plexus.redback.rbac.Resource;
import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.redback.integration.interceptor.SecureAction; import org.codehaus.redback.integration.interceptor.SecureAction;
import org.codehaus.redback.integration.interceptor.SecureActionBundle; import org.codehaus.redback.integration.interceptor.SecureActionBundle;
import org.codehaus.redback.integration.interceptor.SecureActionException; import org.codehaus.redback.integration.interceptor.SecureActionException;
@ -44,23 +42,16 @@ public class EditOrganisationInfoAction
{ {
@Override @Override
public String execute() public String execute()
throws RegistryException, IndeterminateConfigurationException throws RepositoryAdminException
{ {
Configuration config = configuration.getConfiguration();
if ( config != null )
{
OrganisationInformation orgInfo = config.getOrganisationInfo();
if ( orgInfo == null )
{
config.setOrganisationInfo( orgInfo );
}
orgInfo.setLogoLocation( getOrganisationLogo() ); OrganisationInformation orgInfo = archivaAdministration.getOrganisationInformation();
orgInfo.setName( getOrganisationName() );
orgInfo.setUrl( getOrganisationUrl() );
configuration.save( config ); orgInfo.setLogoLocation( getOrganisationLogo() );
} orgInfo.setName( getOrganisationName() );
orgInfo.setUrl( getOrganisationUrl() );
archivaAdministration.setOrganisationInformation( orgInfo );
return SUCCESS; return SUCCESS;
} }

View File

@ -19,6 +19,7 @@ package org.apache.maven.archiva.web.action.admin.appearance;
* under the License. * under the License.
*/ */
import org.apache.archiva.admin.repository.admin.DefaultArchivaAdministration;
import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.web.action.AbstractWebworkTestCase; import org.apache.maven.archiva.web.action.AbstractWebworkTestCase;
@ -50,17 +51,22 @@ public abstract class AbstractOrganizationInfoActionTest
configuration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); configuration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
configuration.getConfiguration(); configuration.getConfiguration();
archivaConfigurationControl.setReturnValue( config, 1, 2 ); archivaConfigurationControl.setReturnValue( config, 1, 5 );
configuration.save( config ); configuration.save( config );
archivaConfigurationControl.setVoidCallable( 1, 2 ); archivaConfigurationControl.setVoidCallable( 1, 4 );
archivaConfigurationControl.replay(); archivaConfigurationControl.replay();
DefaultArchivaAdministration defaultArchivaAdministration = new DefaultArchivaAdministration();
defaultArchivaAdministration.setArchivaConfiguration( configuration );
getAction().setArchivaAdministration( defaultArchivaAdministration );
} }
protected void reloadAction() protected void reloadAction()
{ {
action = getAction(); action = getAction();
action.setConfiguration( configuration ); ( (DefaultArchivaAdministration) action.getArchivaAdministration() ).setArchivaConfiguration( configuration );
} }
} }

View File

@ -20,9 +20,9 @@ package org.apache.maven.archiva.web.action.admin.appearance;
*/ */
import com.opensymphony.xwork2.validator.ActionValidatorManager; import com.opensymphony.xwork2.validator.ActionValidatorManager;
import org.apache.archiva.web.validator.utils.ValidatorUtil;
import org.apache.maven.archiva.configuration.OrganisationInformation; import org.apache.maven.archiva.configuration.OrganisationInformation;
import org.apache.maven.archiva.web.action.admin.repositories.DefaultActionValidatorManagerFactory; import org.apache.maven.archiva.web.action.admin.repositories.DefaultActionValidatorManagerFactory;
import org.apache.archiva.web.validator.utils.ValidatorUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -89,6 +89,8 @@ public class EditOrganizationInfoActionTest
action.execute(); action.execute();
orginfo = config.getOrganisationInfo();
assertEquals( "LOGO1", orginfo.getLogoLocation() ); assertEquals( "LOGO1", orginfo.getLogoLocation() );
assertEquals( "NAME1", orginfo.getName() ); assertEquals( "NAME1", orginfo.getName() );
assertEquals( "URL1", orginfo.getUrl() ); assertEquals( "URL1", orginfo.getUrl() );

View File

@ -49,8 +49,6 @@ public class OrganizationInfoActionTest
@Override @Override
protected AbstractAppearanceAction getAction() protected AbstractAppearanceAction getAction()
{ {
//return (OrganisationInfoAction) lookup( Action.class.getName(), "organisationInfo" );
return (OrganisationInfoAction) getActionProxy( "/components/companyInfo.action" ).getAction(); return (OrganisationInfoAction) getActionProxy( "/components/companyInfo.action" ).getAction();
} }
} }