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.rest.api.services.ArchivaAdministrationService;
31 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
32 import org.apache.commons.lang.StringUtils;
33 import org.springframework.stereotype.Service;
35 import javax.inject.Inject;
36 import javax.inject.Named;
37 import javax.ws.rs.core.Response;
38 import java.util.ArrayList;
39 import java.util.Collections;
40 import java.util.List;
43 * @author Olivier Lamy
46 @Service( "archivaAdministrationService#default" )
47 public class DefaultArchivaAdministrationService
48 extends AbstractRestService
49 implements ArchivaAdministrationService
52 private ArchivaAdministration archivaAdministration;
55 @Named( value = "managedRepositoryContent#legacy" )
56 private ManagedRepositoryContent repositoryContent;
58 public List<LegacyArtifactPath> getLegacyArtifactPaths()
59 throws ArchivaRestServiceException
63 return archivaAdministration.getLegacyArtifactPaths();
65 catch ( RepositoryAdminException e )
67 throw new ArchivaRestServiceException( e.getMessage() );
71 public void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
72 throws ArchivaRestServiceException
75 // Check the proposed Artifact matches the path
76 ArtifactReference artifact = new ArtifactReference();
78 artifact.setGroupId( legacyArtifactPath.getGroupId() );
79 artifact.setArtifactId( legacyArtifactPath.getArtifactId() );
80 artifact.setClassifier( legacyArtifactPath.getClassifier() );
81 artifact.setVersion( legacyArtifactPath.getVersion() );
82 artifact.setType( legacyArtifactPath.getType() );
83 String path = repositoryContent.toPath( artifact );
84 if ( !StringUtils.equals( path, legacyArtifactPath.getPath() ) )
86 throw new ArchivaRestServiceException(
87 "artifact path reference '" + legacyArtifactPath.getPath() + "' does not match the initial path: '"
88 + path + "'", Response.Status.BAD_REQUEST.getStatusCode() );
94 archivaAdministration.addLegacyArtifactPath( legacyArtifactPath, getAuditInformation() );
96 catch ( RepositoryAdminException e )
98 throw new ArchivaRestServiceException( e.getMessage() );
102 public Boolean deleteLegacyArtifactPath( String path )
103 throws ArchivaRestServiceException
107 archivaAdministration.deleteLegacyArtifactPath( path, getAuditInformation() );
110 catch ( RepositoryAdminException e )
112 throw new ArchivaRestServiceException( e.getMessage() );
117 public Boolean addFileTypePattern( String fileTypeId, String pattern )
118 throws ArchivaRestServiceException
122 archivaAdministration.addFileTypePattern( fileTypeId, pattern, getAuditInformation() );
125 catch ( RepositoryAdminException e )
127 throw new ArchivaRestServiceException( e.getMessage() );
131 public Boolean removeFileTypePattern( String fileTypeId, String pattern )
132 throws ArchivaRestServiceException
136 archivaAdministration.removeFileTypePattern( fileTypeId, pattern, getAuditInformation() );
139 catch ( RepositoryAdminException e )
141 throw new ArchivaRestServiceException( e.getMessage() );
145 public FileType getFileType( String fileTypeId )
146 throws ArchivaRestServiceException
150 return archivaAdministration.getFileType( fileTypeId );
152 catch ( RepositoryAdminException e )
154 throw new ArchivaRestServiceException( e.getMessage() );
158 public void addFileType( FileType fileType )
159 throws ArchivaRestServiceException
163 archivaAdministration.addFileType( fileType, getAuditInformation() );
165 catch ( RepositoryAdminException e )
167 throw new ArchivaRestServiceException( e.getMessage() );
171 public Boolean removeFileType( String fileTypeId )
172 throws ArchivaRestServiceException
176 archivaAdministration.removeFileType( fileTypeId, getAuditInformation() );
179 catch ( RepositoryAdminException e )
181 throw new ArchivaRestServiceException( e.getMessage() );
185 public Boolean addKnownContentConsumer( String knownContentConsumer )
186 throws ArchivaRestServiceException
190 archivaAdministration.addKnownContentConsumer( knownContentConsumer, getAuditInformation() );
193 catch ( RepositoryAdminException e )
195 throw new ArchivaRestServiceException( e.getMessage() );
199 public void setKnownContentConsumers( List<String> knownContentConsumers )
200 throws ArchivaRestServiceException
204 archivaAdministration.setKnownContentConsumers( knownContentConsumers, getAuditInformation() );
206 catch ( RepositoryAdminException e )
208 throw new ArchivaRestServiceException( e.getMessage() );
212 public Boolean removeKnownContentConsumer( String knownContentConsumer )
213 throws ArchivaRestServiceException
217 archivaAdministration.removeKnownContentConsumer( knownContentConsumer, getAuditInformation() );
220 catch ( RepositoryAdminException e )
222 throw new ArchivaRestServiceException( e.getMessage() );
226 public Boolean addInvalidContentConsumer( String invalidContentConsumer )
227 throws ArchivaRestServiceException
231 archivaAdministration.addInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
234 catch ( RepositoryAdminException e )
236 throw new ArchivaRestServiceException( e.getMessage() );
240 public void setInvalidContentConsumers( List<String> invalidContentConsumers )
241 throws ArchivaRestServiceException
245 archivaAdministration.setInvalidContentConsumers( invalidContentConsumers, getAuditInformation() );
247 catch ( RepositoryAdminException e )
249 throw new ArchivaRestServiceException( e.getMessage() );
253 public Boolean removeInvalidContentConsumer( String invalidContentConsumer )
254 throws ArchivaRestServiceException
258 archivaAdministration.removeInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
261 catch ( RepositoryAdminException e )
263 throw new ArchivaRestServiceException( e.getMessage() );
267 public List<FileType> getFileTypes()
268 throws ArchivaRestServiceException
272 List<FileType> modelfileTypes = archivaAdministration.getFileTypes();
273 if ( modelfileTypes == null || modelfileTypes.isEmpty() )
275 return Collections.emptyList();
277 return modelfileTypes;
279 catch ( RepositoryAdminException e )
281 throw new ArchivaRestServiceException( e.getMessage() );
285 public List<String> getKnownContentConsumers()
286 throws ArchivaRestServiceException
290 return new ArrayList<String>( archivaAdministration.getKnownContentConsumers() );
292 catch ( RepositoryAdminException e )
294 throw new ArchivaRestServiceException( e.getMessage() );
298 public List<String> getInvalidContentConsumers()
299 throws ArchivaRestServiceException
303 return new ArrayList<String>( archivaAdministration.getInvalidContentConsumers() );
305 catch ( RepositoryAdminException e )
307 throw new ArchivaRestServiceException( e.getMessage() );
311 public OrganisationInformation getOrganisationInformation()
312 throws ArchivaRestServiceException
316 return archivaAdministration.getOrganisationInformation();
318 catch ( RepositoryAdminException e )
320 throw new ArchivaRestServiceException( e.getMessage() );
324 public void setOrganisationInformation( OrganisationInformation organisationInformation )
325 throws ArchivaRestServiceException
329 archivaAdministration.setOrganisationInformation( organisationInformation );
331 catch ( RepositoryAdminException e )
333 throw new ArchivaRestServiceException( e.getMessage() );
338 public UiConfiguration getUiConfiguration()
339 throws ArchivaRestServiceException
343 return archivaAdministration.getUiConfiguration();
345 catch ( RepositoryAdminException e )
347 throw new ArchivaRestServiceException( e.getMessage() );
351 public void setUiConfiguration( UiConfiguration uiConfiguration )
352 throws ArchivaRestServiceException
356 archivaAdministration.updateUiConfiguration( uiConfiguration );
358 catch ( RepositoryAdminException e )
360 throw new ArchivaRestServiceException( e.getMessage() );
364 public NetworkConfiguration getNetworkConfiguration()
365 throws ArchivaRestServiceException
369 return archivaAdministration.getNetworkConfiguration();
371 catch ( RepositoryAdminException e )
373 throw new ArchivaRestServiceException( e.getMessage() );
377 public void setNetworkConfiguration( NetworkConfiguration networkConfiguration )
378 throws ArchivaRestServiceException
382 archivaAdministration.setNetworkConfiguration( networkConfiguration );
384 catch ( RepositoryAdminException e )
386 throw new ArchivaRestServiceException( e.getMessage() );