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.InvalidRepositoryContentConsumer;
34 import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
35 import org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers;
36 import org.codehaus.plexus.registry.RegistryException;
38 public class AdministrationServiceImpl
39 implements AdministrationService
44 private ArchivaConfiguration archivaConfiguration;
46 private RepositoryContentConsumers consumerUtil;
48 public boolean configureDatabaseConsumer( String consumerId, boolean enable ) throws Exception
50 //Configuration config = archivaConfiguration.getConfiguration();
52 // TODO Auto-generated method stub
57 * @see AdministrationService#configureRepositoryConsumer(String, String, boolean)
59 public boolean configureRepositoryConsumer( String repoId, String consumerId, boolean enable )
62 List<KnownRepositoryContentConsumer> knownConsumers = consumerUtil.getAvailableKnownConsumers();
63 List<InvalidRepositoryContentConsumer> invalidConsumers = consumerUtil.getAvailableInvalidConsumers();
65 boolean found = false;
66 boolean isKnownContentConsumer = false;
67 for( KnownRepositoryContentConsumer consumer : knownConsumers )
69 if( consumer.getId().equals( consumerId ) )
72 isKnownContentConsumer = true;
79 for( InvalidRepositoryContentConsumer consumer : invalidConsumers )
81 if( consumer.getId().equals( consumerId ) )
91 throw new Exception( "Invalid repository consumer." );
94 Configuration config = archivaConfiguration.getConfiguration();
95 RepositoryScanningConfiguration repoScanningConfig = config.getRepositoryScanning();
97 if( isKnownContentConsumer )
99 repoScanningConfig.addKnownContentConsumer( consumerId );
103 repoScanningConfig.addInvalidContentConsumer( consumerId );
106 config.setRepositoryScanning( repoScanningConfig );
107 saveConfiguration( config );
112 public boolean deleteArtifact( String repoId, String groupId, String artifactId, String version ) throws Exception
114 // TODO implement delete artifact in Archiva
116 // TODO Auto-generated method stub
120 public boolean executeDatabaseScanner() throws Exception
122 // TODO Auto-generated method stub
126 public boolean executeRepositoryScanner( String repoId ) throws Exception
128 // TODO Auto-generated method stub
133 * @see AdministrationService#getAllDatabaseConsumers()
135 public List<String> getAllDatabaseConsumers()
137 List<String> consumers = new ArrayList<String>();
143 * @see AdministrationService#getAllRepositoryConsumers()
145 public List<String> getAllRepositoryConsumers()
147 List<String> consumers = new ArrayList<String>();
149 List<KnownRepositoryContentConsumer> knownConsumers = consumerUtil.getAvailableKnownConsumers();
150 List<InvalidRepositoryContentConsumer> invalidConsumers = consumerUtil.getAvailableInvalidConsumers();
152 for( KnownRepositoryContentConsumer consumer : knownConsumers )
154 consumers.add( consumer.getId() );
157 for( InvalidRepositoryContentConsumer consumer : invalidConsumers )
159 consumers.add( consumer.getId() );
165 public List<ManagedRepository> getAllManagedRepositories()
170 public List<RemoteRepository> getAllRemoteRepositories()
175 private void saveConfiguration( Configuration config )
180 archivaConfiguration.save( config );
182 catch( RegistryException e )
184 throw new Exception( "Error occurred in the registry." );
186 catch ( IndeterminateConfigurationException e )
188 throw new Exception( "Error occurred while saving the configuration." );
192 public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
194 this.archivaConfiguration = archivaConfiguration;
197 public RepositoryContentConsumers getConsumerUtil()
202 public void setConsumerUtil( RepositoryContentConsumers consumerUtil )
204 this.consumerUtil = consumerUtil;