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.*;
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;
34 import javax.inject.Inject;
35 import java.util.ArrayList;
36 import java.util.Collections;
37 import java.util.List;
40 * @author Olivier Lamy
43 @Service ( "archivaAdministrationService#default" )
44 public class DefaultArchivaAdministrationService
45 extends AbstractRestService
46 implements ArchivaAdministrationService
49 private ArchivaAdministration archivaAdministration;
53 private RepositoryContentConsumers repoConsumerUtil;
56 public List<LegacyArtifactPath> getLegacyArtifactPaths()
57 throws ArchivaRestServiceException
61 return archivaAdministration.getLegacyArtifactPaths();
63 catch ( RepositoryAdminException e )
65 throw new ArchivaRestServiceException( e.getMessage(), e );
71 public Boolean deleteLegacyArtifactPath( String path )
72 throws ArchivaRestServiceException
76 archivaAdministration.deleteLegacyArtifactPath( path, getAuditInformation() );
79 catch ( RepositoryAdminException e )
81 throw new ArchivaRestServiceException( e.getMessage(), e );
87 public Boolean addFileTypePattern( String fileTypeId, String pattern )
88 throws ArchivaRestServiceException
92 archivaAdministration.addFileTypePattern( fileTypeId, pattern, getAuditInformation() );
95 catch ( RepositoryAdminException e )
97 throw new ArchivaRestServiceException( e.getMessage(), e );
102 public Boolean removeFileTypePattern( String fileTypeId, String pattern )
103 throws ArchivaRestServiceException
107 archivaAdministration.removeFileTypePattern( fileTypeId, pattern, getAuditInformation() );
110 catch ( RepositoryAdminException e )
112 throw new ArchivaRestServiceException( e.getMessage(), e );
117 public FileType getFileType( String fileTypeId )
118 throws ArchivaRestServiceException
122 return archivaAdministration.getFileType( fileTypeId );
124 catch ( RepositoryAdminException e )
126 throw new ArchivaRestServiceException( e.getMessage(), e );
131 public void addFileType( FileType fileType )
132 throws ArchivaRestServiceException
136 archivaAdministration.addFileType( fileType, getAuditInformation() );
138 catch ( RepositoryAdminException e )
140 throw new ArchivaRestServiceException( e.getMessage(), e );
145 public Boolean removeFileType( String fileTypeId )
146 throws ArchivaRestServiceException
150 archivaAdministration.removeFileType( fileTypeId, getAuditInformation() );
153 catch ( RepositoryAdminException e )
155 throw new ArchivaRestServiceException( e.getMessage(), e );
160 public Boolean enabledKnownContentConsumer( String knownContentConsumer )
161 throws ArchivaRestServiceException
165 archivaAdministration.addKnownContentConsumer( knownContentConsumer, getAuditInformation() );
168 catch ( RepositoryAdminException e )
170 throw new ArchivaRestServiceException( e.getMessage(), e );
175 public void enabledKnownContentConsumers( List<String> knownContentConsumers )
176 throws ArchivaRestServiceException
180 archivaAdministration.setKnownContentConsumers( knownContentConsumers, getAuditInformation() );
182 catch ( RepositoryAdminException e )
184 throw new ArchivaRestServiceException( e.getMessage(), e );
189 public Boolean disabledKnownContentConsumer( String knownContentConsumer )
190 throws ArchivaRestServiceException
194 archivaAdministration.removeKnownContentConsumer( knownContentConsumer, getAuditInformation() );
197 catch ( RepositoryAdminException e )
199 throw new ArchivaRestServiceException( e.getMessage(), e );
204 public Boolean enabledInvalidContentConsumer( String invalidContentConsumer )
205 throws ArchivaRestServiceException
209 archivaAdministration.addInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
212 catch ( RepositoryAdminException e )
214 throw new ArchivaRestServiceException( e.getMessage(), e );
219 public void enabledInvalidContentConsumers( List<String> invalidContentConsumers )
220 throws ArchivaRestServiceException
224 archivaAdministration.setInvalidContentConsumers( invalidContentConsumers, getAuditInformation() );
226 catch ( RepositoryAdminException e )
228 throw new ArchivaRestServiceException( e.getMessage(), e );
233 public Boolean disabledInvalidContentConsumer( String invalidContentConsumer )
234 throws ArchivaRestServiceException
238 archivaAdministration.removeInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
241 catch ( RepositoryAdminException e )
243 throw new ArchivaRestServiceException( e.getMessage(), e );
248 public List<FileType> getFileTypes()
249 throws ArchivaRestServiceException
253 List<FileType> modelfileTypes = archivaAdministration.getFileTypes();
254 if ( modelfileTypes == null || modelfileTypes.isEmpty() )
256 return Collections.emptyList();
258 return modelfileTypes;
260 catch ( RepositoryAdminException e )
262 throw new ArchivaRestServiceException( e.getMessage(), e );
267 public List<String> getKnownContentConsumers()
268 throws ArchivaRestServiceException
272 return new ArrayList<>( archivaAdministration.getKnownContentConsumers( ) );
274 catch ( RepositoryAdminException e )
276 throw new ArchivaRestServiceException( e.getMessage(), e );
281 public List<String> getInvalidContentConsumers()
282 throws ArchivaRestServiceException
286 return new ArrayList<>( archivaAdministration.getInvalidContentConsumers( ) );
288 catch ( RepositoryAdminException e )
290 throw new ArchivaRestServiceException( e.getMessage(), e );
295 public OrganisationInformation getOrganisationInformation()
296 throws ArchivaRestServiceException
300 return archivaAdministration.getOrganisationInformation();
302 catch ( RepositoryAdminException e )
304 throw new ArchivaRestServiceException( e.getMessage(), e );
309 public void setOrganisationInformation( OrganisationInformation organisationInformation )
310 throws ArchivaRestServiceException
314 archivaAdministration.setOrganisationInformation( organisationInformation );
316 catch ( RepositoryAdminException e )
318 throw new ArchivaRestServiceException( e.getMessage(), 400, e );
323 public Boolean registrationDisabled()
324 throws ArchivaRestServiceException
326 return getUiConfiguration().isDisableRegistration();
330 public UiConfiguration getUiConfiguration()
331 throws ArchivaRestServiceException
335 return archivaAdministration.getUiConfiguration();
337 catch ( RepositoryAdminException e )
339 throw new ArchivaRestServiceException( e.getMessage(), e );
344 public void setUiConfiguration( UiConfiguration uiConfiguration )
345 throws ArchivaRestServiceException
350 // strip any trailing '/' at the end of the url so it won't affect url/link calculations in UI
351 uiConfiguration.setApplicationUrl(StringUtils.stripEnd(uiConfiguration.getApplicationUrl(), "/"));
353 archivaAdministration.updateUiConfiguration( uiConfiguration );
355 catch ( RepositoryAdminException e )
357 throw new ArchivaRestServiceException( e.getMessage(), e );
362 public String getApplicationUrl()
363 throws ArchivaRestServiceException
367 return archivaAdministration.getUiConfiguration().getApplicationUrl();
369 catch ( RepositoryAdminException e )
371 throw new ArchivaRestServiceException( e.getMessage(), e );
376 public NetworkConfiguration getNetworkConfiguration()
377 throws ArchivaRestServiceException
381 return archivaAdministration.getNetworkConfiguration();
383 catch ( RepositoryAdminException e )
385 throw new ArchivaRestServiceException( e.getMessage(), e );
390 public void setNetworkConfiguration( NetworkConfiguration networkConfiguration )
391 throws ArchivaRestServiceException
395 archivaAdministration.setNetworkConfiguration( networkConfiguration );
397 catch ( RepositoryAdminException e )
399 throw new ArchivaRestServiceException( e.getMessage(), e );
404 public List<AdminRepositoryConsumer> getKnownContentAdminRepositoryConsumers()
405 throws ArchivaRestServiceException
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;
416 catch ( RepositoryAdminException e )
418 throw new ArchivaRestServiceException( e.getMessage(), e );
423 public List<AdminRepositoryConsumer> getInvalidContentAdminRepositoryConsumers()
424 throws ArchivaRestServiceException
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;
435 catch ( RepositoryAdminException e )
437 throw new ArchivaRestServiceException( e.getMessage(), e );