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 net.sf.beanlib.provider.replicator.BeanReplicator;
22 import org.apache.archiva.admin.repository.RepositoryAdminException;
23 import org.apache.archiva.admin.repository.admin.ArchivaAdministration;
24 import org.apache.archiva.rest.api.model.FileType;
25 import org.apache.archiva.rest.api.model.LegacyArtifactPath;
26 import org.apache.archiva.rest.api.model.OrganisationInformation;
27 import org.apache.archiva.rest.api.services.ArchivaAdministrationService;
28 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
29 import org.springframework.stereotype.Service;
31 import javax.inject.Inject;
32 import java.util.ArrayList;
33 import java.util.Collections;
34 import java.util.List;
37 * @author Olivier Lamy
40 @Service( "archivaAdministrationService#default" )
41 public class DefaultArchivaAdministrationService
42 extends AbstractRestService
43 implements ArchivaAdministrationService
46 private ArchivaAdministration archivaAdministration;
48 public List<LegacyArtifactPath> getLegacyArtifactPaths()
49 throws ArchivaRestServiceException
53 List<LegacyArtifactPath> legacyArtifactPaths = new ArrayList<LegacyArtifactPath>();
54 for ( org.apache.archiva.admin.repository.admin.LegacyArtifactPath legacyArtifactPath : archivaAdministration.getLegacyArtifactPaths() )
56 legacyArtifactPaths.add(
57 new BeanReplicator().replicateBean( legacyArtifactPath, LegacyArtifactPath.class ) );
59 return legacyArtifactPaths;
61 catch ( RepositoryAdminException e )
63 throw new ArchivaRestServiceException( e.getMessage() );
67 public void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
68 throws ArchivaRestServiceException
72 archivaAdministration.addLegacyArtifactPath( new BeanReplicator().replicateBean( legacyArtifactPath,
73 org.apache.archiva.admin.repository.admin.LegacyArtifactPath.class ),
74 getAuditInformation() );
76 catch ( RepositoryAdminException e )
78 throw new ArchivaRestServiceException( e.getMessage() );
82 public Boolean deleteLegacyArtifactPath( String path )
83 throws ArchivaRestServiceException
87 archivaAdministration.deleteLegacyArtifactPath( path, getAuditInformation() );
90 catch ( RepositoryAdminException e )
92 throw new ArchivaRestServiceException( e.getMessage() );
97 public Boolean addFileTypePattern( String fileTypeId, String pattern )
98 throws ArchivaRestServiceException
102 archivaAdministration.addFileTypePattern( fileTypeId, pattern, getAuditInformation() );
105 catch ( RepositoryAdminException e )
107 throw new ArchivaRestServiceException( e.getMessage() );
111 public Boolean removeFileTypePattern( String fileTypeId, String pattern )
112 throws ArchivaRestServiceException
116 archivaAdministration.removeFileTypePattern( fileTypeId, pattern, getAuditInformation() );
119 catch ( RepositoryAdminException e )
121 throw new ArchivaRestServiceException( e.getMessage() );
125 public FileType getFileType( String fileTypeId )
126 throws ArchivaRestServiceException
130 org.apache.archiva.admin.repository.admin.FileType fileType =
131 archivaAdministration.getFileType( fileTypeId );
132 if ( fileType == null )
136 return new BeanReplicator().replicateBean( fileType, FileType.class );
138 catch ( RepositoryAdminException e )
140 throw new ArchivaRestServiceException( e.getMessage() );
144 public void addFileType( FileType fileType )
145 throws ArchivaRestServiceException
149 archivaAdministration.addFileType( new BeanReplicator().replicateBean( fileType,
150 org.apache.archiva.admin.repository.admin.FileType.class ),
151 getAuditInformation() );
153 catch ( RepositoryAdminException e )
155 throw new ArchivaRestServiceException( e.getMessage() );
159 public Boolean removeFileType( String fileTypeId )
160 throws ArchivaRestServiceException
164 archivaAdministration.removeFileType( fileTypeId, getAuditInformation() );
167 catch ( RepositoryAdminException e )
169 throw new ArchivaRestServiceException( e.getMessage() );
173 public Boolean addKnownContentConsumer( String knownContentConsumer )
174 throws ArchivaRestServiceException
178 archivaAdministration.addKnownContentConsumer( knownContentConsumer, getAuditInformation() );
181 catch ( RepositoryAdminException e )
183 throw new ArchivaRestServiceException( e.getMessage() );
187 public void setKnownContentConsumers( List<String> knownContentConsumers )
188 throws ArchivaRestServiceException
192 archivaAdministration.setKnownContentConsumers( knownContentConsumers, getAuditInformation() );
194 catch ( RepositoryAdminException e )
196 throw new ArchivaRestServiceException( e.getMessage() );
200 public Boolean removeKnownContentConsumer( String knownContentConsumer )
201 throws ArchivaRestServiceException
205 archivaAdministration.removeKnownContentConsumer( knownContentConsumer, getAuditInformation() );
208 catch ( RepositoryAdminException e )
210 throw new ArchivaRestServiceException( e.getMessage() );
214 public Boolean addInvalidContentConsumer( String invalidContentConsumer )
215 throws ArchivaRestServiceException
219 archivaAdministration.addInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
222 catch ( RepositoryAdminException e )
224 throw new ArchivaRestServiceException( e.getMessage() );
228 public void setInvalidContentConsumers( List<String> invalidContentConsumers )
229 throws ArchivaRestServiceException
233 archivaAdministration.setInvalidContentConsumers( invalidContentConsumers, getAuditInformation() );
235 catch ( RepositoryAdminException e )
237 throw new ArchivaRestServiceException( e.getMessage() );
241 public Boolean removeInvalidContentConsumer( String invalidContentConsumer )
242 throws ArchivaRestServiceException
246 archivaAdministration.removeInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
249 catch ( RepositoryAdminException e )
251 throw new ArchivaRestServiceException( e.getMessage() );
255 public List<FileType> getFileTypes()
256 throws ArchivaRestServiceException
260 List<org.apache.archiva.admin.repository.admin.FileType> modelfileTypes =
261 archivaAdministration.getFileTypes();
262 if ( modelfileTypes == null || modelfileTypes.isEmpty() )
264 return Collections.emptyList();
266 List<FileType> fileTypes = new ArrayList<FileType>( modelfileTypes.size() );
267 for ( org.apache.archiva.admin.repository.admin.FileType fileType : modelfileTypes )
269 fileTypes.add( new BeanReplicator().replicateBean( fileType, FileType.class ) );
273 catch ( RepositoryAdminException e )
275 throw new ArchivaRestServiceException( e.getMessage() );
279 public List<String> getKnownContentConsumers()
280 throws ArchivaRestServiceException
284 return new ArrayList<String>( archivaAdministration.getKnownContentConsumers() );
286 catch ( RepositoryAdminException e )
288 throw new ArchivaRestServiceException( e.getMessage() );
292 public List<String> getInvalidContentConsumers()
293 throws ArchivaRestServiceException
297 return new ArrayList<String>( archivaAdministration.getInvalidContentConsumers() );
299 catch ( RepositoryAdminException e )
301 throw new ArchivaRestServiceException( e.getMessage() );
305 public OrganisationInformation getOrganisationInformation()
306 throws ArchivaRestServiceException
310 org.apache.archiva.admin.repository.admin.OrganisationInformation organisationInformation =
311 archivaAdministration.getOrganisationInformation();
313 return organisationInformation == null
315 : new BeanReplicator().replicateBean( organisationInformation, OrganisationInformation.class );
317 catch ( RepositoryAdminException e )
319 throw new ArchivaRestServiceException( e.getMessage() );
323 public void setOrganisationInformation( OrganisationInformation organisationInformation )
324 throws ArchivaRestServiceException
328 if ( organisationInformation == null )
330 archivaAdministration.setOrganisationInformation( null );
334 archivaAdministration.setOrganisationInformation(
335 new BeanReplicator().replicateBean( organisationInformation,
336 org.apache.archiva.admin.repository.admin.OrganisationInformation.class ) );
339 catch ( RepositoryAdminException e )
341 throw new ArchivaRestServiceException( e.getMessage() );