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;
66 public List<LegacyArtifactPath> getLegacyArtifactPaths()
67 throws ArchivaRestServiceException
71 return archivaAdministration.getLegacyArtifactPaths();
73 catch ( RepositoryAdminException e )
75 throw new ArchivaRestServiceException( e.getMessage() );
79 public void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
80 throws ArchivaRestServiceException
83 // Check the proposed Artifact matches the path
84 ArtifactReference artifact = new ArtifactReference();
86 artifact.setGroupId( legacyArtifactPath.getGroupId() );
87 artifact.setArtifactId( legacyArtifactPath.getArtifactId() );
88 artifact.setClassifier( legacyArtifactPath.getClassifier() );
89 artifact.setVersion( legacyArtifactPath.getVersion() );
90 artifact.setType( legacyArtifactPath.getType() );
91 String path = repositoryContent.toPath( artifact );
92 if ( !StringUtils.equals( path, legacyArtifactPath.getPath() ) )
94 throw new ArchivaRestServiceException(
95 "artifact path reference '" + legacyArtifactPath.getPath() + "' does not match the initial path: '"
96 + path + "'", Response.Status.BAD_REQUEST.getStatusCode() );
102 archivaAdministration.addLegacyArtifactPath( legacyArtifactPath, getAuditInformation() );
104 catch ( RepositoryAdminException e )
106 throw new ArchivaRestServiceException( e.getMessage() );
110 public Boolean deleteLegacyArtifactPath( String path )
111 throws ArchivaRestServiceException
115 archivaAdministration.deleteLegacyArtifactPath( path, getAuditInformation() );
118 catch ( RepositoryAdminException e )
120 throw new ArchivaRestServiceException( e.getMessage() );
125 public Boolean addFileTypePattern( String fileTypeId, String pattern )
126 throws ArchivaRestServiceException
130 archivaAdministration.addFileTypePattern( fileTypeId, pattern, getAuditInformation() );
133 catch ( RepositoryAdminException e )
135 throw new ArchivaRestServiceException( e.getMessage() );
139 public Boolean removeFileTypePattern( String fileTypeId, String pattern )
140 throws ArchivaRestServiceException
144 archivaAdministration.removeFileTypePattern( fileTypeId, pattern, getAuditInformation() );
147 catch ( RepositoryAdminException e )
149 throw new ArchivaRestServiceException( e.getMessage() );
153 public FileType getFileType( String fileTypeId )
154 throws ArchivaRestServiceException
158 return archivaAdministration.getFileType( fileTypeId );
160 catch ( RepositoryAdminException e )
162 throw new ArchivaRestServiceException( e.getMessage() );
166 public void addFileType( FileType fileType )
167 throws ArchivaRestServiceException
171 archivaAdministration.addFileType( fileType, getAuditInformation() );
173 catch ( RepositoryAdminException e )
175 throw new ArchivaRestServiceException( e.getMessage() );
179 public Boolean removeFileType( String fileTypeId )
180 throws ArchivaRestServiceException
184 archivaAdministration.removeFileType( fileTypeId, getAuditInformation() );
187 catch ( RepositoryAdminException e )
189 throw new ArchivaRestServiceException( e.getMessage() );
193 public Boolean addKnownContentConsumer( String knownContentConsumer )
194 throws ArchivaRestServiceException
198 archivaAdministration.addKnownContentConsumer( knownContentConsumer, getAuditInformation() );
201 catch ( RepositoryAdminException e )
203 throw new ArchivaRestServiceException( e.getMessage() );
207 public void setKnownContentConsumers( List<String> knownContentConsumers )
208 throws ArchivaRestServiceException
212 archivaAdministration.setKnownContentConsumers( knownContentConsumers, getAuditInformation() );
214 catch ( RepositoryAdminException e )
216 throw new ArchivaRestServiceException( e.getMessage() );
220 public Boolean removeKnownContentConsumer( String knownContentConsumer )
221 throws ArchivaRestServiceException
225 archivaAdministration.removeKnownContentConsumer( knownContentConsumer, getAuditInformation() );
228 catch ( RepositoryAdminException e )
230 throw new ArchivaRestServiceException( e.getMessage() );
234 public Boolean addInvalidContentConsumer( String invalidContentConsumer )
235 throws ArchivaRestServiceException
239 archivaAdministration.addInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
242 catch ( RepositoryAdminException e )
244 throw new ArchivaRestServiceException( e.getMessage() );
248 public void setInvalidContentConsumers( List<String> invalidContentConsumers )
249 throws ArchivaRestServiceException
253 archivaAdministration.setInvalidContentConsumers( invalidContentConsumers, getAuditInformation() );
255 catch ( RepositoryAdminException e )
257 throw new ArchivaRestServiceException( e.getMessage() );
261 public Boolean removeInvalidContentConsumer( String invalidContentConsumer )
262 throws ArchivaRestServiceException
266 archivaAdministration.removeInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
269 catch ( RepositoryAdminException e )
271 throw new ArchivaRestServiceException( e.getMessage() );
275 public List<FileType> getFileTypes()
276 throws ArchivaRestServiceException
280 List<FileType> modelfileTypes = archivaAdministration.getFileTypes();
281 if ( modelfileTypes == null || modelfileTypes.isEmpty() )
283 return Collections.emptyList();
285 return modelfileTypes;
287 catch ( RepositoryAdminException e )
289 throw new ArchivaRestServiceException( e.getMessage() );
293 public List<String> getKnownContentConsumers()
294 throws ArchivaRestServiceException
298 return new ArrayList<String>( archivaAdministration.getKnownContentConsumers() );
300 catch ( RepositoryAdminException e )
302 throw new ArchivaRestServiceException( e.getMessage() );
306 public List<String> getInvalidContentConsumers()
307 throws ArchivaRestServiceException
311 return new ArrayList<String>( archivaAdministration.getInvalidContentConsumers() );
313 catch ( RepositoryAdminException e )
315 throw new ArchivaRestServiceException( e.getMessage() );
319 public OrganisationInformation getOrganisationInformation()
320 throws ArchivaRestServiceException
324 return archivaAdministration.getOrganisationInformation();
326 catch ( RepositoryAdminException e )
328 throw new ArchivaRestServiceException( e.getMessage() );
332 public void setOrganisationInformation( OrganisationInformation organisationInformation )
333 throws ArchivaRestServiceException
337 archivaAdministration.setOrganisationInformation( organisationInformation );
339 catch ( RepositoryAdminException e )
341 throw new ArchivaRestServiceException( e.getMessage() );
346 public UiConfiguration getUiConfiguration()
347 throws ArchivaRestServiceException
351 return archivaAdministration.getUiConfiguration();
353 catch ( RepositoryAdminException e )
355 throw new ArchivaRestServiceException( e.getMessage() );
359 public void setUiConfiguration( UiConfiguration uiConfiguration )
360 throws ArchivaRestServiceException
364 archivaAdministration.updateUiConfiguration( uiConfiguration );
366 catch ( RepositoryAdminException e )
368 throw new ArchivaRestServiceException( e.getMessage() );
372 public NetworkConfiguration getNetworkConfiguration()
373 throws ArchivaRestServiceException
377 return archivaAdministration.getNetworkConfiguration();
379 catch ( RepositoryAdminException e )
381 throw new ArchivaRestServiceException( e.getMessage() );
385 public void setNetworkConfiguration( NetworkConfiguration networkConfiguration )
386 throws ArchivaRestServiceException
390 archivaAdministration.setNetworkConfiguration( networkConfiguration );
392 catch ( RepositoryAdminException e )
394 throw new ArchivaRestServiceException( e.getMessage() );
398 public List<AdminRepositoryConsumer> getKnownContentAdminRepositoryConsumers()
399 throws ArchivaRestServiceException
403 AddAdminRepoConsumerClosure addAdminRepoConsumer =
404 new AddAdminRepoConsumerClosure( archivaAdministration.getKnownContentConsumers() );
405 CollectionUtils.forAllDo( repoConsumerUtil.getAvailableKnownConsumers(), addAdminRepoConsumer );
406 List<AdminRepositoryConsumer> knownContentConsumers = addAdminRepoConsumer.getList();
407 Collections.sort( knownContentConsumers, AdminRepositoryConsumerComparator.getInstance() );
408 return knownContentConsumers;
410 catch ( RepositoryAdminException e )
412 throw new ArchivaRestServiceException( e.getMessage() );
416 public List<AdminRepositoryConsumer> getInvalidContentAdminRepositoryConsumers()
417 throws ArchivaRestServiceException
421 AddAdminRepoConsumerClosure addAdminRepoConsumer =
422 new AddAdminRepoConsumerClosure( archivaAdministration.getInvalidContentConsumers() );
423 CollectionUtils.forAllDo( repoConsumerUtil.getAvailableInvalidConsumers(), addAdminRepoConsumer );
424 List<AdminRepositoryConsumer> invalidContentConsumers = addAdminRepoConsumer.getList();
425 Collections.sort( invalidContentConsumers, AdminRepositoryConsumerComparator.getInstance() );
426 return invalidContentConsumers;
428 catch ( RepositoryAdminException e )
430 throw new ArchivaRestServiceException( e.getMessage() );