1 package org.apache.archiva.web.xmlrpc.services;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import java.util.ArrayList;
23 import java.util.List;
25 import org.apache.archiva.web.xmlrpc.api.AdministrationService;
26 import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository;
27 import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository;
28 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
29 import org.apache.maven.archiva.configuration.Configuration;
30 import org.apache.maven.archiva.configuration.DatabaseScanningConfiguration;
31 import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
32 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
33 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
34 import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
35 import org.apache.maven.archiva.consumers.DatabaseCleanupConsumer;
36 import org.apache.maven.archiva.consumers.DatabaseUnprocessedArtifactConsumer;
37 import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
38 import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
39 import org.apache.maven.archiva.database.updater.DatabaseConsumers;
40 import org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers;
41 import org.apache.maven.archiva.scheduled.ArchivaTaskScheduler;
42 import org.apache.maven.archiva.scheduled.DefaultArchivaTaskScheduler;
43 import org.apache.maven.archiva.scheduled.tasks.ArchivaTask;
44 import org.apache.maven.archiva.scheduled.tasks.DatabaseTask;
45 import org.apache.maven.archiva.scheduled.tasks.RepositoryTask;
46 import org.codehaus.plexus.registry.RegistryException;
49 * AdministrationServiceImpl
51 * @version $Id: AdministrationServiceImpl.java
53 public class AdministrationServiceImpl
54 implements AdministrationService
59 private ArchivaConfiguration archivaConfiguration;
64 private RepositoryContentConsumers repoConsumersUtil;
69 private DatabaseConsumers dbConsumersUtil;
74 private ArchivaTaskScheduler taskScheduler;
77 * @see AdministrationService#configureDatabaseConsumer(String, boolean)
79 public boolean configureDatabaseConsumer( String consumerId, boolean enable ) throws Exception
81 List<DatabaseCleanupConsumer> cleanupConsumers = dbConsumersUtil.getAvailableCleanupConsumers();
82 List<DatabaseUnprocessedArtifactConsumer> unprocessedConsumers =
83 dbConsumersUtil.getAvailableUnprocessedConsumers();
85 boolean found = false;
86 boolean isCleanupConsumer = false;
87 for( DatabaseCleanupConsumer consumer : cleanupConsumers )
89 if( consumer.getId().equals( consumerId ) )
92 isCleanupConsumer = true;
99 for( DatabaseUnprocessedArtifactConsumer consumer : unprocessedConsumers )
101 if( consumer.getId().equals( consumerId ) )
111 throw new Exception( "Invalid database consumer." );
114 Configuration config = archivaConfiguration.getConfiguration();
115 DatabaseScanningConfiguration dbScanningConfig = config.getDatabaseScanning();
117 if( isCleanupConsumer )
119 dbScanningConfig.addCleanupConsumer( consumerId );
123 dbScanningConfig.addUnprocessedConsumer( consumerId );
126 config.setDatabaseScanning( dbScanningConfig );
127 saveConfiguration( config );
133 * @see AdministrationService#configureRepositoryConsumer(String, String, boolean)
135 public boolean configureRepositoryConsumer( String repoId, String consumerId, boolean enable )
138 // TODO use repoId once consumers are configured per repository! (MRM-930)
140 List<KnownRepositoryContentConsumer> knownConsumers = repoConsumersUtil.getAvailableKnownConsumers();
141 List<InvalidRepositoryContentConsumer> invalidConsumers = repoConsumersUtil.getAvailableInvalidConsumers();
143 boolean found = false;
144 boolean isKnownContentConsumer = false;
145 for( KnownRepositoryContentConsumer consumer : knownConsumers )
147 if( consumer.getId().equals( consumerId ) )
150 isKnownContentConsumer = true;
157 for( InvalidRepositoryContentConsumer consumer : invalidConsumers )
159 if( consumer.getId().equals( consumerId ) )
169 throw new Exception( "Invalid repository consumer." );
172 Configuration config = archivaConfiguration.getConfiguration();
173 RepositoryScanningConfiguration repoScanningConfig = config.getRepositoryScanning();
175 if( isKnownContentConsumer )
177 repoScanningConfig.addKnownContentConsumer( consumerId );
181 repoScanningConfig.addInvalidContentConsumer( consumerId );
184 config.setRepositoryScanning( repoScanningConfig );
185 saveConfiguration( config );
191 * @see AdministrationService#deleteArtifact(String, String, String, String)
193 public boolean deleteArtifact( String repoId, String groupId, String artifactId, String version ) throws Exception
195 // TODO implement delete artifact in Archiva
197 // TODO Auto-generated method stub
202 * @see AdministrationService#executeDatabaseScanner()
204 public boolean executeDatabaseScanner() throws Exception
206 if ( taskScheduler.isProcessingDatabaseTask() )
211 DatabaseTask task = new DatabaseTask();
212 task.setName( DefaultArchivaTaskScheduler.DATABASE_JOB + ":user-requested-via-web-service" );
213 task.setQueuePolicy( ArchivaTask.QUEUE_POLICY_WAIT );
215 taskScheduler.queueDatabaseTask( task );
221 * @see AdministrationService#executeRepositoryScanner(String)
223 public boolean executeRepositoryScanner( String repoId ) throws Exception
225 Configuration config = archivaConfiguration.getConfiguration();
226 if( config.findManagedRepositoryById( repoId ) == null )
228 throw new Exception( "Repository does not exist." );
231 if ( taskScheduler.isProcessingAnyRepositoryTask() )
233 if ( taskScheduler.isProcessingRepositoryTask( repoId ) )
239 RepositoryTask task = new RepositoryTask();
240 task.setRepositoryId( repoId );
241 task.setName( DefaultArchivaTaskScheduler.REPOSITORY_JOB + ":" + repoId );
242 task.setQueuePolicy( ArchivaTask.QUEUE_POLICY_WAIT );
244 taskScheduler.queueRepositoryTask( task );
250 * @see AdministrationService#getAllDatabaseConsumers()
252 public List<String> getAllDatabaseConsumers()
254 List<String> consumers = new ArrayList<String>();
256 List<DatabaseCleanupConsumer> cleanupConsumers = dbConsumersUtil.getAvailableCleanupConsumers();
257 List<DatabaseUnprocessedArtifactConsumer> unprocessedConsumers = dbConsumersUtil.getAvailableUnprocessedConsumers();
259 for( DatabaseCleanupConsumer consumer : cleanupConsumers )
261 consumers.add( consumer.getId() );
264 for( DatabaseUnprocessedArtifactConsumer consumer : unprocessedConsumers )
266 consumers.add( consumer.getId() );
273 * @see AdministrationService#getAllRepositoryConsumers()
275 public List<String> getAllRepositoryConsumers()
277 List<String> consumers = new ArrayList<String>();
279 List<KnownRepositoryContentConsumer> knownConsumers = repoConsumersUtil.getAvailableKnownConsumers();
280 List<InvalidRepositoryContentConsumer> invalidConsumers = repoConsumersUtil.getAvailableInvalidConsumers();
282 for( KnownRepositoryContentConsumer consumer : knownConsumers )
284 consumers.add( consumer.getId() );
287 for( InvalidRepositoryContentConsumer consumer : invalidConsumers )
289 consumers.add( consumer.getId() );
296 * @see AdministrationService#getAllManagedRepositories()
298 public List<ManagedRepository> getAllManagedRepositories()
300 List<ManagedRepository> managedRepos = new ArrayList<ManagedRepository>();
302 Configuration config = archivaConfiguration.getConfiguration();
303 List<ManagedRepositoryConfiguration> managedRepoConfigs = config.getManagedRepositories();
305 for( ManagedRepositoryConfiguration repoConfig : managedRepoConfigs )
307 // TODO fix resolution of repo url!
308 ManagedRepository repo =
309 new ManagedRepository( repoConfig.getId(), repoConfig.getName(), "URL", repoConfig.getLayout(),
310 repoConfig.isSnapshots(), repoConfig.isReleases() );
311 managedRepos.add( repo );
318 * @see AdministrationService#getAllRemoteRepositories()
320 public List<RemoteRepository> getAllRemoteRepositories()
322 List<RemoteRepository> remoteRepos = new ArrayList<RemoteRepository>();
324 Configuration config = archivaConfiguration.getConfiguration();
325 List<RemoteRepositoryConfiguration> remoteRepoConfigs = config.getRemoteRepositories();
327 for( RemoteRepositoryConfiguration repoConfig : remoteRepoConfigs )
329 RemoteRepository repo =
330 new RemoteRepository( repoConfig.getId(), repoConfig.getName(), repoConfig.getUrl(),
331 repoConfig.getLayout() );
332 remoteRepos.add( repo );
338 private void saveConfiguration( Configuration config )
343 archivaConfiguration.save( config );
345 catch( RegistryException e )
347 throw new Exception( "Error occurred in the registry." );
349 catch ( IndeterminateConfigurationException e )
351 throw new Exception( "Error occurred while saving the configuration." );
355 public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
357 this.archivaConfiguration = archivaConfiguration;
360 public void setRepoConsumersUtil( RepositoryContentConsumers consumerUtil )
362 this.repoConsumersUtil = consumerUtil;
365 public void setDbConsumersUtil( DatabaseConsumers consumerUtil )
367 this.dbConsumersUtil = consumerUtil;
370 public void setTaskScheduler( ArchivaTaskScheduler taskScheduler )
372 this.taskScheduler = taskScheduler;