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.collections.CollectionUtils;
35 import org.apache.commons.lang.StringUtils;
36 import org.springframework.stereotype.Service;
38 import javax.inject.Inject;
39 import java.util.ArrayList;
40 import java.util.Collections;
41 import java.util.List;
44 * @author Olivier Lamy
47 @Service ( "archivaAdministrationService#default" )
48 public class DefaultArchivaAdministrationService
49 extends AbstractRestService
50 implements ArchivaAdministrationService
53 private ArchivaAdministration archivaAdministration;
57 private RepositoryContentConsumers repoConsumerUtil;
60 public List<LegacyArtifactPath> getLegacyArtifactPaths()
61 throws ArchivaRestServiceException
65 return archivaAdministration.getLegacyArtifactPaths();
67 catch ( RepositoryAdminException e )
69 throw new ArchivaRestServiceException( e.getMessage(), e );
75 public Boolean deleteLegacyArtifactPath( String path )
76 throws ArchivaRestServiceException
80 archivaAdministration.deleteLegacyArtifactPath( path, getAuditInformation() );
83 catch ( RepositoryAdminException e )
85 throw new ArchivaRestServiceException( e.getMessage(), e );
91 public Boolean addFileTypePattern( String fileTypeId, String pattern )
92 throws ArchivaRestServiceException
96 archivaAdministration.addFileTypePattern( fileTypeId, pattern, getAuditInformation() );
99 catch ( RepositoryAdminException e )
101 throw new ArchivaRestServiceException( e.getMessage(), e );
106 public Boolean removeFileTypePattern( String fileTypeId, String pattern )
107 throws ArchivaRestServiceException
111 archivaAdministration.removeFileTypePattern( fileTypeId, pattern, getAuditInformation() );
114 catch ( RepositoryAdminException e )
116 throw new ArchivaRestServiceException( e.getMessage(), e );
121 public FileType getFileType( String fileTypeId )
122 throws ArchivaRestServiceException
126 return archivaAdministration.getFileType( fileTypeId );
128 catch ( RepositoryAdminException e )
130 throw new ArchivaRestServiceException( e.getMessage(), e );
135 public void addFileType( FileType fileType )
136 throws ArchivaRestServiceException
140 archivaAdministration.addFileType( fileType, getAuditInformation() );
142 catch ( RepositoryAdminException e )
144 throw new ArchivaRestServiceException( e.getMessage(), e );
149 public Boolean removeFileType( String fileTypeId )
150 throws ArchivaRestServiceException
154 archivaAdministration.removeFileType( fileTypeId, getAuditInformation() );
157 catch ( RepositoryAdminException e )
159 throw new ArchivaRestServiceException( e.getMessage(), e );
164 public Boolean enabledKnownContentConsumer( String knownContentConsumer )
165 throws ArchivaRestServiceException
169 archivaAdministration.addKnownContentConsumer( knownContentConsumer, getAuditInformation() );
172 catch ( RepositoryAdminException e )
174 throw new ArchivaRestServiceException( e.getMessage(), e );
179 public void enabledKnownContentConsumers( List<String> knownContentConsumers )
180 throws ArchivaRestServiceException
184 archivaAdministration.setKnownContentConsumers( knownContentConsumers, getAuditInformation() );
186 catch ( RepositoryAdminException e )
188 throw new ArchivaRestServiceException( e.getMessage(), e );
193 public Boolean disabledKnownContentConsumer( String knownContentConsumer )
194 throws ArchivaRestServiceException
198 archivaAdministration.removeKnownContentConsumer( knownContentConsumer, getAuditInformation() );
201 catch ( RepositoryAdminException e )
203 throw new ArchivaRestServiceException( e.getMessage(), e );
208 public Boolean enabledInvalidContentConsumer( String invalidContentConsumer )
209 throws ArchivaRestServiceException
213 archivaAdministration.addInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
216 catch ( RepositoryAdminException e )
218 throw new ArchivaRestServiceException( e.getMessage(), e );
223 public void enabledInvalidContentConsumers( List<String> invalidContentConsumers )
224 throws ArchivaRestServiceException
228 archivaAdministration.setInvalidContentConsumers( invalidContentConsumers, getAuditInformation() );
230 catch ( RepositoryAdminException e )
232 throw new ArchivaRestServiceException( e.getMessage(), e );
237 public Boolean disabledInvalidContentConsumer( String invalidContentConsumer )
238 throws ArchivaRestServiceException
242 archivaAdministration.removeInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
245 catch ( RepositoryAdminException e )
247 throw new ArchivaRestServiceException( e.getMessage(), e );
252 public List<FileType> getFileTypes()
253 throws ArchivaRestServiceException
257 List<FileType> modelfileTypes = archivaAdministration.getFileTypes();
258 if ( modelfileTypes == null || modelfileTypes.isEmpty() )
260 return Collections.emptyList();
262 return modelfileTypes;
264 catch ( RepositoryAdminException e )
266 throw new ArchivaRestServiceException( e.getMessage(), e );
271 public List<String> getKnownContentConsumers()
272 throws ArchivaRestServiceException
276 return new ArrayList<String>( archivaAdministration.getKnownContentConsumers() );
278 catch ( RepositoryAdminException e )
280 throw new ArchivaRestServiceException( e.getMessage(), e );
285 public List<String> getInvalidContentConsumers()
286 throws ArchivaRestServiceException
290 return new ArrayList<String>( archivaAdministration.getInvalidContentConsumers() );
292 catch ( RepositoryAdminException e )
294 throw new ArchivaRestServiceException( e.getMessage(), e );
299 public OrganisationInformation getOrganisationInformation()
300 throws ArchivaRestServiceException
304 return archivaAdministration.getOrganisationInformation();
306 catch ( RepositoryAdminException e )
308 throw new ArchivaRestServiceException( e.getMessage(), e );
313 public void setOrganisationInformation( OrganisationInformation organisationInformation )
314 throws ArchivaRestServiceException
318 archivaAdministration.setOrganisationInformation( organisationInformation );
320 catch ( RepositoryAdminException e )
322 throw new ArchivaRestServiceException( e.getMessage(), e );
327 public Boolean registrationDisabled()
328 throws ArchivaRestServiceException
330 return getUiConfiguration().isDisableRegistration();
334 public UiConfiguration getUiConfiguration()
335 throws ArchivaRestServiceException
339 return archivaAdministration.getUiConfiguration();
341 catch ( RepositoryAdminException e )
343 throw new ArchivaRestServiceException( e.getMessage(), e );
348 public void setUiConfiguration( UiConfiguration uiConfiguration )
349 throws ArchivaRestServiceException
354 // strip any trailing '/' at the end of the url so it won't affect url/link calculations in UI
355 uiConfiguration.setApplicationUrl(StringUtils.stripEnd(uiConfiguration.getApplicationUrl(), "/"));
357 archivaAdministration.updateUiConfiguration( uiConfiguration );
359 catch ( RepositoryAdminException e )
361 throw new ArchivaRestServiceException( e.getMessage(), e );
366 public String getApplicationUrl()
367 throws ArchivaRestServiceException
371 return archivaAdministration.getUiConfiguration().getApplicationUrl();
373 catch ( RepositoryAdminException e )
375 throw new ArchivaRestServiceException( e.getMessage(), e );
380 public NetworkConfiguration getNetworkConfiguration()
381 throws ArchivaRestServiceException
385 return archivaAdministration.getNetworkConfiguration();
387 catch ( RepositoryAdminException e )
389 throw new ArchivaRestServiceException( e.getMessage(), e );
394 public void setNetworkConfiguration( NetworkConfiguration networkConfiguration )
395 throws ArchivaRestServiceException
399 archivaAdministration.setNetworkConfiguration( networkConfiguration );
401 catch ( RepositoryAdminException e )
403 throw new ArchivaRestServiceException( e.getMessage(), e );
408 public List<AdminRepositoryConsumer> getKnownContentAdminRepositoryConsumers()
409 throws ArchivaRestServiceException
413 AddAdminRepoConsumerClosure addAdminRepoConsumer =
414 new AddAdminRepoConsumerClosure( archivaAdministration.getKnownContentConsumers() );
415 CollectionUtils.forAllDo( repoConsumerUtil.getAvailableKnownConsumers(), addAdminRepoConsumer );
416 List<AdminRepositoryConsumer> knownContentConsumers = addAdminRepoConsumer.getList();
417 Collections.sort( knownContentConsumers, AdminRepositoryConsumerComparator.getInstance() );
418 return knownContentConsumers;
420 catch ( RepositoryAdminException e )
422 throw new ArchivaRestServiceException( e.getMessage(), e );
427 public List<AdminRepositoryConsumer> getInvalidContentAdminRepositoryConsumers()
428 throws ArchivaRestServiceException
432 AddAdminRepoConsumerClosure addAdminRepoConsumer =
433 new AddAdminRepoConsumerClosure( archivaAdministration.getInvalidContentConsumers() );
434 CollectionUtils.forAllDo( repoConsumerUtil.getAvailableInvalidConsumers(), addAdminRepoConsumer );
435 List<AdminRepositoryConsumer> invalidContentConsumers = addAdminRepoConsumer.getList();
436 Collections.sort( invalidContentConsumers, AdminRepositoryConsumerComparator.getInstance() );
437 return invalidContentConsumers;
439 catch ( RepositoryAdminException e )
441 throw new ArchivaRestServiceException( e.getMessage(), e );