]> source.dussan.org Git - archiva.git/blob
2ccf33d21902c04dced026a4368664f792014e92
[archiva.git] /
1 package org.apache.archiva.web.xmlrpc.services;
2
3 /*
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
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  * under the License.
20  */
21
22 import java.util.ArrayList;
23 import java.util.List;
24
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;
40
41 /**
42  * AdministrationServiceImpl
43  * 
44  * @version $Id: AdministrationServiceImpl.java
45  */
46 public class AdministrationServiceImpl
47     implements AdministrationService
48 {
49     /**
50      * @plexus.requirement
51      */
52     private ArchivaConfiguration archivaConfiguration;
53     
54     private RepositoryContentConsumers repoConsumersUtil;
55     
56     private DatabaseConsumers dbConsumersUtil;
57     
58     /**
59      * @see AdministrationService#configureDatabaseConsumer(String, boolean)
60      */
61     public boolean configureDatabaseConsumer( String consumerId, boolean enable ) throws Exception
62     {
63         List<DatabaseCleanupConsumer> cleanupConsumers = dbConsumersUtil.getAvailableCleanupConsumers();
64         List<DatabaseUnprocessedArtifactConsumer> unprocessedConsumers =
65             dbConsumersUtil.getAvailableUnprocessedConsumers();
66         
67         boolean found = false;
68         boolean isCleanupConsumer = false;        
69         for( DatabaseCleanupConsumer consumer : cleanupConsumers )
70         {
71             if( consumer.getId().equals( consumerId ) )
72             {
73                 found = true;
74                 isCleanupConsumer = true;
75                 break;
76             }
77         }
78         
79         if( !found )
80         {
81             for( DatabaseUnprocessedArtifactConsumer consumer : unprocessedConsumers )
82             {
83                 if( consumer.getId().equals( consumerId ) )
84                 {
85                     found = true;
86                     break;
87                 }
88             }
89         }
90         
91         if( !found )
92         {
93             throw new Exception( "Invalid database consumer." );
94         }
95         
96         Configuration config = archivaConfiguration.getConfiguration();
97         DatabaseScanningConfiguration dbScanningConfig = config.getDatabaseScanning();
98         
99         if( isCleanupConsumer )
100         {
101             dbScanningConfig.addCleanupConsumer( consumerId );            
102         }
103         else
104         {
105             dbScanningConfig.addUnprocessedConsumer( consumerId );
106         }
107         
108         config.setDatabaseScanning( dbScanningConfig );        
109         saveConfiguration( config );
110         
111         return true;
112     }
113
114     /**
115      * @see AdministrationService#configureRepositoryConsumer(String, String, boolean)
116      */
117     public boolean configureRepositoryConsumer( String repoId, String consumerId, boolean enable )
118         throws Exception
119     {
120         // TODO use repoId once consumers are configured per repository! (MRM-930)
121         
122         List<KnownRepositoryContentConsumer> knownConsumers = repoConsumersUtil.getAvailableKnownConsumers();
123         List<InvalidRepositoryContentConsumer> invalidConsumers = repoConsumersUtil.getAvailableInvalidConsumers();
124         
125         boolean found = false;
126         boolean isKnownContentConsumer = false;
127         for( KnownRepositoryContentConsumer consumer : knownConsumers )
128         {
129             if( consumer.getId().equals( consumerId ) )
130             {
131                 found = true;
132                 isKnownContentConsumer = true;
133                 break;
134             }
135         }
136         
137         if( !found )
138         {
139             for( InvalidRepositoryContentConsumer consumer : invalidConsumers )
140             {
141                 if( consumer.getId().equals( consumerId ) )
142                 {
143                     found = true;
144                     break;
145                 }
146             }
147         }
148         
149         if( !found )
150         {
151             throw new Exception( "Invalid repository consumer." );
152         }
153         
154         Configuration config = archivaConfiguration.getConfiguration();
155         RepositoryScanningConfiguration repoScanningConfig = config.getRepositoryScanning();
156         
157         if( isKnownContentConsumer )
158         {
159             repoScanningConfig.addKnownContentConsumer( consumerId );
160         }
161         else
162         {
163             repoScanningConfig.addInvalidContentConsumer( consumerId );
164         }
165         
166         config.setRepositoryScanning( repoScanningConfig );        
167         saveConfiguration( config );
168         
169         return true;
170     }
171     
172     /**
173      * @see AdministrationService#deleteArtifact(String, String, String, String)
174      */
175     public boolean deleteArtifact( String repoId, String groupId, String artifactId, String version ) throws Exception
176     {
177         // TODO implement delete artifact in Archiva
178         
179         // TODO Auto-generated method stub
180         return false;
181     }
182
183     /**
184      * @see AdministrationService#executeDatabaseScanner()
185      */
186     public boolean executeDatabaseScanner() throws Exception
187     {
188         // TODO Auto-generated method stub
189         return false;
190     }
191
192     /**
193      * @see AdministrationService#executeRepositoryScanner(String)
194      */
195     public boolean executeRepositoryScanner( String repoId ) throws Exception
196     {
197         // TODO Auto-generated method stub
198         return false;
199     }
200
201     /**
202      * @see AdministrationService#getAllDatabaseConsumers()
203      */
204     public List<String> getAllDatabaseConsumers()
205     {
206         List<String> consumers = new ArrayList<String>();
207         
208         List<DatabaseCleanupConsumer> cleanupConsumers = dbConsumersUtil.getAvailableCleanupConsumers();
209         List<DatabaseUnprocessedArtifactConsumer> unprocessedConsumers = dbConsumersUtil.getAvailableUnprocessedConsumers();
210         
211         for( DatabaseCleanupConsumer consumer : cleanupConsumers )
212         {
213             consumers.add( consumer.getId() );
214         }  
215         
216         for( DatabaseUnprocessedArtifactConsumer consumer : unprocessedConsumers )
217         {
218             consumers.add( consumer.getId() );
219         } 
220         
221         return consumers;
222     }
223
224     /**
225      * @see AdministrationService#getAllRepositoryConsumers()
226      */
227     public List<String> getAllRepositoryConsumers()
228     {
229         List<String> consumers = new ArrayList<String>();
230                 
231         List<KnownRepositoryContentConsumer> knownConsumers = repoConsumersUtil.getAvailableKnownConsumers();
232         List<InvalidRepositoryContentConsumer> invalidConsumers = repoConsumersUtil.getAvailableInvalidConsumers();
233         
234         for( KnownRepositoryContentConsumer consumer : knownConsumers )
235         {
236             consumers.add( consumer.getId() );
237         }
238         
239         for( InvalidRepositoryContentConsumer consumer : invalidConsumers )
240         {
241             consumers.add( consumer.getId() );
242         }
243
244         return consumers;
245     }
246
247     /**
248      * @see AdministrationService#getAllManagedRepositories()
249      */
250     public List<ManagedRepository> getAllManagedRepositories()
251     {
252         return null;
253     }
254
255     /**
256      * @see AdministrationService#getAllRemoteRepositories()
257      */
258     public List<RemoteRepository> getAllRemoteRepositories()
259     {
260         return null;
261     }
262
263     private void saveConfiguration( Configuration config )
264         throws Exception
265     {
266         try
267         {
268             archivaConfiguration.save( config );
269         }
270         catch(  RegistryException e )
271         {
272             throw new Exception( "Error occurred in the registry." );
273         }
274         catch ( IndeterminateConfigurationException e )
275         {
276             throw new Exception( "Error occurred while saving the configuration." );    
277         }
278     }
279     
280     public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
281     {
282         this.archivaConfiguration = archivaConfiguration;
283     }
284
285     public void setRepoConsumersUtil( RepositoryContentConsumers consumerUtil )
286     {
287         this.repoConsumersUtil = consumerUtil;
288     }    
289     
290     public void setDbConsumersUtil( DatabaseConsumers consumerUtil )
291     {
292         this.dbConsumersUtil = consumerUtil;
293     }   
294 }