1 package org.apache.archiva.admin.repository.runtime;
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import net.sf.beanlib.provider.replicator.BeanReplicator;
22 import org.apache.archiva.admin.model.RepositoryAdminException;
23 import org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration;
24 import org.apache.archiva.admin.model.beans.CacheConfiguration;
25 import org.apache.archiva.admin.model.runtime.ArchivaRuntimeConfigurationAdmin;
26 import org.apache.archiva.configuration.ArchivaConfiguration;
27 import org.apache.archiva.configuration.Configuration;
28 import org.apache.archiva.configuration.IndeterminateConfigurationException;
29 import org.apache.archiva.redback.components.cache.Cache;
30 import org.apache.archiva.redback.components.registry.RegistryException;
31 import org.springframework.stereotype.Service;
33 import javax.annotation.PostConstruct;
34 import javax.inject.Inject;
35 import javax.inject.Named;
38 * @author Olivier Lamy
41 @Service("archivaRuntimeConfigurationAdmin#default")
42 public class DefaultArchivaRuntimeConfigurationAdmin
43 implements ArchivaRuntimeConfigurationAdmin
47 private ArchivaConfiguration archivaConfiguration;
50 @Named( value = "cache#url-failures-cache" )
51 private Cache urlFailureCache;
54 public void initialize()
55 throws RepositoryAdminException
57 ArchivaRuntimeConfiguration archivaRuntimeConfiguration = getArchivaRuntimeConfiguration();
62 if ( archivaRuntimeConfiguration.getUrlFailureCacheConfiguration() == null )
64 archivaRuntimeConfiguration.setUrlFailureCacheConfiguration( new CacheConfiguration() );
67 // if -1 it means non initialized to take values from the spring bean
68 if ( archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getTimeToIdleSeconds() < 0 )
70 archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().setTimeToIdleSeconds(
71 urlFailureCache.getTimeToIdleSeconds() );
75 urlFailureCache.setTimeToIdleSeconds(
76 archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getTimeToIdleSeconds() );
78 if ( archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getTimeToLiveSeconds() < 0 )
80 archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().setTimeToLiveSeconds(
81 urlFailureCache.getTimeToLiveSeconds() );
85 urlFailureCache.setTimeToLiveSeconds(
86 archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getTimeToLiveSeconds() );
88 if ( archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getMaxElementsInMemory() < 0 )
90 archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().setMaxElementsInMemory(
91 urlFailureCache.getMaxElementsInMemory() );
94 urlFailureCache.setMaxElementsInMemory(
95 archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getMaxElementsInMemory() );
97 if ( archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getMaxElementsOnDisk() < 0 )
99 archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().setMaxElementsOnDisk(
100 urlFailureCache.getMaxElementsOnDisk() );
103 urlFailureCache.setMaxElementsOnDisk(
104 archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getMaxElementsOnDisk() );
108 updateArchivaRuntimeConfiguration( archivaRuntimeConfiguration );
113 public ArchivaRuntimeConfiguration getArchivaRuntimeConfiguration()
114 throws RepositoryAdminException
116 return build( archivaConfiguration.getConfiguration().getArchivaRuntimeConfiguration() );
119 public void updateArchivaRuntimeConfiguration( ArchivaRuntimeConfiguration archivaRuntimeConfiguration )
120 throws RepositoryAdminException
122 Configuration configuration = archivaConfiguration.getConfiguration();
123 configuration.setArchivaRuntimeConfiguration( build( archivaRuntimeConfiguration ) );
126 archivaConfiguration.save( configuration );
128 catch ( RegistryException e )
130 throw new RepositoryAdminException( e.getMessage(), e );
132 catch ( IndeterminateConfigurationException e )
134 throw new RepositoryAdminException( e.getMessage(), e );
138 protected ArchivaRuntimeConfiguration build(
139 org.apache.archiva.configuration.ArchivaRuntimeConfiguration archivaRuntimeConfiguration )
141 if ( archivaRuntimeConfiguration == null )
143 return new ArchivaRuntimeConfiguration();
146 ArchivaRuntimeConfiguration res =
147 new BeanReplicator().replicateBean( archivaRuntimeConfiguration, ArchivaRuntimeConfiguration.class );
149 if ( archivaRuntimeConfiguration.getUrlFailureCacheConfiguration() != null )
152 res.setUrlFailureCacheConfiguration(
153 new BeanReplicator().replicateBean( archivaRuntimeConfiguration.getUrlFailureCacheConfiguration(),
154 CacheConfiguration.class ) );
161 protected org.apache.archiva.configuration.ArchivaRuntimeConfiguration build(
162 ArchivaRuntimeConfiguration archivaRuntimeConfiguration )
164 if ( archivaRuntimeConfiguration == null )
166 return new org.apache.archiva.configuration.ArchivaRuntimeConfiguration();
169 org.apache.archiva.configuration.ArchivaRuntimeConfiguration res =
170 new BeanReplicator().replicateBean( archivaRuntimeConfiguration,
171 org.apache.archiva.configuration.ArchivaRuntimeConfiguration.class );
173 if ( archivaRuntimeConfiguration.getUrlFailureCacheConfiguration() != null )
176 res.setUrlFailureCacheConfiguration(
177 new BeanReplicator().replicateBean( archivaRuntimeConfiguration.getUrlFailureCacheConfiguration(),
178 org.apache.archiva.configuration.CacheConfiguration.class ) );