This project has retired. For details please refer to its Attic page.
Source code
001package 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
021import org.apache.archiva.admin.model.RepositoryAdminException;
022import org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration;
023import org.apache.archiva.admin.model.beans.CacheConfiguration;
024import org.apache.archiva.admin.model.beans.FileLockConfiguration;
025import org.apache.archiva.admin.model.runtime.ArchivaRuntimeConfigurationAdmin;
026import org.apache.archiva.common.filelock.FileLockManager;
027import org.apache.archiva.components.cache.Cache;
028import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
029import org.apache.archiva.rest.api.services.ArchivaRuntimeConfigurationService;
030import org.springframework.stereotype.Service;
031
032import javax.inject.Inject;
033import javax.inject.Named;
034
035/**
036 * @author Olivier Lamy
037 * @since 1.4-M4
038 */
039@Service( "archivaRuntimeConfigurationService#rest" )
040public class DefaultArchivaRuntimeConfigurationService
041    extends AbstractRestService
042    implements ArchivaRuntimeConfigurationService
043{
044    @Inject
045    private ArchivaRuntimeConfigurationAdmin archivaRuntimeConfigurationAdmin;
046
047    @Inject
048    @Named( value = "cache#url-failures-cache" )
049    private Cache usersCache;
050
051    @Inject
052    @Named( value = "fileLockManager#default" )
053    private FileLockManager fileLockManager;
054
055    @Override
056    public ArchivaRuntimeConfiguration getArchivaRuntimeConfiguration()
057        throws ArchivaRestServiceException
058    {
059        try
060        {
061            return archivaRuntimeConfigurationAdmin.getArchivaRuntimeConfiguration();
062        }
063        catch ( RepositoryAdminException e )
064        {
065            throw new ArchivaRestServiceException( e.getMessage(), e );
066        }
067    }
068
069    @Override
070    public Boolean updateArchivaRuntimeConfiguration( ArchivaRuntimeConfiguration archivaRuntimeConfiguration )
071        throws ArchivaRestServiceException
072    {
073        try
074        {
075            archivaRuntimeConfigurationAdmin.updateArchivaRuntimeConfiguration( archivaRuntimeConfiguration );
076            CacheConfiguration cacheConfiguration = archivaRuntimeConfiguration.getUrlFailureCacheConfiguration();
077            if ( cacheConfiguration != null )
078            {
079                usersCache.setTimeToLiveSeconds( cacheConfiguration.getTimeToLiveSeconds() );
080                usersCache.setTimeToIdleSeconds( cacheConfiguration.getTimeToIdleSeconds() );
081                usersCache.setMaxElementsOnDisk( cacheConfiguration.getMaxElementsOnDisk() );
082                usersCache.setMaxElementsInMemory( cacheConfiguration.getMaxElementsInMemory() );
083            }
084
085            FileLockConfiguration fileLockConfiguration = archivaRuntimeConfiguration.getFileLockConfiguration();
086            if ( fileLockConfiguration != null )
087            {
088                fileLockManager.setTimeout( fileLockConfiguration.getLockingTimeout() );
089                fileLockManager.setSkipLocking( fileLockConfiguration.isSkipLocking() );
090            }
091
092
093        }
094        catch ( RepositoryAdminException e )
095        {
096            throw new ArchivaRestServiceException( e.getMessage(), e );
097        }
098        return Boolean.TRUE;
099    }
100}