]> source.dussan.org Git - archiva.git/blob
6aa60ea1995661014dc2b470a80ae997b67e2688
[archiva.git] /
1 package org.apache.archiva.rest.services;
2 /*
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
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
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
18  * under the License.
19  */
20
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;
31
32 import javax.inject.Inject;
33 import java.util.ArrayList;
34 import java.util.List;
35
36 /**
37  * @author Olivier Lamy
38  * @since 1.4
39  */
40 @Service( "archivaAdministrationService#default" )
41 public class DefaultArchivaAdministrationService
42     extends AbstractRestService
43     implements ArchivaAdministrationService
44 {
45     @Inject
46     private ArchivaAdministration archivaAdministration;
47
48     public List<LegacyArtifactPath> getLegacyArtifactPaths()
49         throws ArchivaRestServiceException
50     {
51         try
52         {
53             List<LegacyArtifactPath> legacyArtifactPaths = new ArrayList<LegacyArtifactPath>();
54             for ( org.apache.archiva.admin.repository.admin.LegacyArtifactPath legacyArtifactPath : archivaAdministration.getLegacyArtifactPaths() )
55             {
56                 legacyArtifactPaths.add(
57                     new BeanReplicator().replicateBean( legacyArtifactPath, LegacyArtifactPath.class ) );
58             }
59             return legacyArtifactPaths;
60         }
61         catch ( RepositoryAdminException e )
62         {
63             throw new ArchivaRestServiceException( e.getMessage() );
64         }
65     }
66
67     public void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
68         throws ArchivaRestServiceException
69     {
70         try
71         {
72             archivaAdministration.addLegacyArtifactPath( new BeanReplicator().replicateBean( legacyArtifactPath,
73                                                                                              org.apache.archiva.admin.repository.admin.LegacyArtifactPath.class ),
74                                                          getAuditInformation() );
75         }
76         catch ( RepositoryAdminException e )
77         {
78             throw new ArchivaRestServiceException( e.getMessage() );
79         }
80     }
81
82     public Boolean deleteLegacyArtifactPath( String path )
83         throws ArchivaRestServiceException
84     {
85         try
86         {
87             archivaAdministration.deleteLegacyArtifactPath( path, getAuditInformation() );
88             return Boolean.TRUE;
89         }
90         catch ( RepositoryAdminException e )
91         {
92             throw new ArchivaRestServiceException( e.getMessage() );
93         }
94     }
95
96     public RepositoryScanning getRepositoryScanning()
97         throws ArchivaRestServiceException
98     {
99         try
100         {
101             BeanTransformer beanTransformer = new BeanTransformer()
102             {
103                 @Override
104                 protected <T> T createToInstance( Object from, Class<T> toClass )
105                     throws InstantiationException, IllegalAccessException, SecurityException, NoSuchMethodException
106                 {
107                     if ( from.getClass().equals( org.apache.maven.archiva.configuration.FileType.class ) )
108                     {
109                         return (T) new FileType();
110                     }
111                     return super.createToInstance( from, toClass );
112                 }
113             };
114             BeanReplicator beanReplicator = new BeanReplicator( beanTransformer );
115
116             RepositoryScanning repositoryScanning =
117                 beanReplicator.replicateBean( archivaAdministration.getRepositoryScanning(), RepositoryScanning.class );
118
119             return repositoryScanning;
120         }
121         catch ( RepositoryAdminException e )
122         {
123             throw new ArchivaRestServiceException( e.getMessage() );
124         }
125     }
126
127     public void updateRepositoryScanning( RepositoryScanning repositoryScanning )
128         throws ArchivaRestServiceException
129     {
130         try
131         {
132             archivaAdministration.updateRepositoryScanning( new BeanReplicator().replicateBean( getRepositoryScanning(),
133                                                                                                 org.apache.archiva.admin.repository.admin.RepositoryScanning.class ),
134                                                             getAuditInformation() );
135         }
136         catch ( RepositoryAdminException e )
137         {
138             throw new ArchivaRestServiceException( e.getMessage() );
139         }
140     }
141
142     public Boolean addFileTypePattern( String fileTypeId, String pattern )
143         throws ArchivaRestServiceException
144     {
145         try
146         {
147             archivaAdministration.addFileTypePattern( fileTypeId, pattern, getAuditInformation() );
148             return Boolean.TRUE;
149         }
150         catch ( RepositoryAdminException e )
151         {
152             throw new ArchivaRestServiceException( e.getMessage() );
153         }
154     }
155
156     public Boolean removeFileTypePattern( String fileTypeId, String pattern )
157         throws ArchivaRestServiceException
158     {
159         try
160         {
161             archivaAdministration.removeFileTypePattern( fileTypeId, pattern, getAuditInformation() );
162             return Boolean.TRUE;
163         }
164         catch ( RepositoryAdminException e )
165         {
166             throw new ArchivaRestServiceException( e.getMessage() );
167         }
168     }
169
170     public FileType getFileType( String fileTypeId )
171         throws ArchivaRestServiceException
172     {
173         try
174         {
175             org.apache.archiva.admin.repository.admin.FileType fileType =
176                 archivaAdministration.getFileType( fileTypeId );
177             if ( fileType == null )
178             {
179                 return null;
180             }
181             return new BeanReplicator().replicateBean( fileType, FileType.class );
182         }
183         catch ( RepositoryAdminException e )
184         {
185             throw new ArchivaRestServiceException( e.getMessage() );
186         }
187     }
188
189     public void addFileType( FileType fileType )
190         throws ArchivaRestServiceException
191     {
192         try
193         {
194             archivaAdministration.addFileType( new BeanReplicator().replicateBean( fileType,
195                                                                                    org.apache.archiva.admin.repository.admin.FileType.class ),
196                                                getAuditInformation() );
197         }
198         catch ( RepositoryAdminException e )
199         {
200             throw new ArchivaRestServiceException( e.getMessage() );
201         }
202     }
203
204     public Boolean removeFileType( String fileTypeId )
205         throws ArchivaRestServiceException
206     {
207         try
208         {
209             archivaAdministration.removeFileType( fileTypeId, getAuditInformation() );
210             return Boolean.TRUE;
211         }
212         catch ( RepositoryAdminException e )
213         {
214             throw new ArchivaRestServiceException( e.getMessage() );
215         }
216     }
217
218     public Boolean addKnownContentConsumer( String knownContentConsumer )
219         throws ArchivaRestServiceException
220     {
221         try
222         {
223             archivaAdministration.addKnownContentConsumer( knownContentConsumer, getAuditInformation() );
224             return Boolean.TRUE;
225         }
226         catch ( RepositoryAdminException e )
227         {
228             throw new ArchivaRestServiceException( e.getMessage() );
229         }
230     }
231
232     public void setKnownContentConsumers( List<String> knownContentConsumers )
233         throws ArchivaRestServiceException
234     {
235         try
236         {
237             archivaAdministration.setKnownContentConsumers( knownContentConsumers, getAuditInformation() );
238         }
239         catch ( RepositoryAdminException e )
240         {
241             throw new ArchivaRestServiceException( e.getMessage() );
242         }
243     }
244
245     public Boolean removeKnownContentConsumer( String knownContentConsumer )
246         throws ArchivaRestServiceException
247     {
248         try
249         {
250             archivaAdministration.removeKnownContentConsumer( knownContentConsumer, getAuditInformation() );
251             return Boolean.TRUE;
252         }
253         catch ( RepositoryAdminException e )
254         {
255             throw new ArchivaRestServiceException( e.getMessage() );
256         }
257     }
258
259     public Boolean addInvalidContentConsumer( String invalidContentConsumer )
260         throws ArchivaRestServiceException
261     {
262         try
263         {
264             archivaAdministration.addInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
265             return Boolean.TRUE;
266         }
267         catch ( RepositoryAdminException e )
268         {
269             throw new ArchivaRestServiceException( e.getMessage() );
270         }
271     }
272
273     public void setInvalidContentConsumers( List<String> invalidContentConsumers )
274         throws ArchivaRestServiceException
275     {
276         try
277         {
278             archivaAdministration.setInvalidContentConsumers( invalidContentConsumers, getAuditInformation() );
279         }
280         catch ( RepositoryAdminException e )
281         {
282             throw new ArchivaRestServiceException( e.getMessage() );
283         }
284     }
285
286     public Boolean removeInvalidContentConsumer( String invalidContentConsumer )
287         throws ArchivaRestServiceException
288     {
289         try
290         {
291             archivaAdministration.removeInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
292             return Boolean.TRUE;
293         }
294         catch ( RepositoryAdminException e )
295         {
296             throw new ArchivaRestServiceException( e.getMessage() );
297         }
298     }
299 }