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.RepositoryScanningConfiguration;
33 import org.apache.maven.archiva.consumers.DatabaseCleanupConsumer;
34 import org.apache.maven.archiva.consumers.DatabaseUnprocessedArtifactConsumer;
35 import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
36 import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
37 import org.apache.maven.archiva.database.updater.DatabaseConsumers;
38 import org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers;
39 import org.codehaus.plexus.registry.RegistryException;
42 * AdministrationServiceImpl
44 * @version $Id: AdministrationServiceImpl.java
46 public class AdministrationServiceImpl
47 implements AdministrationService
52 private ArchivaConfiguration archivaConfiguration;
54 private RepositoryContentConsumers repoConsumersUtil;
56 private DatabaseConsumers dbConsumersUtil;
59 * @see AdministrationService#configureDatabaseConsumer(String, boolean)
61 public boolean configureDatabaseConsumer( String consumerId, boolean enable ) throws Exception
63 List<DatabaseCleanupConsumer> cleanupConsumers = dbConsumersUtil.getAvailableCleanupConsumers();
64 List<DatabaseUnprocessedArtifactConsumer> unprocessedConsumers =
65 dbConsumersUtil.getAvailableUnprocessedConsumers();
67 boolean found = false;
68 boolean isCleanupConsumer = false;
69 for( DatabaseCleanupConsumer consumer : cleanupConsumers )
71 if( consumer.getId().equals( consumerId ) )
74 isCleanupConsumer = true;
81 for( DatabaseUnprocessedArtifactConsumer consumer : unprocessedConsumers )
83 if( consumer.getId().equals( consumerId ) )
93 throw new Exception( "Invalid database consumer." );
96 Configuration config = archivaConfiguration.getConfiguration();
97 DatabaseScanningConfiguration dbScanningConfig = config.getDatabaseScanning();
99 if( isCleanupConsumer )
101 dbScanningConfig.addCleanupConsumer( consumerId );
105 dbScanningConfig.addUnprocessedConsumer( consumerId );
108 config.setDatabaseScanning( dbScanningConfig );
109 saveConfiguration( config );
115 * @see AdministrationService#configureRepositoryConsumer(String, String, boolean)
117 public boolean configureRepositoryConsumer( String repoId, String consumerId, boolean enable )
120 // TODO use repoId once consumers are configured per repository! (MRM-930)
122 List<KnownRepositoryContentConsumer> knownConsumers = repoConsumersUtil.getAvailableKnownConsumers();
123 List<InvalidRepositoryContentConsumer> invalidConsumers = repoConsumersUtil.getAvailableInvalidConsumers();
125 boolean found = false;
126 boolean isKnownContentConsumer = false;
127 for( KnownRepositoryContentConsumer consumer : knownConsumers )
129 if( consumer.getId().equals( consumerId ) )
132 isKnownContentConsumer = true;
139 for( InvalidRepositoryContentConsumer consumer : invalidConsumers )
141 if( consumer.getId().equals( consumerId ) )
151 throw new Exception( "Invalid repository consumer." );
154 Configuration config = archivaConfiguration.getConfiguration();
155 RepositoryScanningConfiguration repoScanningConfig = config.getRepositoryScanning();
157 if( isKnownContentConsumer )
159 repoScanningConfig.addKnownContentConsumer( consumerId );
163 repoScanningConfig.addInvalidContentConsumer( consumerId );
166 config.setRepositoryScanning( repoScanningConfig );
167 saveConfiguration( config );
173 * @see AdministrationService#deleteArtifact(String, String, String, String)
175 public boolean deleteArtifact( String repoId, String groupId, String artifactId, String version ) throws Exception
177 // TODO implement delete artifact in Archiva
179 // TODO Auto-generated method stub
184 * @see AdministrationService#executeDatabaseScanner()
186 public boolean executeDatabaseScanner() throws Exception
188 // TODO Auto-generated method stub
193 * @see AdministrationService#executeRepositoryScanner(String)
195 public boolean executeRepositoryScanner( String repoId ) throws Exception
197 // TODO Auto-generated method stub
202 * @see AdministrationService#getAllDatabaseConsumers()
204 public List<String> getAllDatabaseConsumers()
206 List<String> consumers = new ArrayList<String>();
208 List<DatabaseCleanupConsumer> cleanupConsumers = dbConsumersUtil.getAvailableCleanupConsumers();
209 List<DatabaseUnprocessedArtifactConsumer> unprocessedConsumers = dbConsumersUtil.getAvailableUnprocessedConsumers();
211 for( DatabaseCleanupConsumer consumer : cleanupConsumers )
213 consumers.add( consumer.getId() );
216 for( DatabaseUnprocessedArtifactConsumer consumer : unprocessedConsumers )
218 consumers.add( consumer.getId() );
225 * @see AdministrationService#getAllRepositoryConsumers()
227 public List<String> getAllRepositoryConsumers()
229 List<String> consumers = new ArrayList<String>();
231 List<KnownRepositoryContentConsumer> knownConsumers = repoConsumersUtil.getAvailableKnownConsumers();
232 List<InvalidRepositoryContentConsumer> invalidConsumers = repoConsumersUtil.getAvailableInvalidConsumers();
234 for( KnownRepositoryContentConsumer consumer : knownConsumers )
236 consumers.add( consumer.getId() );
239 for( InvalidRepositoryContentConsumer consumer : invalidConsumers )
241 consumers.add( consumer.getId() );
248 * @see AdministrationService#getAllManagedRepositories()
250 public List<ManagedRepository> getAllManagedRepositories()
256 * @see AdministrationService#getAllRemoteRepositories()
258 public List<RemoteRepository> getAllRemoteRepositories()
263 private void saveConfiguration( Configuration config )
268 archivaConfiguration.save( config );
270 catch( RegistryException e )
272 throw new Exception( "Error occurred in the registry." );
274 catch ( IndeterminateConfigurationException e )
276 throw new Exception( "Error occurred while saving the configuration." );
280 public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
282 this.archivaConfiguration = archivaConfiguration;
285 public void setRepoConsumersUtil( RepositoryContentConsumers consumerUtil )
287 this.repoConsumersUtil = consumerUtil;
290 public void setDbConsumersUtil( DatabaseConsumers consumerUtil )
292 this.dbConsumersUtil = consumerUtil;