This project has retired. For details please refer to its
Attic page.
DefaultArchivaAdministrationService xref
1 package org.apache.archiva.rest.services;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import org.apache.archiva.admin.model.RepositoryAdminException;
22 import org.apache.archiva.admin.model.admin.ArchivaAdministration;
23 import org.apache.archiva.admin.model.beans.*;
24 import org.apache.archiva.repository.scanner.RepositoryContentConsumers;
25 import org.apache.archiva.rest.api.model.AdminRepositoryConsumer;
26 import org.apache.archiva.rest.api.services.ArchivaAdministrationService;
27 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
28 import org.apache.archiva.rest.services.utils.AddAdminRepoConsumerClosure;
29 import org.apache.archiva.rest.services.utils.AdminRepositoryConsumerComparator;
30 import org.apache.commons.collections4.IterableUtils;
31 import org.apache.commons.lang3.StringUtils;
32 import org.springframework.stereotype.Service;
33
34 import javax.inject.Inject;
35 import java.util.ArrayList;
36 import java.util.Collections;
37 import java.util.List;
38
39
40
41
42
43 @Service ( "archivaAdministrationService#default" )
44 public class DefaultArchivaAdministrationService
45 extends AbstractRestService
46 implements ArchivaAdministrationService
47 {
48 @Inject
49 private ArchivaAdministration archivaAdministration;
50
51
52 @Inject
53 private RepositoryContentConsumers repoConsumerUtil;
54
55 @Override
56 public List<LegacyArtifactPath> getLegacyArtifactPaths()
57 throws ArchivaRestServiceException
58 {
59 try
60 {
61 return archivaAdministration.getLegacyArtifactPaths();
62 }
63 catch ( RepositoryAdminException e )
64 {
65 throw new ArchivaRestServiceException( e.getMessage(), e );
66 }
67 }
68
69
70 @Override
71 public Boolean deleteLegacyArtifactPath( String path )
72 throws ArchivaRestServiceException
73 {
74 try
75 {
76 archivaAdministration.deleteLegacyArtifactPath( path, getAuditInformation() );
77 return Boolean.TRUE;
78 }
79 catch ( RepositoryAdminException e )
80 {
81 throw new ArchivaRestServiceException( e.getMessage(), e );
82 }
83 }
84
85
86 @Override
87 public Boolean addFileTypePattern( String fileTypeId, String pattern )
88 throws ArchivaRestServiceException
89 {
90 try
91 {
92 archivaAdministration.addFileTypePattern( fileTypeId, pattern, getAuditInformation() );
93 return Boolean.TRUE;
94 }
95 catch ( RepositoryAdminException e )
96 {
97 throw new ArchivaRestServiceException( e.getMessage(), e );
98 }
99 }
100
101 @Override
102 public Boolean removeFileTypePattern( String fileTypeId, String pattern )
103 throws ArchivaRestServiceException
104 {
105 try
106 {
107 archivaAdministration.removeFileTypePattern( fileTypeId, pattern, getAuditInformation() );
108 return Boolean.TRUE;
109 }
110 catch ( RepositoryAdminException e )
111 {
112 throw new ArchivaRestServiceException( e.getMessage(), e );
113 }
114 }
115
116 @Override
117 public FileType getFileType( String fileTypeId )
118 throws ArchivaRestServiceException
119 {
120 try
121 {
122 return archivaAdministration.getFileType( fileTypeId );
123 }
124 catch ( RepositoryAdminException e )
125 {
126 throw new ArchivaRestServiceException( e.getMessage(), e );
127 }
128 }
129
130 @Override
131 public void addFileType( FileType fileType )
132 throws ArchivaRestServiceException
133 {
134 try
135 {
136 archivaAdministration.addFileType( fileType, getAuditInformation() );
137 }
138 catch ( RepositoryAdminException e )
139 {
140 throw new ArchivaRestServiceException( e.getMessage(), e );
141 }
142 }
143
144 @Override
145 public Boolean removeFileType( String fileTypeId )
146 throws ArchivaRestServiceException
147 {
148 try
149 {
150 archivaAdministration.removeFileType( fileTypeId, getAuditInformation() );
151 return Boolean.TRUE;
152 }
153 catch ( RepositoryAdminException e )
154 {
155 throw new ArchivaRestServiceException( e.getMessage(), e );
156 }
157 }
158
159 @Override
160 public Boolean enabledKnownContentConsumer( String knownContentConsumer )
161 throws ArchivaRestServiceException
162 {
163 try
164 {
165 archivaAdministration.addKnownContentConsumer( knownContentConsumer, getAuditInformation() );
166 return Boolean.TRUE;
167 }
168 catch ( RepositoryAdminException e )
169 {
170 throw new ArchivaRestServiceException( e.getMessage(), e );
171 }
172 }
173
174 @Override
175 public void enabledKnownContentConsumers( List<String> knownContentConsumers )
176 throws ArchivaRestServiceException
177 {
178 try
179 {
180 archivaAdministration.setKnownContentConsumers( knownContentConsumers, getAuditInformation() );
181 }
182 catch ( RepositoryAdminException e )
183 {
184 throw new ArchivaRestServiceException( e.getMessage(), e );
185 }
186 }
187
188 @Override
189 public Boolean disabledKnownContentConsumer( String knownContentConsumer )
190 throws ArchivaRestServiceException
191 {
192 try
193 {
194 archivaAdministration.removeKnownContentConsumer( knownContentConsumer, getAuditInformation() );
195 return Boolean.TRUE;
196 }
197 catch ( RepositoryAdminException e )
198 {
199 throw new ArchivaRestServiceException( e.getMessage(), e );
200 }
201 }
202
203 @Override
204 public Boolean enabledInvalidContentConsumer( String invalidContentConsumer )
205 throws ArchivaRestServiceException
206 {
207 try
208 {
209 archivaAdministration.addInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
210 return Boolean.TRUE;
211 }
212 catch ( RepositoryAdminException e )
213 {
214 throw new ArchivaRestServiceException( e.getMessage(), e );
215 }
216 }
217
218 @Override
219 public void enabledInvalidContentConsumers( List<String> invalidContentConsumers )
220 throws ArchivaRestServiceException
221 {
222 try
223 {
224 archivaAdministration.setInvalidContentConsumers( invalidContentConsumers, getAuditInformation() );
225 }
226 catch ( RepositoryAdminException e )
227 {
228 throw new ArchivaRestServiceException( e.getMessage(), e );
229 }
230 }
231
232 @Override
233 public Boolean disabledInvalidContentConsumer( String invalidContentConsumer )
234 throws ArchivaRestServiceException
235 {
236 try
237 {
238 archivaAdministration.removeInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
239 return Boolean.TRUE;
240 }
241 catch ( RepositoryAdminException e )
242 {
243 throw new ArchivaRestServiceException( e.getMessage(), e );
244 }
245 }
246
247 @Override
248 public List<FileType> getFileTypes()
249 throws ArchivaRestServiceException
250 {
251 try
252 {
253 List<FileType> modelfileTypes = archivaAdministration.getFileTypes();
254 if ( modelfileTypes == null || modelfileTypes.isEmpty() )
255 {
256 return Collections.emptyList();
257 }
258 return modelfileTypes;
259 }
260 catch ( RepositoryAdminException e )
261 {
262 throw new ArchivaRestServiceException( e.getMessage(), e );
263 }
264 }
265
266 @Override
267 public List<String> getKnownContentConsumers()
268 throws ArchivaRestServiceException
269 {
270 try
271 {
272 return new ArrayList<>( archivaAdministration.getKnownContentConsumers( ) );
273 }
274 catch ( RepositoryAdminException e )
275 {
276 throw new ArchivaRestServiceException( e.getMessage(), e );
277 }
278 }
279
280 @Override
281 public List<String> getInvalidContentConsumers()
282 throws ArchivaRestServiceException
283 {
284 try
285 {
286 return new ArrayList<>( archivaAdministration.getInvalidContentConsumers( ) );
287 }
288 catch ( RepositoryAdminException e )
289 {
290 throw new ArchivaRestServiceException( e.getMessage(), e );
291 }
292 }
293
294 @Override
295 public OrganisationInformation getOrganisationInformation()
296 throws ArchivaRestServiceException
297 {
298 try
299 {
300 return archivaAdministration.getOrganisationInformation();
301 }
302 catch ( RepositoryAdminException e )
303 {
304 throw new ArchivaRestServiceException( e.getMessage(), e );
305 }
306 }
307
308 @Override
309 public void setOrganisationInformation( OrganisationInformation organisationInformation )
310 throws ArchivaRestServiceException
311 {
312 try
313 {
314 archivaAdministration.setOrganisationInformation( organisationInformation );
315 }
316 catch ( RepositoryAdminException e )
317 {
318 throw new ArchivaRestServiceException( e.getMessage(), 400, e );
319 }
320 }
321
322 @Override
323 public Boolean registrationDisabled()
324 throws ArchivaRestServiceException
325 {
326 return getUiConfiguration().isDisableRegistration();
327 }
328
329 @Override
330 public UiConfiguration getUiConfiguration()
331 throws ArchivaRestServiceException
332 {
333 try
334 {
335 return archivaAdministration.getUiConfiguration();
336 }
337 catch ( RepositoryAdminException e )
338 {
339 throw new ArchivaRestServiceException( e.getMessage(), e );
340 }
341 }
342
343 @Override
344 public void setUiConfiguration( UiConfiguration uiConfiguration )
345 throws ArchivaRestServiceException
346 {
347 try
348 {
349
350
351 uiConfiguration.setApplicationUrl(StringUtils.stripEnd(uiConfiguration.getApplicationUrl(), "/"));
352
353 archivaAdministration.updateUiConfiguration( uiConfiguration );
354 }
355 catch ( RepositoryAdminException e )
356 {
357 throw new ArchivaRestServiceException( e.getMessage(), e );
358 }
359 }
360
361 @Override
362 public String getApplicationUrl()
363 throws ArchivaRestServiceException
364 {
365 try
366 {
367 return archivaAdministration.getUiConfiguration().getApplicationUrl();
368 }
369 catch ( RepositoryAdminException e )
370 {
371 throw new ArchivaRestServiceException( e.getMessage(), e );
372 }
373 }
374
375 @Override
376 public NetworkConfiguration getNetworkConfiguration()
377 throws ArchivaRestServiceException
378 {
379 try
380 {
381 return archivaAdministration.getNetworkConfiguration();
382 }
383 catch ( RepositoryAdminException e )
384 {
385 throw new ArchivaRestServiceException( e.getMessage(), e );
386 }
387 }
388
389 @Override
390 public void setNetworkConfiguration( NetworkConfiguration networkConfiguration )
391 throws ArchivaRestServiceException
392 {
393 try
394 {
395 archivaAdministration.setNetworkConfiguration( networkConfiguration );
396 }
397 catch ( RepositoryAdminException e )
398 {
399 throw new ArchivaRestServiceException( e.getMessage(), e );
400 }
401 }
402
403 @Override
404 public List<AdminRepositoryConsumer> getKnownContentAdminRepositoryConsumers()
405 throws ArchivaRestServiceException
406 {
407 try
408 {
409 AddAdminRepoConsumerClosure addAdminRepoConsumer =
410 new AddAdminRepoConsumerClosure( archivaAdministration.getKnownContentConsumers() );
411 IterableUtils.forEach( repoConsumerUtil.getAvailableKnownConsumers(), addAdminRepoConsumer );
412 List<AdminRepositoryConsumer> knownContentConsumers = addAdminRepoConsumer.getList();
413 knownContentConsumers.sort( AdminRepositoryConsumerComparator.getInstance( ) );
414 return knownContentConsumers;
415 }
416 catch ( RepositoryAdminException e )
417 {
418 throw new ArchivaRestServiceException( e.getMessage(), e );
419 }
420 }
421
422 @Override
423 public List<AdminRepositoryConsumer> getInvalidContentAdminRepositoryConsumers()
424 throws ArchivaRestServiceException
425 {
426 try
427 {
428 AddAdminRepoConsumerClosure addAdminRepoConsumer =
429 new AddAdminRepoConsumerClosure( archivaAdministration.getInvalidContentConsumers() );
430 IterableUtils.forEach( repoConsumerUtil.getAvailableInvalidConsumers(), addAdminRepoConsumer );
431 List<AdminRepositoryConsumer> invalidContentConsumers = addAdminRepoConsumer.getList();
432 invalidContentConsumers.sort( AdminRepositoryConsumerComparator.getInstance( ) );
433 return invalidContentConsumers;
434 }
435 catch ( RepositoryAdminException e )
436 {
437 throw new ArchivaRestServiceException( e.getMessage(), e );
438 }
439 }
440 }