This project has retired. For details please refer to its Attic page.
Source code
001package org.apache.archiva.rest.services;
002/*
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *   http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied.  See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 */
020
021import org.apache.archiva.admin.model.RepositoryAdminException;
022import org.apache.archiva.admin.model.admin.ArchivaAdministration;
023import org.apache.archiva.admin.model.beans.*;
024import org.apache.archiva.repository.scanner.RepositoryContentConsumers;
025import org.apache.archiva.rest.api.model.AdminRepositoryConsumer;
026import org.apache.archiva.rest.api.services.ArchivaAdministrationService;
027import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
028import org.apache.archiva.rest.services.utils.AddAdminRepoConsumerClosure;
029import org.apache.archiva.rest.services.utils.AdminRepositoryConsumerComparator;
030import org.apache.commons.collections4.IterableUtils;
031import org.apache.commons.lang3.StringUtils;
032import org.springframework.stereotype.Service;
033
034import javax.inject.Inject;
035import java.util.ArrayList;
036import java.util.Collections;
037import java.util.List;
038
039/**
040 * @author Olivier Lamy
041 * @since 1.4-M1
042 */
043@Service ( "archivaAdministrationService#default" )
044public class DefaultArchivaAdministrationService
045    extends AbstractRestService
046    implements ArchivaAdministrationService
047{
048    @Inject
049    private ArchivaAdministration archivaAdministration;
050
051
052    @Inject
053    private RepositoryContentConsumers repoConsumerUtil;
054
055    @Override
056    public List<LegacyArtifactPath> getLegacyArtifactPaths()
057        throws ArchivaRestServiceException
058    {
059        try
060        {
061            return archivaAdministration.getLegacyArtifactPaths();
062        }
063        catch ( RepositoryAdminException e )
064        {
065            throw new ArchivaRestServiceException( e.getMessage(), e );
066        }
067    }
068
069
070    @Override
071    public Boolean deleteLegacyArtifactPath( String path )
072        throws ArchivaRestServiceException
073    {
074        try
075        {
076            archivaAdministration.deleteLegacyArtifactPath( path, getAuditInformation() );
077            return Boolean.TRUE;
078        }
079        catch ( RepositoryAdminException e )
080        {
081            throw new ArchivaRestServiceException( e.getMessage(), e );
082        }
083    }
084
085
086    @Override
087    public Boolean addFileTypePattern( String fileTypeId, String pattern )
088        throws ArchivaRestServiceException
089    {
090        try
091        {
092            archivaAdministration.addFileTypePattern( fileTypeId, pattern, getAuditInformation() );
093            return Boolean.TRUE;
094        }
095        catch ( RepositoryAdminException e )
096        {
097            throw new ArchivaRestServiceException( e.getMessage(), e );
098        }
099    }
100
101    @Override
102    public Boolean removeFileTypePattern( String fileTypeId, String pattern )
103        throws ArchivaRestServiceException
104    {
105        try
106        {
107            archivaAdministration.removeFileTypePattern( fileTypeId, pattern, getAuditInformation() );
108            return Boolean.TRUE;
109        }
110        catch ( RepositoryAdminException e )
111        {
112            throw new ArchivaRestServiceException( e.getMessage(), e );
113        }
114    }
115
116    @Override
117    public FileType getFileType( String fileTypeId )
118        throws ArchivaRestServiceException
119    {
120        try
121        {
122            return archivaAdministration.getFileType( fileTypeId );
123        }
124        catch ( RepositoryAdminException e )
125        {
126            throw new ArchivaRestServiceException( e.getMessage(), e );
127        }
128    }
129
130    @Override
131    public void addFileType( FileType fileType )
132        throws ArchivaRestServiceException
133    {
134        try
135        {
136            archivaAdministration.addFileType( fileType, getAuditInformation() );
137        }
138        catch ( RepositoryAdminException e )
139        {
140            throw new ArchivaRestServiceException( e.getMessage(), e );
141        }
142    }
143
144    @Override
145    public Boolean removeFileType( String fileTypeId )
146        throws ArchivaRestServiceException
147    {
148        try
149        {
150            archivaAdministration.removeFileType( fileTypeId, getAuditInformation() );
151            return Boolean.TRUE;
152        }
153        catch ( RepositoryAdminException e )
154        {
155            throw new ArchivaRestServiceException( e.getMessage(), e );
156        }
157    }
158
159    @Override
160    public Boolean enabledKnownContentConsumer( String knownContentConsumer )
161        throws ArchivaRestServiceException
162    {
163        try
164        {
165            archivaAdministration.addKnownContentConsumer( knownContentConsumer, getAuditInformation() );
166            return Boolean.TRUE;
167        }
168        catch ( RepositoryAdminException e )
169        {
170            throw new ArchivaRestServiceException( e.getMessage(), e );
171        }
172    }
173
174    @Override
175    public void enabledKnownContentConsumers( List<String> knownContentConsumers )
176        throws ArchivaRestServiceException
177    {
178        try
179        {
180            archivaAdministration.setKnownContentConsumers( knownContentConsumers, getAuditInformation() );
181        }
182        catch ( RepositoryAdminException e )
183        {
184            throw new ArchivaRestServiceException( e.getMessage(), e );
185        }
186    }
187
188    @Override
189    public Boolean disabledKnownContentConsumer( String knownContentConsumer )
190        throws ArchivaRestServiceException
191    {
192        try
193        {
194            archivaAdministration.removeKnownContentConsumer( knownContentConsumer, getAuditInformation() );
195            return Boolean.TRUE;
196        }
197        catch ( RepositoryAdminException e )
198        {
199            throw new ArchivaRestServiceException( e.getMessage(), e );
200        }
201    }
202
203    @Override
204    public Boolean enabledInvalidContentConsumer( String invalidContentConsumer )
205        throws ArchivaRestServiceException
206    {
207        try
208        {
209            archivaAdministration.addInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
210            return Boolean.TRUE;
211        }
212        catch ( RepositoryAdminException e )
213        {
214            throw new ArchivaRestServiceException( e.getMessage(), e );
215        }
216    }
217
218    @Override
219    public void enabledInvalidContentConsumers( List<String> invalidContentConsumers )
220        throws ArchivaRestServiceException
221    {
222        try
223        {
224            archivaAdministration.setInvalidContentConsumers( invalidContentConsumers, getAuditInformation() );
225        }
226        catch ( RepositoryAdminException e )
227        {
228            throw new ArchivaRestServiceException( e.getMessage(), e );
229        }
230    }
231
232    @Override
233    public Boolean disabledInvalidContentConsumer( String invalidContentConsumer )
234        throws ArchivaRestServiceException
235    {
236        try
237        {
238            archivaAdministration.removeInvalidContentConsumer( invalidContentConsumer, getAuditInformation() );
239            return Boolean.TRUE;
240        }
241        catch ( RepositoryAdminException e )
242        {
243            throw new ArchivaRestServiceException( e.getMessage(), e );
244        }
245    }
246
247    @Override
248    public List<FileType> getFileTypes()
249        throws ArchivaRestServiceException
250    {
251        try
252        {
253            List<FileType> modelfileTypes = archivaAdministration.getFileTypes();
254            if ( modelfileTypes == null || modelfileTypes.isEmpty() )
255            {
256                return Collections.emptyList();
257            }
258            return modelfileTypes;
259        }
260        catch ( RepositoryAdminException e )
261        {
262            throw new ArchivaRestServiceException( e.getMessage(), e );
263        }
264    }
265
266    @Override
267    public List<String> getKnownContentConsumers()
268        throws ArchivaRestServiceException
269    {
270        try
271        {
272            return new ArrayList<>( archivaAdministration.getKnownContentConsumers( ) );
273        }
274        catch ( RepositoryAdminException e )
275        {
276            throw new ArchivaRestServiceException( e.getMessage(), e );
277        }
278    }
279
280    @Override
281    public List<String> getInvalidContentConsumers()
282        throws ArchivaRestServiceException
283    {
284        try
285        {
286            return new ArrayList<>( archivaAdministration.getInvalidContentConsumers( ) );
287        }
288        catch ( RepositoryAdminException e )
289        {
290            throw new ArchivaRestServiceException( e.getMessage(), e );
291        }
292    }
293
294    @Override
295    public OrganisationInformation getOrganisationInformation()
296        throws ArchivaRestServiceException
297    {
298        try
299        {
300            return archivaAdministration.getOrganisationInformation();
301        }
302        catch ( RepositoryAdminException e )
303        {
304            throw new ArchivaRestServiceException( e.getMessage(), e );
305        }
306    }
307
308    @Override
309    public void setOrganisationInformation( OrganisationInformation organisationInformation )
310        throws ArchivaRestServiceException
311    {
312        try
313        {
314            archivaAdministration.setOrganisationInformation( organisationInformation );
315        }
316        catch ( RepositoryAdminException e )
317        {
318            throw new ArchivaRestServiceException( e.getMessage(), 400, e );
319        }
320    }
321
322    @Override
323    public Boolean registrationDisabled()
324        throws ArchivaRestServiceException
325    {
326        return getUiConfiguration().isDisableRegistration();
327    }
328
329    @Override
330    public UiConfiguration getUiConfiguration()
331        throws ArchivaRestServiceException
332    {
333        try
334        {
335            return archivaAdministration.getUiConfiguration();
336        }
337        catch ( RepositoryAdminException e )
338        {
339            throw new ArchivaRestServiceException( e.getMessage(), e );
340        }
341    }
342
343    @Override
344    public void setUiConfiguration( UiConfiguration uiConfiguration )
345        throws ArchivaRestServiceException
346    {
347        try
348        {
349            // fix for MRM-1757
350            // strip any trailing '/' at the end of the url so it won't affect url/link calculations in UI
351            uiConfiguration.setApplicationUrl(StringUtils.stripEnd(uiConfiguration.getApplicationUrl(), "/"));
352
353            archivaAdministration.updateUiConfiguration( uiConfiguration );
354        }
355        catch ( RepositoryAdminException e )
356        {
357            throw new ArchivaRestServiceException( e.getMessage(), e );
358        }
359    }
360
361    @Override
362    public String getApplicationUrl()
363        throws ArchivaRestServiceException
364    {
365        try
366        {
367            return archivaAdministration.getUiConfiguration().getApplicationUrl();
368        }
369        catch ( RepositoryAdminException e )
370        {
371            throw new ArchivaRestServiceException( e.getMessage(), e );
372        }
373    }
374
375    @Override
376    public NetworkConfiguration getNetworkConfiguration()
377        throws ArchivaRestServiceException
378    {
379        try
380        {
381            return archivaAdministration.getNetworkConfiguration();
382        }
383        catch ( RepositoryAdminException e )
384        {
385            throw new ArchivaRestServiceException( e.getMessage(), e );
386        }
387    }
388
389    @Override
390    public void setNetworkConfiguration( NetworkConfiguration networkConfiguration )
391        throws ArchivaRestServiceException
392    {
393        try
394        {
395            archivaAdministration.setNetworkConfiguration( networkConfiguration );
396        }
397        catch ( RepositoryAdminException e )
398        {
399            throw new ArchivaRestServiceException( e.getMessage(), e );
400        }
401    }
402
403    @Override
404    public List<AdminRepositoryConsumer> getKnownContentAdminRepositoryConsumers()
405        throws ArchivaRestServiceException
406    {
407        try
408        {
409            AddAdminRepoConsumerClosure addAdminRepoConsumer =
410                new AddAdminRepoConsumerClosure( archivaAdministration.getKnownContentConsumers() );
411            IterableUtils.forEach( repoConsumerUtil.getAvailableKnownConsumers(), addAdminRepoConsumer );
412            List<AdminRepositoryConsumer> knownContentConsumers = addAdminRepoConsumer.getList();
413            knownContentConsumers.sort( AdminRepositoryConsumerComparator.getInstance( ) );
414            return knownContentConsumers;
415        }
416        catch ( RepositoryAdminException e )
417        {
418            throw new ArchivaRestServiceException( e.getMessage(), e );
419        }
420    }
421
422    @Override
423    public List<AdminRepositoryConsumer> getInvalidContentAdminRepositoryConsumers()
424        throws ArchivaRestServiceException
425    {
426        try
427        {
428            AddAdminRepoConsumerClosure addAdminRepoConsumer =
429                new AddAdminRepoConsumerClosure( archivaAdministration.getInvalidContentConsumers() );
430            IterableUtils.forEach( repoConsumerUtil.getAvailableInvalidConsumers(), addAdminRepoConsumer );
431            List<AdminRepositoryConsumer> invalidContentConsumers = addAdminRepoConsumer.getList();
432            invalidContentConsumers.sort( AdminRepositoryConsumerComparator.getInstance( ) );
433            return invalidContentConsumers;
434        }
435        catch ( RepositoryAdminException e )
436        {
437            throw new ArchivaRestServiceException( e.getMessage(), e );
438        }
439    }
440}