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.services.ArchivaAdministrationService;
27 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
28 import org.springframework.stereotype.Service;
30 import javax.inject.Inject;
31 import java.util.ArrayList;
32 import java.util.Collections;
33 import java.util.List;
36 * @author Olivier Lamy
39 @Service( "archivaAdministrationService#default" )
40 public class DefaultArchivaAdministrationService
41 extends AbstractRestService
42 implements ArchivaAdministrationService
45 private ArchivaAdministration archivaAdministration;
47 public List<LegacyArtifactPath> getLegacyArtifactPaths()
48 throws ArchivaRestServiceException
52 List<LegacyArtifactPath> legacyArtifactPaths = new ArrayList<LegacyArtifactPath>();
53 for ( org.apache.archiva.admin.repository.admin.LegacyArtifactPath legacyArtifactPath : archivaAdministration.getLegacyArtifactPaths() )
55 legacyArtifactPaths.add(
56 new BeanReplicator().replicateBean( legacyArtifactPath, LegacyArtifactPath.class ) );
58 return legacyArtifactPaths;
60 catch ( RepositoryAdminException e )
62 throw new ArchivaRestServiceException( e.getMessage() );
66 public void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
67 throws ArchivaRestServiceException
71 archivaAdministration.addLegacyArtifactPath( new BeanReplicator().replicateBean( legacyArtifactPath,
72 org.apache.archiva.admin.repository.admin.LegacyArtifactPath.class ),
73 getAuditInformation() );
75 catch ( RepositoryAdminException e )
77 throw new ArchivaRestServiceException( e.getMessage() );
81 public Boolean deleteLegacyArtifactPath( String path )
82 throws ArchivaRestServiceException
86 archivaAdministration.deleteLegacyArtifactPath( path, getAuditInformation() );
89 catch ( RepositoryAdminException e )
91 throw new ArchivaRestServiceException( e.getMessage() );
96 public Boolean addFileTypePattern( String fileTypeId, String pattern )
97 throws ArchivaRestServiceException
101 archivaAdministration.addFileTypePattern( fileTypeId, pattern, getAuditInformation() );
104 catch ( RepositoryAdminException e )
106 throw new ArchivaRestServiceException( e.getMessage() );
110 public Boolean removeFileTypePattern( String fileTypeId, String pattern )
111 throws ArchivaRestServiceException
115 archivaAdministration.removeFileTypePattern( fileTypeId, pattern, getAuditInformation() );
118 catch ( RepositoryAdminException e )
120 throw new ArchivaRestServiceException( e.getMessage() );
124 public FileType getFileType( String fileTypeId )
125 throws ArchivaRestServiceException
129 org.apache.archiva.admin.repository.admin.FileType fileType =
130 archivaAdministration.getFileType( fileTypeId );
131 if ( fileType == null )
135 return new BeanReplicator().replicateBean( fileType, FileType.class );
137 catch ( RepositoryAdminException e )
139 throw new ArchivaRestServiceException( e.getMessage() );
143 public void addFileType( FileType fileType )
144 throws ArchivaRestServiceException
148 archivaAdministration.addFileType( new BeanReplicator().replicateBean( fileType,
149 org.apache.archiva.admin.repository.admin.FileType.class ),
150 getAuditInformation() );
152 catch ( RepositoryAdminException e )
154 throw new ArchivaRestServiceException( e.getMessage() );
158 public Boolean removeFileType( String fileTypeId )
159 throws ArchivaRestServiceException
163 archivaAdministration.removeFileType( fileTypeId, getAuditInformation() );
166 catch ( RepositoryAdminException e )
168 throw new ArchivaRestServiceException( e.getMessage() );
172 public Boolean addKnownContentConsumer( String knownContentConsumer )
173 throws ArchivaRestServiceException
177 archivaAdministration.addKnownContentConsumer( knownContentConsumer, getAuditInformation() );
180 catch ( RepositoryAdminException e )
182 throw new ArchivaRestServiceException( e.getMessage() );
186 public void setKnownContentConsumers( List<String> knownContentConsumers )
187 throws ArchivaRestServiceException
191 archivaAdministration.setKnownContentConsumers( knownContentConsumers, getAuditInformation() );
193 catch ( RepositoryAdminException e )
195 throw new ArchivaRestServiceException( e.getMessage() );
199 public Boolean removeKnownContentConsumer( String knownContentConsumer )
200 throws ArchivaRestServiceException
204 archivaAdministration.removeKnownContentConsumer( knownContentConsumer, getAuditInformation() );
207 catch ( RepositoryAdminException e )
209 throw new ArchivaRestServiceException( e.getMessage() );
213 public Boolean addInvalidContentConsumer( String invalidContentConsumer )
214 throws ArchivaRestServiceException
218 archivaAdministration.addInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
221 catch ( RepositoryAdminException e )
223 throw new ArchivaRestServiceException( e.getMessage() );
227 public void setInvalidContentConsumers( List<String> invalidContentConsumers )
228 throws ArchivaRestServiceException
232 archivaAdministration.setInvalidContentConsumers( invalidContentConsumers, getAuditInformation() );
234 catch ( RepositoryAdminException e )
236 throw new ArchivaRestServiceException( e.getMessage() );
240 public Boolean removeInvalidContentConsumer( String invalidContentConsumer )
241 throws ArchivaRestServiceException
245 archivaAdministration.removeInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
248 catch ( RepositoryAdminException e )
250 throw new ArchivaRestServiceException( e.getMessage() );
254 public List<FileType> getFileTypes()
255 throws ArchivaRestServiceException
259 List<org.apache.archiva.admin.repository.admin.FileType> modelfileTypes =
260 archivaAdministration.getFileTypes();
261 if ( modelfileTypes == null || modelfileTypes.isEmpty() )
263 return Collections.emptyList();
265 List<FileType> fileTypes = new ArrayList<FileType>( modelfileTypes.size() );
266 for ( org.apache.archiva.admin.repository.admin.FileType fileType : modelfileTypes )
268 fileTypes.add( new BeanReplicator().replicateBean( fileType, FileType.class ) );
272 catch ( RepositoryAdminException e )
274 throw new ArchivaRestServiceException( e.getMessage() );
278 public List<String> getKnownContentConsumers()
279 throws ArchivaRestServiceException
283 return new ArrayList<String>( archivaAdministration.getKnownContentConsumers() );
285 catch ( RepositoryAdminException e )
287 throw new ArchivaRestServiceException( e.getMessage() );
291 public List<String> getInvalidContentConsumers()
292 throws ArchivaRestServiceException
296 return new ArrayList<String>( archivaAdministration.getInvalidContentConsumers() );
298 catch ( RepositoryAdminException e )
300 throw new ArchivaRestServiceException( e.getMessage() );