]> source.dussan.org Git - archiva.git/blob
7de4cc5c6d60e90eb2b39f4a2a0816f9d2ea106d
[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 org.apache.archiva.admin.model.RepositoryAdminException;
22 import org.apache.archiva.admin.model.beans.ManagedRepository;
23 import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
24 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
25 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
26 import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
27 import org.apache.commons.lang.StringUtils;
28 import org.springframework.stereotype.Service;
29
30 import javax.inject.Inject;
31 import java.util.Collections;
32 import java.util.List;
33
34 /**
35  * @author Olivier Lamy
36  * @since 1.4-M1
37  */
38 @Service( "managedRepositoriesService#rest" )
39 public class DefaultManagedRepositoriesService
40     extends AbstractRestService
41     implements ManagedRepositoriesService
42 {
43
44     @Inject
45     private ManagedRepositoryAdmin managedRepositoryAdmin;
46
47     @Inject
48     private PlexusSisuBridge plexusSisuBridge;
49
50
51     public List<ManagedRepository> getManagedRepositories()
52         throws ArchivaRestServiceException
53     {
54         try
55         {
56             List<org.apache.archiva.admin.model.beans.ManagedRepository> repos =
57                 managedRepositoryAdmin.getManagedRepositories();
58             return repos == null ? Collections.<ManagedRepository>emptyList() : repos;
59         }
60         catch ( RepositoryAdminException e )
61         {
62             throw new ArchivaRestServiceException( e.getMessage() );
63         }
64     }
65
66     public ManagedRepository getManagedRepository( String repositoryId )
67         throws ArchivaRestServiceException
68     {
69         List<ManagedRepository> repos = getManagedRepositories();
70         for ( ManagedRepository repo : repos )
71         {
72             if ( StringUtils.equals( repo.getId(), repositoryId ) )
73             {
74                 return repo;
75             }
76         }
77         return null;
78     }
79
80
81     public Boolean deleteManagedRepository( String repoId, boolean deleteContent )
82         throws ArchivaRestServiceException
83     {
84
85         try
86         {
87             return managedRepositoryAdmin.deleteManagedRepository( repoId, getAuditInformation(), deleteContent );
88         }
89         catch ( RepositoryAdminException e )
90         {
91             log.error( e.getMessage(), e );
92             throw new ArchivaRestServiceException( e.getMessage() );
93         }
94     }
95
96     public Boolean addManagedRepository( ManagedRepository managedRepository )
97         throws ArchivaRestServiceException
98     {
99
100         try
101         {
102             return managedRepositoryAdmin.addManagedRepository( managedRepository,
103                                                                 managedRepository.isStageRepoNeeded(),
104                                                                 getAuditInformation() );
105         }
106         catch ( RepositoryAdminException e )
107         {
108             throw new ArchivaRestServiceException( e.getMessage() );
109         }
110     }
111
112
113     public Boolean updateManagedRepository( ManagedRepository managedRepository )
114         throws ArchivaRestServiceException
115     {
116
117         try
118         {
119             return managedRepositoryAdmin.updateManagedRepository( managedRepository,
120                                                                    managedRepository.isStageRepoNeeded(),
121                                                                    getAuditInformation(),
122                                                                    managedRepository.isResetStats() );
123         }
124         catch ( RepositoryAdminException e )
125         {
126             throw new ArchivaRestServiceException( e.getMessage() );
127         }
128     }
129
130 }