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