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.model.ArtifactReference;
29 import org.apache.archiva.repository.ManagedRepositoryContent;
30 import org.apache.archiva.repository.scanner.RepositoryContentConsumers;
31 import org.apache.archiva.rest.api.model.AdminRepositoryConsumer;
32 import org.apache.archiva.rest.api.services.ArchivaAdministrationService;
33 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
34 import org.apache.archiva.rest.services.utils.AddAdminRepoConsumerClosure;
35 import org.apache.archiva.rest.services.utils.AdminRepositoryConsumerComparator;
36 import org.apache.commons.collections.CollectionUtils;
37 import org.apache.commons.lang.StringUtils;
38 import org.springframework.stereotype.Service;
40 import javax.inject.Inject;
41 import javax.inject.Named;
42 import javax.ws.rs.core.Response;
43 import java.util.ArrayList;
44 import java.util.Collections;
45 import java.util.List;
48 * @author Olivier Lamy
51 @Service ( "archivaAdministrationService#default" )
52 public class DefaultArchivaAdministrationService
53 extends AbstractRestService
54 implements ArchivaAdministrationService
57 private ArchivaAdministration archivaAdministration;
60 @Named ( value = "managedRepositoryContent#legacy" )
61 private ManagedRepositoryContent repositoryContent;
64 private RepositoryContentConsumers repoConsumerUtil;
67 public List<LegacyArtifactPath> getLegacyArtifactPaths()
68 throws ArchivaRestServiceException
72 return archivaAdministration.getLegacyArtifactPaths();
74 catch ( RepositoryAdminException e )
76 throw new ArchivaRestServiceException( e.getMessage(), e );
81 public void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
82 throws ArchivaRestServiceException
85 // Check the proposed Artifact matches the path
86 ArtifactReference artifact = new ArtifactReference();
88 artifact.setGroupId( legacyArtifactPath.getGroupId() );
89 artifact.setArtifactId( legacyArtifactPath.getArtifactId() );
90 artifact.setClassifier( legacyArtifactPath.getClassifier() );
91 artifact.setVersion( legacyArtifactPath.getVersion() );
92 artifact.setType( legacyArtifactPath.getType() );
93 String path = repositoryContent.toPath( artifact );
94 if ( !StringUtils.equals( path, legacyArtifactPath.getPath() ) )
96 throw new ArchivaRestServiceException(
97 "artifact path reference '" + legacyArtifactPath.getPath() + "' does not match the initial path: '"
98 + path + "'", Response.Status.BAD_REQUEST.getStatusCode(), null );
104 archivaAdministration.addLegacyArtifactPath( legacyArtifactPath, getAuditInformation() );
106 catch ( RepositoryAdminException e )
108 throw new ArchivaRestServiceException( e.getMessage(), e );
113 public Boolean deleteLegacyArtifactPath( String path )
114 throws ArchivaRestServiceException
118 archivaAdministration.deleteLegacyArtifactPath( path, getAuditInformation() );
121 catch ( RepositoryAdminException e )
123 throw new ArchivaRestServiceException( e.getMessage(), e );
129 public Boolean addFileTypePattern( String fileTypeId, String pattern )
130 throws ArchivaRestServiceException
134 archivaAdministration.addFileTypePattern( fileTypeId, pattern, getAuditInformation() );
137 catch ( RepositoryAdminException e )
139 throw new ArchivaRestServiceException( e.getMessage(), e );
144 public Boolean removeFileTypePattern( String fileTypeId, String pattern )
145 throws ArchivaRestServiceException
149 archivaAdministration.removeFileTypePattern( fileTypeId, pattern, getAuditInformation() );
152 catch ( RepositoryAdminException e )
154 throw new ArchivaRestServiceException( e.getMessage(), e );
159 public FileType getFileType( String fileTypeId )
160 throws ArchivaRestServiceException
164 return archivaAdministration.getFileType( fileTypeId );
166 catch ( RepositoryAdminException e )
168 throw new ArchivaRestServiceException( e.getMessage(), e );
173 public void addFileType( FileType fileType )
174 throws ArchivaRestServiceException
178 archivaAdministration.addFileType( fileType, getAuditInformation() );
180 catch ( RepositoryAdminException e )
182 throw new ArchivaRestServiceException( e.getMessage(), e );
187 public Boolean removeFileType( String fileTypeId )
188 throws ArchivaRestServiceException
192 archivaAdministration.removeFileType( fileTypeId, getAuditInformation() );
195 catch ( RepositoryAdminException e )
197 throw new ArchivaRestServiceException( e.getMessage(), e );
202 public Boolean enabledKnownContentConsumer( String knownContentConsumer )
203 throws ArchivaRestServiceException
207 archivaAdministration.addKnownContentConsumer( knownContentConsumer, getAuditInformation() );
210 catch ( RepositoryAdminException e )
212 throw new ArchivaRestServiceException( e.getMessage(), e );
217 public void enabledKnownContentConsumers( List<String> knownContentConsumers )
218 throws ArchivaRestServiceException
222 archivaAdministration.setKnownContentConsumers( knownContentConsumers, getAuditInformation() );
224 catch ( RepositoryAdminException e )
226 throw new ArchivaRestServiceException( e.getMessage(), e );
231 public Boolean disabledKnownContentConsumer( String knownContentConsumer )
232 throws ArchivaRestServiceException
236 archivaAdministration.removeKnownContentConsumer( knownContentConsumer, getAuditInformation() );
239 catch ( RepositoryAdminException e )
241 throw new ArchivaRestServiceException( e.getMessage(), e );
246 public Boolean enabledInvalidContentConsumer( String invalidContentConsumer )
247 throws ArchivaRestServiceException
251 archivaAdministration.addInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
254 catch ( RepositoryAdminException e )
256 throw new ArchivaRestServiceException( e.getMessage(), e );
261 public void enabledInvalidContentConsumers( List<String> invalidContentConsumers )
262 throws ArchivaRestServiceException
266 archivaAdministration.setInvalidContentConsumers( invalidContentConsumers, getAuditInformation() );
268 catch ( RepositoryAdminException e )
270 throw new ArchivaRestServiceException( e.getMessage(), e );
275 public Boolean disabledInvalidContentConsumer( String invalidContentConsumer )
276 throws ArchivaRestServiceException
280 archivaAdministration.removeInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
283 catch ( RepositoryAdminException e )
285 throw new ArchivaRestServiceException( e.getMessage(), e );
290 public List<FileType> getFileTypes()
291 throws ArchivaRestServiceException
295 List<FileType> modelfileTypes = archivaAdministration.getFileTypes();
296 if ( modelfileTypes == null || modelfileTypes.isEmpty() )
298 return Collections.emptyList();
300 return modelfileTypes;
302 catch ( RepositoryAdminException e )
304 throw new ArchivaRestServiceException( e.getMessage(), e );
309 public List<String> getKnownContentConsumers()
310 throws ArchivaRestServiceException
314 return new ArrayList<String>( archivaAdministration.getKnownContentConsumers() );
316 catch ( RepositoryAdminException e )
318 throw new ArchivaRestServiceException( e.getMessage(), e );
323 public List<String> getInvalidContentConsumers()
324 throws ArchivaRestServiceException
328 return new ArrayList<String>( archivaAdministration.getInvalidContentConsumers() );
330 catch ( RepositoryAdminException e )
332 throw new ArchivaRestServiceException( e.getMessage(), e );
337 public OrganisationInformation getOrganisationInformation()
338 throws ArchivaRestServiceException
342 return archivaAdministration.getOrganisationInformation();
344 catch ( RepositoryAdminException e )
346 throw new ArchivaRestServiceException( e.getMessage(), e );
351 public void setOrganisationInformation( OrganisationInformation organisationInformation )
352 throws ArchivaRestServiceException
356 archivaAdministration.setOrganisationInformation( organisationInformation );
358 catch ( RepositoryAdminException e )
360 throw new ArchivaRestServiceException( e.getMessage(), e );
365 public Boolean registrationDisabled()
366 throws ArchivaRestServiceException
368 return getUiConfiguration().isDisableRegistration();
372 public UiConfiguration getUiConfiguration()
373 throws ArchivaRestServiceException
377 return archivaAdministration.getUiConfiguration();
379 catch ( RepositoryAdminException e )
381 throw new ArchivaRestServiceException( e.getMessage(), e );
386 public void setUiConfiguration( UiConfiguration uiConfiguration )
387 throws ArchivaRestServiceException
392 // strip any trailing '/' at the end of the url so it won't affect url/link calculations in UI
393 uiConfiguration.setApplicationUrl(StringUtils.stripEnd(uiConfiguration.getApplicationUrl(), "/"));
395 archivaAdministration.updateUiConfiguration( uiConfiguration );
397 catch ( RepositoryAdminException e )
399 throw new ArchivaRestServiceException( e.getMessage(), e );
404 public String getApplicationUrl()
405 throws ArchivaRestServiceException
409 return archivaAdministration.getUiConfiguration().getApplicationUrl();
411 catch ( RepositoryAdminException e )
413 throw new ArchivaRestServiceException( e.getMessage(), e );
418 public NetworkConfiguration getNetworkConfiguration()
419 throws ArchivaRestServiceException
423 return archivaAdministration.getNetworkConfiguration();
425 catch ( RepositoryAdminException e )
427 throw new ArchivaRestServiceException( e.getMessage(), e );
432 public void setNetworkConfiguration( NetworkConfiguration networkConfiguration )
433 throws ArchivaRestServiceException
437 archivaAdministration.setNetworkConfiguration( networkConfiguration );
439 catch ( RepositoryAdminException e )
441 throw new ArchivaRestServiceException( e.getMessage(), e );
446 public List<AdminRepositoryConsumer> getKnownContentAdminRepositoryConsumers()
447 throws ArchivaRestServiceException
451 AddAdminRepoConsumerClosure addAdminRepoConsumer =
452 new AddAdminRepoConsumerClosure( archivaAdministration.getKnownContentConsumers() );
453 CollectionUtils.forAllDo( repoConsumerUtil.getAvailableKnownConsumers(), addAdminRepoConsumer );
454 List<AdminRepositoryConsumer> knownContentConsumers = addAdminRepoConsumer.getList();
455 Collections.sort( knownContentConsumers, AdminRepositoryConsumerComparator.getInstance() );
456 return knownContentConsumers;
458 catch ( RepositoryAdminException e )
460 throw new ArchivaRestServiceException( e.getMessage(), e );
465 public List<AdminRepositoryConsumer> getInvalidContentAdminRepositoryConsumers()
466 throws ArchivaRestServiceException
470 AddAdminRepoConsumerClosure addAdminRepoConsumer =
471 new AddAdminRepoConsumerClosure( archivaAdministration.getInvalidContentConsumers() );
472 CollectionUtils.forAllDo( repoConsumerUtil.getAvailableInvalidConsumers(), addAdminRepoConsumer );
473 List<AdminRepositoryConsumer> invalidContentConsumers = addAdminRepoConsumer.getList();
474 Collections.sort( invalidContentConsumers, AdminRepositoryConsumerComparator.getInstance() );
475 return invalidContentConsumers;
477 catch ( RepositoryAdminException e )
479 throw new ArchivaRestServiceException( e.getMessage(), e );