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.BeanTransformer;
22 import net.sf.beanlib.provider.replicator.BeanReplicator;
23 import org.apache.archiva.admin.repository.RepositoryAdminException;
24 import org.apache.archiva.admin.repository.admin.ArchivaAdministration;
25 import org.apache.archiva.rest.api.model.FileType;
26 import org.apache.archiva.rest.api.model.LegacyArtifactPath;
27 import org.apache.archiva.rest.api.model.RepositoryScanning;
28 import org.apache.archiva.rest.api.services.ArchivaAdministrationService;
29 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
30 import org.springframework.stereotype.Service;
32 import javax.inject.Inject;
33 import java.util.ArrayList;
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() );
96 public RepositoryScanning getRepositoryScanning()
97 throws ArchivaRestServiceException
101 BeanTransformer beanTransformer = new BeanTransformer()
104 protected <T> T createToInstance( Object from, Class<T> toClass )
105 throws InstantiationException, IllegalAccessException, SecurityException, NoSuchMethodException
107 if ( from.getClass().equals( org.apache.maven.archiva.configuration.FileType.class ) )
109 return (T) new FileType();
111 return super.createToInstance( from, toClass );
114 BeanReplicator beanReplicator = new BeanReplicator( beanTransformer );
116 RepositoryScanning repositoryScanning =
117 beanReplicator.replicateBean( archivaAdministration.getRepositoryScanning(), RepositoryScanning.class );
119 return repositoryScanning;
121 catch ( RepositoryAdminException e )
123 throw new ArchivaRestServiceException( e.getMessage() );
127 public void updateRepositoryScanning( RepositoryScanning repositoryScanning )
128 throws ArchivaRestServiceException
132 archivaAdministration.updateRepositoryScanning( new BeanReplicator().replicateBean( getRepositoryScanning(),
133 org.apache.archiva.admin.repository.admin.RepositoryScanning.class ),
134 getAuditInformation() );
136 catch ( RepositoryAdminException e )
138 throw new ArchivaRestServiceException( e.getMessage() );
142 public Boolean addFileTypePattern( String fileTypeId, String pattern )
143 throws ArchivaRestServiceException
147 archivaAdministration.addFileTypePattern( fileTypeId, pattern, getAuditInformation() );
150 catch ( RepositoryAdminException e )
152 throw new ArchivaRestServiceException( e.getMessage() );
156 public Boolean removeFileTypePattern( String fileTypeId, String pattern )
157 throws ArchivaRestServiceException
161 archivaAdministration.removeFileTypePattern( fileTypeId, pattern, getAuditInformation() );
164 catch ( RepositoryAdminException e )
166 throw new ArchivaRestServiceException( e.getMessage() );
170 public FileType getFileType( String fileTypeId )
171 throws ArchivaRestServiceException
175 org.apache.archiva.admin.repository.admin.FileType fileType =
176 archivaAdministration.getFileType( fileTypeId );
177 if ( fileType == null )
181 return new BeanReplicator().replicateBean( fileType, FileType.class );
183 catch ( RepositoryAdminException e )
185 throw new ArchivaRestServiceException( e.getMessage() );
189 public void addFileType( FileType fileType )
190 throws ArchivaRestServiceException
194 archivaAdministration.addFileType( new BeanReplicator().replicateBean( fileType,
195 org.apache.archiva.admin.repository.admin.FileType.class ),
196 getAuditInformation() );
198 catch ( RepositoryAdminException e )
200 throw new ArchivaRestServiceException( e.getMessage() );
204 public Boolean removeFileType( String fileTypeId )
205 throws ArchivaRestServiceException
209 archivaAdministration.removeFileType( fileTypeId, getAuditInformation() );
212 catch ( RepositoryAdminException e )
214 throw new ArchivaRestServiceException( e.getMessage() );
218 public Boolean addKnownContentConsumer( String knownContentConsumer )
219 throws ArchivaRestServiceException
223 archivaAdministration.addKnownContentConsumer( knownContentConsumer, getAuditInformation() );
226 catch ( RepositoryAdminException e )
228 throw new ArchivaRestServiceException( e.getMessage() );
232 public void setKnownContentConsumers( List<String> knownContentConsumers )
233 throws ArchivaRestServiceException
237 archivaAdministration.setKnownContentConsumers( knownContentConsumers, getAuditInformation() );
239 catch ( RepositoryAdminException e )
241 throw new ArchivaRestServiceException( e.getMessage() );
245 public Boolean removeKnownContentConsumer( String knownContentConsumer )
246 throws ArchivaRestServiceException
250 archivaAdministration.removeKnownContentConsumer( knownContentConsumer, getAuditInformation() );
253 catch ( RepositoryAdminException e )
255 throw new ArchivaRestServiceException( e.getMessage() );
259 public Boolean addInvalidContentConsumer( String invalidContentConsumer )
260 throws ArchivaRestServiceException
264 archivaAdministration.addInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
267 catch ( RepositoryAdminException e )
269 throw new ArchivaRestServiceException( e.getMessage() );
273 public void setInvalidContentConsumers( List<String> invalidContentConsumers )
274 throws ArchivaRestServiceException
278 archivaAdministration.setInvalidContentConsumers( invalidContentConsumers, getAuditInformation() );
280 catch ( RepositoryAdminException e )
282 throw new ArchivaRestServiceException( e.getMessage() );
286 public Boolean removeInvalidContentConsumer( String invalidContentConsumer )
287 throws ArchivaRestServiceException
291 archivaAdministration.removeInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
294 catch ( RepositoryAdminException e )
296 throw new ArchivaRestServiceException( e.getMessage() );