]> source.dussan.org Git - archiva.git/blob
880e2d918db64fa904ec487124ae93eb6022fc59
[archiva.git] /
1 package org.apache.archiva.rest.services;
2 /*
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  */
20
21 import net.sf.beanlib.provider.replicator.BeanReplicator;
22 import org.apache.archiva.admin.repository.RepositoryAdminException;
23 import org.apache.archiva.admin.repository.admin.ArchivaAdministration;
24 import org.apache.archiva.rest.api.model.FileType;
25 import org.apache.archiva.rest.api.model.LegacyArtifactPath;
26 import org.apache.archiva.rest.api.model.RepositoryScanning;
27 import org.apache.archiva.rest.api.services.ArchivaAdministrationService;
28 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
29 import org.springframework.stereotype.Service;
30
31 import javax.inject.Inject;
32 import java.util.ArrayList;
33 import java.util.List;
34
35 /**
36  * @author Olivier Lamy
37  * @since 1.4
38  */
39 @Service( "archivaAdministrationService#default" )
40 public class DefaultArchivaAdministrationService
41     extends AbstractRestService
42     implements ArchivaAdministrationService
43 {
44     @Inject
45     private ArchivaAdministration archivaAdministration;
46
47     public List<LegacyArtifactPath> getLegacyArtifactPaths()
48         throws ArchivaRestServiceException
49     {
50         try
51         {
52             List<LegacyArtifactPath> legacyArtifactPaths = new ArrayList<LegacyArtifactPath>();
53             for ( org.apache.archiva.admin.repository.admin.LegacyArtifactPath legacyArtifactPath : archivaAdministration.getLegacyArtifactPaths() )
54             {
55                 legacyArtifactPaths.add(
56                     new BeanReplicator().replicateBean( legacyArtifactPath, LegacyArtifactPath.class ) );
57             }
58             return legacyArtifactPaths;
59         }
60         catch ( RepositoryAdminException e )
61         {
62             throw new ArchivaRestServiceException( e.getMessage() );
63         }
64     }
65
66     public void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
67         throws ArchivaRestServiceException
68     {
69         try
70         {
71             archivaAdministration.addLegacyArtifactPath( new BeanReplicator().replicateBean( legacyArtifactPath,
72                                                                                              org.apache.archiva.admin.repository.admin.LegacyArtifactPath.class ),
73                                                          getAuditInformation() );
74         }
75         catch ( RepositoryAdminException e )
76         {
77             throw new ArchivaRestServiceException( e.getMessage() );
78         }
79     }
80
81     public Boolean deleteLegacyArtifactPath( String path )
82         throws ArchivaRestServiceException
83     {
84         try
85         {
86             archivaAdministration.deleteLegacyArtifactPath( path, getAuditInformation() );
87             return Boolean.TRUE;
88         }
89         catch ( RepositoryAdminException e )
90         {
91             throw new ArchivaRestServiceException( e.getMessage() );
92         }
93     }
94
95     public RepositoryScanning getRepositoryScanning()
96         throws ArchivaRestServiceException
97     {
98         try
99         {
100             return new BeanReplicator().replicateBean( archivaAdministration.getRepositoryScanning(),
101                                                        RepositoryScanning.class );
102         }
103         catch ( RepositoryAdminException e )
104         {
105             throw new ArchivaRestServiceException( e.getMessage() );
106         }
107     }
108
109     public void updateRepositoryScanning( RepositoryScanning repositoryScanning )
110         throws ArchivaRestServiceException
111     {
112         try
113         {
114             archivaAdministration.updateRepositoryScanning( new BeanReplicator().replicateBean( getRepositoryScanning(),
115                                                                                                 org.apache.archiva.admin.repository.admin.RepositoryScanning.class ),
116                                                             getAuditInformation() );
117         }
118         catch ( RepositoryAdminException e )
119         {
120             throw new ArchivaRestServiceException( e.getMessage() );
121         }
122     }
123
124     public Boolean addFileTypePattern( String fileTypeId, String pattern )
125         throws ArchivaRestServiceException
126     {
127         try
128         {
129             archivaAdministration.addFileTypePattern( fileTypeId, pattern, getAuditInformation() );
130             return Boolean.TRUE;
131         }
132         catch ( RepositoryAdminException e )
133         {
134             throw new ArchivaRestServiceException( e.getMessage() );
135         }
136     }
137
138     public Boolean removeFileTypePattern( String fileTypeId, String pattern )
139         throws ArchivaRestServiceException
140     {
141         try
142         {
143             archivaAdministration.removeFileTypePattern( fileTypeId, pattern, getAuditInformation() );
144             return Boolean.TRUE;
145         }
146         catch ( RepositoryAdminException e )
147         {
148             throw new ArchivaRestServiceException( e.getMessage() );
149         }
150     }
151
152     public FileType getFileType( String fileTypeId )
153         throws ArchivaRestServiceException
154     {
155         try
156         {
157             org.apache.archiva.admin.repository.admin.FileType fileType =
158                 archivaAdministration.getFileType( fileTypeId );
159             if ( fileType == null )
160             {
161                 return null;
162             }
163             return new BeanReplicator().replicateBean( fileType, FileType.class );
164         }
165         catch ( RepositoryAdminException e )
166         {
167             throw new ArchivaRestServiceException( e.getMessage() );
168         }
169     }
170
171     public void addFileType( FileType fileType )
172         throws ArchivaRestServiceException
173     {
174         try
175         {
176             archivaAdministration.addFileType( new BeanReplicator().replicateBean( fileType,
177                                                                                    org.apache.archiva.admin.repository.admin.FileType.class ),
178                                                getAuditInformation() );
179         }
180         catch ( RepositoryAdminException e )
181         {
182             throw new ArchivaRestServiceException( e.getMessage() );
183         }
184     }
185
186     public Boolean removeFileType( String fileTypeId )
187         throws ArchivaRestServiceException
188     {
189         try
190         {
191             archivaAdministration.removeFileType( fileTypeId, getAuditInformation() );
192             return Boolean.TRUE;
193         }
194         catch ( RepositoryAdminException e )
195         {
196             throw new ArchivaRestServiceException( e.getMessage() );
197         }
198     }
199
200     public Boolean addKnownContentConsumer( String knownContentConsumer )
201         throws ArchivaRestServiceException
202     {
203         try
204         {
205             archivaAdministration.addKnownContentConsumer( knownContentConsumer, getAuditInformation() );
206             return Boolean.TRUE;
207         }
208         catch ( RepositoryAdminException e )
209         {
210             throw new ArchivaRestServiceException( e.getMessage() );
211         }
212     }
213
214     public void setKnownContentConsumers( List<String> knownContentConsumers )
215         throws ArchivaRestServiceException
216     {
217         try
218         {
219             archivaAdministration.setKnownContentConsumers( knownContentConsumers, getAuditInformation() );
220         }
221         catch ( RepositoryAdminException e )
222         {
223             throw new ArchivaRestServiceException( e.getMessage() );
224         }
225     }
226
227     public Boolean removeKnownContentConsumer( String knownContentConsumer )
228         throws ArchivaRestServiceException
229     {
230         try
231         {
232             archivaAdministration.removeKnownContentConsumer( knownContentConsumer, getAuditInformation() );
233             return Boolean.TRUE;
234         }
235         catch ( RepositoryAdminException e )
236         {
237             throw new ArchivaRestServiceException( e.getMessage() );
238         }
239     }
240
241     public Boolean addInvalidContentConsumer( String invalidContentConsumer )
242         throws ArchivaRestServiceException
243     {
244         try
245         {
246             archivaAdministration.addInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
247             return Boolean.TRUE;
248         }
249         catch ( RepositoryAdminException e )
250         {
251             throw new ArchivaRestServiceException( e.getMessage() );
252         }
253     }
254
255     public void setInvalidContentConsumers( List<String> invalidContentConsumers )
256         throws ArchivaRestServiceException
257     {
258         try
259         {
260             archivaAdministration.setInvalidContentConsumers( invalidContentConsumers, getAuditInformation() );
261         }
262         catch ( RepositoryAdminException e )
263         {
264             throw new ArchivaRestServiceException( e.getMessage() );
265         }
266     }
267
268     public Boolean removeInvalidContentConsumer( String invalidContentConsumer )
269         throws ArchivaRestServiceException
270     {
271         try
272         {
273             archivaAdministration.removeInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
274             return Boolean.TRUE;
275         }
276         catch ( RepositoryAdminException e )
277         {
278             throw new ArchivaRestServiceException( e.getMessage() );
279         }
280     }
281 }