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