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(), e );
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(), null );
102 archivaAdministration.addLegacyArtifactPath( legacyArtifactPath, getAuditInformation() );
104 catch ( RepositoryAdminException e )
106 throw new ArchivaRestServiceException( e.getMessage(), e );
110 public Boolean deleteLegacyArtifactPath( String path )
111 throws ArchivaRestServiceException
115 archivaAdministration.deleteLegacyArtifactPath( path, getAuditInformation() );
118 catch ( RepositoryAdminException e )
120 throw new ArchivaRestServiceException( e.getMessage(), e );
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(), e );
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(), e );
153 public FileType getFileType( String fileTypeId )
154 throws ArchivaRestServiceException
158 return archivaAdministration.getFileType( fileTypeId );
160 catch ( RepositoryAdminException e )
162 throw new ArchivaRestServiceException( e.getMessage(), e );
166 public void addFileType( FileType fileType )
167 throws ArchivaRestServiceException
171 archivaAdministration.addFileType( fileType, getAuditInformation() );
173 catch ( RepositoryAdminException e )
175 throw new ArchivaRestServiceException( e.getMessage(), e );
179 public Boolean removeFileType( String fileTypeId )
180 throws ArchivaRestServiceException
184 archivaAdministration.removeFileType( fileTypeId, getAuditInformation() );
187 catch ( RepositoryAdminException e )
189 throw new ArchivaRestServiceException( e.getMessage(), e );
193 public Boolean enabledKnownContentConsumer( String knownContentConsumer )
194 throws ArchivaRestServiceException
198 archivaAdministration.addKnownContentConsumer( knownContentConsumer, getAuditInformation() );
201 catch ( RepositoryAdminException e )
203 throw new ArchivaRestServiceException( e.getMessage(), e );
207 public void enabledKnownContentConsumers( List<String> knownContentConsumers )
208 throws ArchivaRestServiceException
212 archivaAdministration.setKnownContentConsumers( knownContentConsumers, getAuditInformation() );
214 catch ( RepositoryAdminException e )
216 throw new ArchivaRestServiceException( e.getMessage(), e );
220 public Boolean disabledKnownContentConsumer( String knownContentConsumer )
221 throws ArchivaRestServiceException
225 archivaAdministration.removeKnownContentConsumer( knownContentConsumer, getAuditInformation() );
228 catch ( RepositoryAdminException e )
230 throw new ArchivaRestServiceException( e.getMessage(), e );
234 public Boolean enabledInvalidContentConsumer( String invalidContentConsumer )
235 throws ArchivaRestServiceException
239 archivaAdministration.addInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
242 catch ( RepositoryAdminException e )
244 throw new ArchivaRestServiceException( e.getMessage(), e );
248 public void enabledInvalidContentConsumers( List<String> invalidContentConsumers )
249 throws ArchivaRestServiceException
253 archivaAdministration.setInvalidContentConsumers( invalidContentConsumers, getAuditInformation() );
255 catch ( RepositoryAdminException e )
257 throw new ArchivaRestServiceException( e.getMessage(), e );
261 public Boolean disabledInvalidContentConsumer( String invalidContentConsumer )
262 throws ArchivaRestServiceException
266 archivaAdministration.removeInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
269 catch ( RepositoryAdminException e )
271 throw new ArchivaRestServiceException( e.getMessage(), e );
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(), e );
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(), e );
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(), e );
319 public OrganisationInformation getOrganisationInformation()
320 throws ArchivaRestServiceException
324 return archivaAdministration.getOrganisationInformation();
326 catch ( RepositoryAdminException e )
328 throw new ArchivaRestServiceException( e.getMessage(), e );
332 public void setOrganisationInformation( OrganisationInformation organisationInformation )
333 throws ArchivaRestServiceException
337 archivaAdministration.setOrganisationInformation( organisationInformation );
339 catch ( RepositoryAdminException e )
341 throw new ArchivaRestServiceException( e.getMessage(), e );
345 public Boolean registrationDisabled()
346 throws ArchivaRestServiceException
348 return getUiConfiguration().isDisableRegistration();
351 public UiConfiguration getUiConfiguration()
352 throws ArchivaRestServiceException
356 return archivaAdministration.getUiConfiguration();
358 catch ( RepositoryAdminException e )
360 throw new ArchivaRestServiceException( e.getMessage(), e );
364 public void setUiConfiguration( UiConfiguration uiConfiguration )
365 throws ArchivaRestServiceException
369 archivaAdministration.updateUiConfiguration( uiConfiguration );
371 catch ( RepositoryAdminException e )
373 throw new ArchivaRestServiceException( e.getMessage(), e );
377 public String getApplicationUrl()
378 throws ArchivaRestServiceException
382 return archivaAdministration.getUiConfiguration().getApplicationUrl();
384 catch ( RepositoryAdminException e )
386 throw new ArchivaRestServiceException( e.getMessage(), e );
390 public NetworkConfiguration getNetworkConfiguration()
391 throws ArchivaRestServiceException
395 return archivaAdministration.getNetworkConfiguration();
397 catch ( RepositoryAdminException e )
399 throw new ArchivaRestServiceException( e.getMessage(), e );
403 public void setNetworkConfiguration( NetworkConfiguration networkConfiguration )
404 throws ArchivaRestServiceException
408 archivaAdministration.setNetworkConfiguration( networkConfiguration );
410 catch ( RepositoryAdminException e )
412 throw new ArchivaRestServiceException( e.getMessage(), e );
416 public List<AdminRepositoryConsumer> getKnownContentAdminRepositoryConsumers()
417 throws ArchivaRestServiceException
421 AddAdminRepoConsumerClosure addAdminRepoConsumer =
422 new AddAdminRepoConsumerClosure( archivaAdministration.getKnownContentConsumers() );
423 CollectionUtils.forAllDo( repoConsumerUtil.getAvailableKnownConsumers(), addAdminRepoConsumer );
424 List<AdminRepositoryConsumer> knownContentConsumers = addAdminRepoConsumer.getList();
425 Collections.sort( knownContentConsumers, AdminRepositoryConsumerComparator.getInstance() );
426 return knownContentConsumers;
428 catch ( RepositoryAdminException e )
430 throw new ArchivaRestServiceException( e.getMessage(), e );
434 public List<AdminRepositoryConsumer> getInvalidContentAdminRepositoryConsumers()
435 throws ArchivaRestServiceException
439 AddAdminRepoConsumerClosure addAdminRepoConsumer =
440 new AddAdminRepoConsumerClosure( archivaAdministration.getInvalidContentConsumers() );
441 CollectionUtils.forAllDo( repoConsumerUtil.getAvailableInvalidConsumers(), addAdminRepoConsumer );
442 List<AdminRepositoryConsumer> invalidContentConsumers = addAdminRepoConsumer.getList();
443 Collections.sort( invalidContentConsumers, AdminRepositoryConsumerComparator.getInstance() );
444 return invalidContentConsumers;
446 catch ( RepositoryAdminException e )
448 throw new ArchivaRestServiceException( e.getMessage(), e );