1 package org.apache.archiva.rest.services;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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
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.FileType;
24 import org.apache.archiva.admin.model.beans.LegacyArtifactPath;
25 import org.apache.archiva.admin.model.beans.NetworkConfiguration;
26 import org.apache.archiva.admin.model.beans.OrganisationInformation;
27 import org.apache.archiva.admin.model.beans.UiConfiguration;
28 import org.apache.archiva.repository.scanner.RepositoryContentConsumers;
29 import org.apache.archiva.rest.api.model.AdminRepositoryConsumer;
30 import org.apache.archiva.rest.api.services.ArchivaAdministrationService;
31 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
32 import org.apache.archiva.rest.services.utils.AddAdminRepoConsumerClosure;
33 import org.apache.archiva.rest.services.utils.AdminRepositoryConsumerComparator;
34 import org.apache.commons.collections4.CollectionUtils;
35 import org.apache.commons.collections4.IterableUtils;
36 import org.apache.commons.lang.StringUtils;
37 import org.springframework.stereotype.Service;
39 import javax.inject.Inject;
40 import java.util.ArrayList;
41 import java.util.Collections;
42 import java.util.List;
45 * @author Olivier Lamy
48 @Service ( "archivaAdministrationService#default" )
49 public class DefaultArchivaAdministrationService
50 extends AbstractRestService
51 implements ArchivaAdministrationService
54 private ArchivaAdministration archivaAdministration;
58 private RepositoryContentConsumers repoConsumerUtil;
61 public List<LegacyArtifactPath> getLegacyArtifactPaths()
62 throws ArchivaRestServiceException
66 return archivaAdministration.getLegacyArtifactPaths();
68 catch ( RepositoryAdminException e )
70 throw new ArchivaRestServiceException( e.getMessage(), e );
76 public Boolean deleteLegacyArtifactPath( String path )
77 throws ArchivaRestServiceException
81 archivaAdministration.deleteLegacyArtifactPath( path, getAuditInformation() );
84 catch ( RepositoryAdminException e )
86 throw new ArchivaRestServiceException( e.getMessage(), e );
92 public Boolean addFileTypePattern( String fileTypeId, String pattern )
93 throws ArchivaRestServiceException
97 archivaAdministration.addFileTypePattern( fileTypeId, pattern, getAuditInformation() );
100 catch ( RepositoryAdminException e )
102 throw new ArchivaRestServiceException( e.getMessage(), e );
107 public Boolean removeFileTypePattern( String fileTypeId, String pattern )
108 throws ArchivaRestServiceException
112 archivaAdministration.removeFileTypePattern( fileTypeId, pattern, getAuditInformation() );
115 catch ( RepositoryAdminException e )
117 throw new ArchivaRestServiceException( e.getMessage(), e );
122 public FileType getFileType( String fileTypeId )
123 throws ArchivaRestServiceException
127 return archivaAdministration.getFileType( fileTypeId );
129 catch ( RepositoryAdminException e )
131 throw new ArchivaRestServiceException( e.getMessage(), e );
136 public void addFileType( FileType fileType )
137 throws ArchivaRestServiceException
141 archivaAdministration.addFileType( fileType, getAuditInformation() );
143 catch ( RepositoryAdminException e )
145 throw new ArchivaRestServiceException( e.getMessage(), e );
150 public Boolean removeFileType( String fileTypeId )
151 throws ArchivaRestServiceException
155 archivaAdministration.removeFileType( fileTypeId, getAuditInformation() );
158 catch ( RepositoryAdminException e )
160 throw new ArchivaRestServiceException( e.getMessage(), e );
165 public Boolean enabledKnownContentConsumer( String knownContentConsumer )
166 throws ArchivaRestServiceException
170 archivaAdministration.addKnownContentConsumer( knownContentConsumer, getAuditInformation() );
173 catch ( RepositoryAdminException e )
175 throw new ArchivaRestServiceException( e.getMessage(), e );
180 public void enabledKnownContentConsumers( List<String> knownContentConsumers )
181 throws ArchivaRestServiceException
185 archivaAdministration.setKnownContentConsumers( knownContentConsumers, getAuditInformation() );
187 catch ( RepositoryAdminException e )
189 throw new ArchivaRestServiceException( e.getMessage(), e );
194 public Boolean disabledKnownContentConsumer( String knownContentConsumer )
195 throws ArchivaRestServiceException
199 archivaAdministration.removeKnownContentConsumer( knownContentConsumer, getAuditInformation() );
202 catch ( RepositoryAdminException e )
204 throw new ArchivaRestServiceException( e.getMessage(), e );
209 public Boolean enabledInvalidContentConsumer( String invalidContentConsumer )
210 throws ArchivaRestServiceException
214 archivaAdministration.addInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
217 catch ( RepositoryAdminException e )
219 throw new ArchivaRestServiceException( e.getMessage(), e );
224 public void enabledInvalidContentConsumers( List<String> invalidContentConsumers )
225 throws ArchivaRestServiceException
229 archivaAdministration.setInvalidContentConsumers( invalidContentConsumers, getAuditInformation() );
231 catch ( RepositoryAdminException e )
233 throw new ArchivaRestServiceException( e.getMessage(), e );
238 public Boolean disabledInvalidContentConsumer( String invalidContentConsumer )
239 throws ArchivaRestServiceException
243 archivaAdministration.removeInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
246 catch ( RepositoryAdminException e )
248 throw new ArchivaRestServiceException( e.getMessage(), e );
253 public List<FileType> getFileTypes()
254 throws ArchivaRestServiceException
258 List<FileType> modelfileTypes = archivaAdministration.getFileTypes();
259 if ( modelfileTypes == null || modelfileTypes.isEmpty() )
261 return Collections.emptyList();
263 return modelfileTypes;
265 catch ( RepositoryAdminException e )
267 throw new ArchivaRestServiceException( e.getMessage(), e );
272 public List<String> getKnownContentConsumers()
273 throws ArchivaRestServiceException
277 return new ArrayList<String>( archivaAdministration.getKnownContentConsumers() );
279 catch ( RepositoryAdminException e )
281 throw new ArchivaRestServiceException( e.getMessage(), e );
286 public List<String> getInvalidContentConsumers()
287 throws ArchivaRestServiceException
291 return new ArrayList<String>( archivaAdministration.getInvalidContentConsumers() );
293 catch ( RepositoryAdminException e )
295 throw new ArchivaRestServiceException( e.getMessage(), e );
300 public OrganisationInformation getOrganisationInformation()
301 throws ArchivaRestServiceException
305 return archivaAdministration.getOrganisationInformation();
307 catch ( RepositoryAdminException e )
309 throw new ArchivaRestServiceException( e.getMessage(), e );
314 public void setOrganisationInformation( OrganisationInformation organisationInformation )
315 throws ArchivaRestServiceException
319 archivaAdministration.setOrganisationInformation( organisationInformation );
321 catch ( RepositoryAdminException e )
323 throw new ArchivaRestServiceException( e.getMessage(), e );
328 public Boolean registrationDisabled()
329 throws ArchivaRestServiceException
331 return getUiConfiguration().isDisableRegistration();
335 public UiConfiguration getUiConfiguration()
336 throws ArchivaRestServiceException
340 return archivaAdministration.getUiConfiguration();
342 catch ( RepositoryAdminException e )
344 throw new ArchivaRestServiceException( e.getMessage(), e );
349 public void setUiConfiguration( UiConfiguration uiConfiguration )
350 throws ArchivaRestServiceException
355 // strip any trailing '/' at the end of the url so it won't affect url/link calculations in UI
356 uiConfiguration.setApplicationUrl(StringUtils.stripEnd(uiConfiguration.getApplicationUrl(), "/"));
358 archivaAdministration.updateUiConfiguration( uiConfiguration );
360 catch ( RepositoryAdminException e )
362 throw new ArchivaRestServiceException( e.getMessage(), e );
367 public String getApplicationUrl()
368 throws ArchivaRestServiceException
372 return archivaAdministration.getUiConfiguration().getApplicationUrl();
374 catch ( RepositoryAdminException e )
376 throw new ArchivaRestServiceException( e.getMessage(), e );
381 public NetworkConfiguration getNetworkConfiguration()
382 throws ArchivaRestServiceException
386 return archivaAdministration.getNetworkConfiguration();
388 catch ( RepositoryAdminException e )
390 throw new ArchivaRestServiceException( e.getMessage(), e );
395 public void setNetworkConfiguration( NetworkConfiguration networkConfiguration )
396 throws ArchivaRestServiceException
400 archivaAdministration.setNetworkConfiguration( networkConfiguration );
402 catch ( RepositoryAdminException e )
404 throw new ArchivaRestServiceException( e.getMessage(), e );
409 public List<AdminRepositoryConsumer> getKnownContentAdminRepositoryConsumers()
410 throws ArchivaRestServiceException
414 AddAdminRepoConsumerClosure addAdminRepoConsumer =
415 new AddAdminRepoConsumerClosure( archivaAdministration.getKnownContentConsumers() );
416 IterableUtils.forEach( repoConsumerUtil.getAvailableKnownConsumers(), addAdminRepoConsumer );
417 List<AdminRepositoryConsumer> knownContentConsumers = addAdminRepoConsumer.getList();
418 Collections.sort( knownContentConsumers, AdminRepositoryConsumerComparator.getInstance() );
419 return knownContentConsumers;
421 catch ( RepositoryAdminException e )
423 throw new ArchivaRestServiceException( e.getMessage(), e );
428 public List<AdminRepositoryConsumer> getInvalidContentAdminRepositoryConsumers()
429 throws ArchivaRestServiceException
433 AddAdminRepoConsumerClosure addAdminRepoConsumer =
434 new AddAdminRepoConsumerClosure( archivaAdministration.getInvalidContentConsumers() );
435 IterableUtils.forEach( repoConsumerUtil.getAvailableInvalidConsumers(), addAdminRepoConsumer );
436 List<AdminRepositoryConsumer> invalidContentConsumers = addAdminRepoConsumer.getList();
437 Collections.sort( invalidContentConsumers, AdminRepositoryConsumerComparator.getInstance() );
438 return invalidContentConsumers;
440 catch ( RepositoryAdminException e )
442 throw new ArchivaRestServiceException( e.getMessage(), e );