fix bean mapping and init of ttl values from spring bean

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1425373 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-12-22 23:44:08 +00:00
parent 292087cbea
commit 4119701f84
3 changed files with 140 additions and 38 deletions

View File

@ -0,0 +1,77 @@
package org.apache.archiva.admin.model.beans;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
/**
* @author Olivier Lamy
* @since 1.4-M4
*/
@XmlRootElement( name = "cacheConfiguration" )
public class CacheConfiguration
implements Serializable
{
/**
* TimeToIdleSeconds.
*/
private int timeToIdleSeconds = -1;
/**
* TimeToLiveSeconds.
*/
private int timeToLiveSeconds = -1;
public CacheConfiguration()
{
// no op
}
public int getTimeToIdleSeconds()
{
return timeToIdleSeconds;
}
public void setTimeToIdleSeconds( int timeToIdleSeconds )
{
this.timeToIdleSeconds = timeToIdleSeconds;
}
public int getTimeToLiveSeconds()
{
return timeToLiveSeconds;
}
public void setTimeToLiveSeconds( int timeToLiveSeconds )
{
this.timeToLiveSeconds = timeToLiveSeconds;
}
@Override
public String toString()
{
final StringBuilder sb = new StringBuilder();
sb.append( "CacheConfiguration" );
sb.append( "{timeToIdleSeconds=" ).append( timeToIdleSeconds );
sb.append( ", timeToLiveSeconds=" ).append( timeToLiveSeconds );
sb.append( '}' );
return sb.toString();
}
}

View File

@ -20,12 +20,14 @@ package org.apache.archiva.admin.repository.runtime;
import net.sf.beanlib.provider.replicator.BeanReplicator; import net.sf.beanlib.provider.replicator.BeanReplicator;
import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.admin.model.beans.CacheConfiguration;
import org.apache.archiva.admin.model.beans.LdapConfiguration; import org.apache.archiva.admin.model.beans.LdapConfiguration;
import org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration; import org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration;
import org.apache.archiva.admin.model.runtime.RedbackRuntimeConfigurationAdmin; import org.apache.archiva.admin.model.runtime.RedbackRuntimeConfigurationAdmin;
import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.Configuration;
import org.apache.archiva.configuration.IndeterminateConfigurationException; import org.apache.archiva.configuration.IndeterminateConfigurationException;
import org.apache.archiva.redback.components.cache.Cache;
import org.apache.archiva.redback.components.registry.RegistryException; import org.apache.archiva.redback.components.registry.RegistryException;
import org.apache.archiva.redback.configuration.UserConfiguration; import org.apache.archiva.redback.configuration.UserConfiguration;
import org.apache.archiva.redback.configuration.UserConfigurationException; import org.apache.archiva.redback.configuration.UserConfigurationException;
@ -58,6 +60,10 @@ public class DefaultRedbackRuntimeConfigurationAdmin
@Named( value = "userConfiguration#redback" ) @Named( value = "userConfiguration#redback" )
UserConfiguration userConfiguration; UserConfiguration userConfiguration;
@Inject
@Named( value = "cache#users" )
private Cache usersCache;
@PostConstruct @PostConstruct
public void initialize() public void initialize()
throws UserConfigurationException throws UserConfigurationException
@ -104,7 +110,6 @@ public class DefaultRedbackRuntimeConfigurationAdmin
updateRedbackRuntimeConfiguration( redbackRuntimeConfiguration ); updateRedbackRuntimeConfiguration( redbackRuntimeConfiguration );
} }
// we must ensure userManagerImpls list is not empty if so put at least jdo one ! // we must ensure userManagerImpls list is not empty if so put at least jdo one !
if ( redbackRuntimeConfiguration.getUserManagerImpls().isEmpty() ) if ( redbackRuntimeConfiguration.getUserManagerImpls().isEmpty() )
{ {
@ -114,6 +119,39 @@ public class DefaultRedbackRuntimeConfigurationAdmin
updateRedbackRuntimeConfiguration( redbackRuntimeConfiguration ); updateRedbackRuntimeConfiguration( redbackRuntimeConfiguration );
} }
boolean save = false;
// NPE free
if ( redbackRuntimeConfiguration.getUsersCacheConfiguration() == null )
{
redbackRuntimeConfiguration.setUsersCacheConfiguration( new CacheConfiguration() );
}
// if -1 it means non initialized to take values from the spring bean
if ( redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToIdleSeconds() < 0 )
{
redbackRuntimeConfiguration.getUsersCacheConfiguration().setTimeToIdleSeconds(
usersCache.getTimeToIdleSeconds() );
save = true;
}
usersCache.setTimeToIdleSeconds(
redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToIdleSeconds() );
if ( redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToLiveSeconds() < 0 )
{
redbackRuntimeConfiguration.getUsersCacheConfiguration().setTimeToLiveSeconds(
usersCache.getTimeToLiveSeconds() );
save = true;
}
usersCache.setTimeToLiveSeconds(
redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToLiveSeconds() );
if ( save )
{
updateRedbackRuntimeConfiguration( redbackRuntimeConfiguration );
}
} }
catch ( RepositoryAdminException e ) catch ( RepositoryAdminException e )
{ {
@ -129,8 +167,8 @@ public class DefaultRedbackRuntimeConfigurationAdmin
public void updateRedbackRuntimeConfiguration( RedbackRuntimeConfiguration redbackRuntimeConfiguration ) public void updateRedbackRuntimeConfiguration( RedbackRuntimeConfiguration redbackRuntimeConfiguration )
throws RepositoryAdminException throws RepositoryAdminException
{ {
org.apache.archiva.configuration.RedbackRuntimeConfiguration org.apache.archiva.configuration.RedbackRuntimeConfiguration runtimeConfiguration =
runtimeConfiguration = build( redbackRuntimeConfiguration ); build( redbackRuntimeConfiguration );
Configuration configuration = archivaConfiguration.getConfiguration(); Configuration configuration = archivaConfiguration.getConfiguration();
configuration.setRedbackRuntimeConfiguration( runtimeConfiguration ); configuration.setRedbackRuntimeConfiguration( runtimeConfiguration );
try try
@ -147,7 +185,8 @@ public class DefaultRedbackRuntimeConfigurationAdmin
} }
} }
private RedbackRuntimeConfiguration build( org.apache.archiva.configuration.RedbackRuntimeConfiguration runtimeConfiguration ) private RedbackRuntimeConfiguration build(
org.apache.archiva.configuration.RedbackRuntimeConfiguration runtimeConfiguration )
{ {
RedbackRuntimeConfiguration redbackRuntimeConfiguration = RedbackRuntimeConfiguration redbackRuntimeConfiguration =
new BeanReplicator().replicateBean( runtimeConfiguration, RedbackRuntimeConfiguration.class ); new BeanReplicator().replicateBean( runtimeConfiguration, RedbackRuntimeConfiguration.class );
@ -159,24 +198,42 @@ public class DefaultRedbackRuntimeConfigurationAdmin
LdapConfiguration.class ) ); LdapConfiguration.class ) );
} }
if ( runtimeConfiguration.getUsersCacheConfiguration() != null )
{
redbackRuntimeConfiguration.setUsersCacheConfiguration(
new BeanReplicator().replicateBean( runtimeConfiguration.getUsersCacheConfiguration(),
CacheConfiguration.class ) );
}
if ( redbackRuntimeConfiguration.getLdapConfiguration() == null ) if ( redbackRuntimeConfiguration.getLdapConfiguration() == null )
{ {
// prevent NPE // prevent NPE
redbackRuntimeConfiguration.setLdapConfiguration( new LdapConfiguration() ); redbackRuntimeConfiguration.setLdapConfiguration( new LdapConfiguration() );
} }
if ( redbackRuntimeConfiguration.getUsersCacheConfiguration() == null )
{
redbackRuntimeConfiguration.setUsersCacheConfiguration( new CacheConfiguration() );
}
return redbackRuntimeConfiguration; return redbackRuntimeConfiguration;
} }
private org.apache.archiva.configuration.RedbackRuntimeConfiguration build( RedbackRuntimeConfiguration archivaRuntimeConfiguration ) private org.apache.archiva.configuration.RedbackRuntimeConfiguration build(
RedbackRuntimeConfiguration archivaRuntimeConfiguration )
{ {
org.apache.archiva.configuration.RedbackRuntimeConfiguration redbackRuntimeConfiguration = org.apache.archiva.configuration.RedbackRuntimeConfiguration redbackRuntimeConfiguration =
new BeanReplicator().replicateBean( archivaRuntimeConfiguration, org.apache.archiva.configuration.RedbackRuntimeConfiguration.class ); new BeanReplicator().replicateBean( archivaRuntimeConfiguration,
org.apache.archiva.configuration.RedbackRuntimeConfiguration.class );
redbackRuntimeConfiguration.setLdapConfiguration( redbackRuntimeConfiguration.setLdapConfiguration(
new BeanReplicator().replicateBean( archivaRuntimeConfiguration.getLdapConfiguration(), new BeanReplicator().replicateBean( archivaRuntimeConfiguration.getLdapConfiguration(),
org.apache.archiva.configuration.LdapConfiguration.class ) ); org.apache.archiva.configuration.LdapConfiguration.class ) );
redbackRuntimeConfiguration.setUsersCacheConfiguration(
new BeanReplicator().replicateBean( archivaRuntimeConfiguration.getUsersCacheConfiguration(),
org.apache.archiva.configuration.CacheConfiguration.class ) );
return redbackRuntimeConfiguration; return redbackRuntimeConfiguration;
} }

View File

@ -78,38 +78,6 @@ public class DefaultRedbackRuntimeConfigurationService
@Named( value = "cache#users" ) @Named( value = "cache#users" )
private Cache usersCache; private Cache usersCache;
@PostConstruct
public void initialize()
throws RepositoryAdminException
{
RedbackRuntimeConfiguration redbackRuntimeConfiguration =
redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration();
// NPE free
if ( redbackRuntimeConfiguration.getUsersCacheConfiguration() == null )
{
redbackRuntimeConfiguration.setUsersCacheConfiguration( new CacheConfiguration() );
}
// if -1 it means non initialized to take values from the spring bean
if ( redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToIdleSeconds() < 0 )
{
redbackRuntimeConfiguration.getUsersCacheConfiguration().setTimeToIdleSeconds(
usersCache.getTimeToIdleSeconds() );
}
usersCache.setTimeToIdleSeconds(
redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToIdleSeconds() );
if ( redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToLiveSeconds() < 0 )
{
redbackRuntimeConfiguration.getUsersCacheConfiguration().setTimeToLiveSeconds(
usersCache.getTimeToLiveSeconds() );
}
usersCache.setTimeToLiveSeconds(
redbackRuntimeConfiguration.getUsersCacheConfiguration().getTimeToLiveSeconds() );
}
public RedbackRuntimeConfiguration getRedbackRuntimeConfiguration() public RedbackRuntimeConfiguration getRedbackRuntimeConfiguration()
throws ArchivaRestServiceException throws ArchivaRestServiceException