EMMA Coverage Report (generated Sun Sep 18 11:34:27 PHT 2011)
[all classes][org.apache.continuum.repository]

COVERAGE SUMMARY FOR SOURCE FILE [DefaultRepositoryService.java]

nameclass, %method, %block, %line, %
DefaultRepositoryService.java100% (1/1)70%  (7/10)49%  (163/331)49%  (33/67)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DefaultRepositoryService100% (1/1)70%  (7/10)49%  (163/331)49%  (33/67)
getLocalRepositoriesByLayout (String): List 0%   (0/1)0%   (0/5)0%   (0/1)
getLocalRepositoryByLocation (String): LocalRepository 0%   (0/1)0%   (0/33)0%   (0/5)
updateLocalRepository (LocalRepository): void 0%   (0/1)0%   (0/43)0%   (0/11)
getLocalRepository (int): LocalRepository 100% (1/1)15%  (5/33)20%  (1/5)
removePurgeConfigurationsOfRepository (int): void 100% (1/1)44%  (22/50)56%  (5/9)
addLocalRepository (LocalRepository): LocalRepository 100% (1/1)77%  (57/74)74%  (11.2/15)
removeLocalRepository (int): void 100% (1/1)83%  (68/82)72%  (12.9/18)
<static initializer> 100% (1/1)100% (4/4)100% (1/1)
DefaultRepositoryService (): void 100% (1/1)100% (3/3)100% (1/1)
getAllLocalRepositories (): List 100% (1/1)100% (4/4)100% (1/1)

1package org.apache.continuum.repository;
2 
3/*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements.  See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership.  The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License.  You may obtain a copy of the License at
11 *
12 *   http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied.  See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21 
22import java.util.List;
23 
24import org.apache.continuum.dao.LocalRepositoryDao;
25import org.apache.continuum.dao.ProjectGroupDao;
26import org.apache.continuum.dao.RepositoryPurgeConfigurationDao;
27import org.apache.continuum.model.repository.LocalRepository;
28import org.apache.continuum.model.repository.RepositoryPurgeConfiguration;
29import org.apache.continuum.taskqueue.manager.TaskQueueManager;
30import org.apache.continuum.taskqueue.manager.TaskQueueManagerException;
31import org.apache.maven.continuum.model.project.ProjectGroup;
32import org.apache.maven.continuum.store.ContinuumObjectNotFoundException;
33import org.apache.maven.continuum.store.ContinuumStoreException;
34import org.slf4j.Logger;
35import org.slf4j.LoggerFactory;
36 
37/**
38 * DefaultRepositoryService
39 *
40 * @author Maria Catherine Tan
41 * @version $Id: DefaultRepositoryService.java 764863 2009-04-14 16:28:12Z evenisse $
42 * @plexus.component role="org.apache.continuum.repository.RepositoryService" role-hint="default"
43 * @since 25 jul 07
44 */
45public class DefaultRepositoryService
46    implements RepositoryService
47{
48    private static final Logger log = LoggerFactory.getLogger( DefaultRepositoryService.class );
49 
50    /**
51     * @plexus.requirement
52     */
53    private LocalRepositoryDao localRepositoryDao;
54 
55    /**
56     * @plexus.requirement
57     */
58    private RepositoryPurgeConfigurationDao repositoryPurgeConfigurationDao;
59 
60    /**
61     * @plexus.requirement
62     */
63    private ProjectGroupDao projectGroupDao;
64 
65    /**
66     * @plexus.requirement
67     */
68    private TaskQueueManager taskQueueManager;
69 
70    public LocalRepository addLocalRepository( LocalRepository localRepository )
71        throws RepositoryServiceException
72    {
73        LocalRepository repository = null;
74 
75        try
76        {
77            List<LocalRepository> repos = getAllLocalRepositories();
78            for ( LocalRepository repo : repos )
79            {
80                if ( repo.getName().equals( localRepository.getName() ) )
81                {
82                    throw new RepositoryServiceException( "Local repository name must be unique" );
83                }
84 
85                if ( repo.getLocation().equals( localRepository.getLocation() ) )
86                {
87                    throw new RepositoryServiceException( "Local repository location must be unique" );
88                }
89            }
90 
91            localRepository.setName( localRepository.getName().trim() );
92            localRepository.setLocation( localRepository.getLocation().trim() );
93 
94            repository = localRepositoryDao.addLocalRepository( localRepository );
95 
96            log.info( "Added new local repository: " + repository.getName() );
97        }
98        catch ( ContinuumStoreException e )
99        {
100            throw new RepositoryServiceException( "Unable to add the requested local repository", e );
101        }
102 
103        return repository;
104    }
105 
106    public void removeLocalRepository( int repositoryId )
107        throws RepositoryServiceException
108    {
109        try
110        {
111            LocalRepository repository = getLocalRepository( repositoryId );
112 
113            if ( taskQueueManager.isRepositoryInUse( repositoryId ) )
114            {
115                return;
116            }
117 
118            if ( taskQueueManager.isRepositoryInPurgeQueue( repositoryId ) )
119            {
120                taskQueueManager.removeRepositoryFromPurgeQueue( repositoryId );
121            }
122 
123            log.info( "Remove purge configurations of " + repository.getName() );
124            removePurgeConfigurationsOfRepository( repositoryId );
125 
126            List<ProjectGroup> groups = projectGroupDao.getProjectGroupByRepository( repositoryId );
127 
128            for ( ProjectGroup group : groups )
129            {
130                group.setLocalRepository( null );
131                projectGroupDao.updateProjectGroup( group );
132            }
133 
134            localRepositoryDao.removeLocalRepository( repository );
135 
136            log.info( "Removed local repository: " + repository.getName() );
137        }
138        catch ( TaskQueueManagerException e )
139        {
140            // swallow?
141        }
142        catch ( ContinuumStoreException e )
143        {
144            throw new RepositoryServiceException( "Unable to delete the requested local repository", e );
145        }
146    }
147 
148    public void updateLocalRepository( LocalRepository localRepository )
149        throws RepositoryServiceException
150    {
151        localRepository.setName( localRepository.getName().trim() );
152        localRepository.setLocation( localRepository.getLocation().trim() );
153 
154        try
155        {
156            if ( taskQueueManager.isRepositoryInUse( localRepository.getId() ) )
157            {
158                return;
159            }
160 
161            localRepositoryDao.updateLocalRepository( localRepository );
162 
163            log.info( "Updated local repository: " + localRepository.getName() );
164        }
165        catch ( TaskQueueManagerException e )
166        {
167            // swallow?
168        }
169        catch ( ContinuumStoreException e )
170        {
171            throw new RepositoryServiceException( "Unable to update the requested local repository", e );
172        }
173    }
174 
175    public List<LocalRepository> getAllLocalRepositories()
176    {
177        return localRepositoryDao.getAllLocalRepositories();
178    }
179 
180    public List<LocalRepository> getLocalRepositoriesByLayout( String layout )
181    {
182        return localRepositoryDao.getLocalRepositoriesByLayout( layout );
183    }
184 
185    public LocalRepository getLocalRepositoryByLocation( String location )
186        throws RepositoryServiceException
187    {
188        try
189        {
190            return localRepositoryDao.getLocalRepositoryByLocation( location );
191        }
192        catch ( ContinuumObjectNotFoundException e )
193        {
194            throw new RepositoryServiceException( "No repository found with location: " + location, e );
195        }
196        catch ( ContinuumStoreException e )
197        {
198            throw new RepositoryServiceException( "Unable to retrieve local repository by location: " + location, e );
199        }
200    }
201 
202    public LocalRepository getLocalRepository( int repositoryId )
203        throws RepositoryServiceException
204    {
205        try
206        {
207            return localRepositoryDao.getLocalRepository( repositoryId );
208        }
209        catch ( ContinuumObjectNotFoundException e )
210        {
211            throw new RepositoryServiceException( "No repository found with id: " + repositoryId, e );
212        }
213        catch ( ContinuumStoreException e )
214        {
215            throw new RepositoryServiceException( "Unable to retrieve local repository: " + repositoryId, e );
216        }
217    }
218 
219    private void removePurgeConfigurationsOfRepository( int repositoryId )
220        throws RepositoryServiceException
221    {
222        try
223        {
224            List<RepositoryPurgeConfiguration> purgeConfigs =
225                repositoryPurgeConfigurationDao.getRepositoryPurgeConfigurationsByLocalRepository( repositoryId );
226 
227            for ( RepositoryPurgeConfiguration purgeConfig : purgeConfigs )
228            {
229                repositoryPurgeConfigurationDao.removeRepositoryPurgeConfiguration( purgeConfig );
230            }
231        }
232        catch ( ContinuumObjectNotFoundException e )
233        {
234            throw new RepositoryServiceException( "Error while removing local repository: " + repositoryId, e );
235        }
236        catch ( ContinuumStoreException e )
237        {
238            throw new RepositoryServiceException(
239                "Error while removing purge configurations of local repository: " + repositoryId, e );
240        }
241    }
242}

[all classes][org.apache.continuum.repository]
EMMA 2.0.5312 (C) Vladimir Roubtsov