001 package org.apache.archiva.rest.services; 002 /* 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, 014 * software distributed under the License is distributed on an 015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 016 * KIND, either express or implied. See the License for the 017 * specific language governing permissions and limitations 018 * under the License. 019 */ 020 021 import org.apache.archiva.admin.model.RepositoryAdminException; 022 import org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration; 023 import org.apache.archiva.admin.model.beans.CacheConfiguration; 024 import org.apache.archiva.admin.model.runtime.ArchivaRuntimeConfigurationAdmin; 025 import org.apache.archiva.redback.components.cache.Cache; 026 import org.apache.archiva.rest.api.services.ArchivaRestServiceException; 027 import org.apache.archiva.rest.api.services.ArchivaRuntimeConfigurationService; 028 import org.springframework.stereotype.Service; 029 030 import javax.inject.Inject; 031 import javax.inject.Named; 032 033 /** 034 * @author Olivier Lamy 035 * @since 1.4-M4 036 */ 037 @Service( "archivaRuntimeConfigurationService#rest" ) 038 public class DefaultArchivaRuntimeConfigurationService 039 extends AbstractRestService 040 implements ArchivaRuntimeConfigurationService 041 { 042 @Inject 043 private ArchivaRuntimeConfigurationAdmin archivaRuntimeConfigurationAdmin; 044 045 @Inject 046 @Named( value = "cache#url-failures-cache" ) 047 private Cache usersCache; 048 049 public ArchivaRuntimeConfiguration getArchivaRuntimeConfiguration() 050 throws ArchivaRestServiceException 051 { 052 try 053 { 054 return archivaRuntimeConfigurationAdmin.getArchivaRuntimeConfiguration(); 055 } 056 catch ( RepositoryAdminException e ) 057 { 058 throw new ArchivaRestServiceException( e.getMessage(), e ); 059 } 060 } 061 062 public Boolean updateArchivaRuntimeConfiguration( ArchivaRuntimeConfiguration archivaRuntimeConfiguration ) 063 throws ArchivaRestServiceException 064 { 065 try 066 { 067 archivaRuntimeConfigurationAdmin.updateArchivaRuntimeConfiguration( archivaRuntimeConfiguration ); 068 CacheConfiguration cacheConfiguration = archivaRuntimeConfiguration.getUrlFailureCacheConfiguration(); 069 if ( cacheConfiguration != null ) 070 { 071 usersCache.setTimeToLiveSeconds( cacheConfiguration.getTimeToLiveSeconds() ); 072 usersCache.setTimeToIdleSeconds( cacheConfiguration.getTimeToIdleSeconds() ); 073 usersCache.setMaxElementsOnDisk( cacheConfiguration.getMaxElementsOnDisk() ); 074 usersCache.setMaxElementsInMemory( cacheConfiguration.getMaxElementsInMemory() ); 075 } 076 } 077 catch ( RepositoryAdminException e ) 078 { 079 throw new ArchivaRestServiceException( e.getMessage(), e ); 080 } 081 return Boolean.TRUE; 082 } 083 }