View Javadoc

1   /*
2   * Copyright 2005 Arnaud Prost
3   * 
4   * Arnaud.prost@gmail.com
5   * 
6   * This software is a computer program whose purpose is to ease the 
7   * management of software project.
8   * 
9   * This software is governed by the CeCILL  license under French law and
10  * abiding by the rules of distribution of free software.  You can  use, 
11  * modify and/ or redistribute the software under the terms of the CeCILL
12  * license as circulated by CEA, CNRS and INRIA at the following URL
13  * "http://www.cecill.info". 
14  * 
15  * As a counterpart to the access to the source code and  rights to copy,
16  * modify and redistribute granted by the license, users are provided only
17  * with a limited warranty  and the software's author,  the holder of the
18  * economic rights,  and the successive licensors  have only  limited
19  * liability. 
20  * 
21  * In this respect, the user's attention is drawn to the risks associated
22  * with loading,  using,  modifying and/or developing or reproducing the
23  * software by the user in light of its specific status of free software,
24  * that may mean  that it is complicated to manipulate,  and  that  also
25  * therefore means  that it is reserved for developers  and  experienced
26  * professionals having in-depth computer knowledge. Users are therefore
27  * encouraged to load and test the software's suitability as regards their
28  * requirements in conditions enabling the security of their systems and/or 
29  * data to be ensured and,  more generally, to use and operate it in the 
30  * same conditions as regards security. 
31  * 
32  * The fact that you are presently reading this means that you have had
33  * knowledge of the CeCILL license and that you accept its terms.
34  */
35  
36  package net.sf.pmr.agilePlanning.domain.iteration;
37  
38  import java.util.Date;
39  import java.util.Set;
40  
41  import org.springframework.aop.TargetSource;
42  import org.springframework.aop.framework.Advised;
43  import org.springframework.aop.target.SingletonTargetSource;
44  
45  import net.sf.pmr.agilePlanning.data.iteration.IterationMapper;
46  import net.sf.pmr.core.domain.basicProject.BasicProject;
47  
48  /***
49   * @author Arnaud Prost (arnaud.prost@gmail.com)
50   *
51   * Iteration repositoy
52   */
53  public class IterationRepositoryImpl implements IterationRepository {
54  
55      /***
56       * Iteration mapper
57       */
58      private IterationMapper iterationMapper;
59  
60      /***
61       * @param iterationMapper
62       */
63      public IterationRepositoryImpl(final IterationMapper iterationMapper) {
64          super();
65          this.iterationMapper = iterationMapper;
66      }
67  
68      /***
69       * @see net.sf.pmr.agilePlanning.domain.iteration.IterationRepository#findByPersistanceId(int)
70       */
71      public Iteration findByPersistanceId(final int persistanceId) {
72          return (Iteration) iterationMapper.findById(persistanceId);
73      }
74  
75      /***
76       * @see net.sf.pmr.agilePlanning.domain.iteration.IterationRepository#addOrUpdate(net.sf.pmr.agilePlanning.domain.iteration.Iteration)
77       */
78      public void addOrUpdate(final Iteration iteration) {
79          
80          // Avant de faire l'enregistrement en base, il faut récupérer la target du proxy
81          // basicProject
82          BasicProject basicProjectTarget = (getTarget(iteration.getBasicProject()));
83          iteration.setBasicProject(basicProjectTarget);
84  
85          
86          iterationMapper.addOrUpdate(iteration);
87      }
88  
89      /***
90       * @see net.sf.pmr.agilePlanning.domain.iteration.IterationRepository#findByProjectPersistanceId(int)
91       */
92      public Set findByProjectPersistanceId(final int projetPersistanceId) {
93          return iterationMapper.findByProjectPersistanceId(projetPersistanceId);
94      }
95      
96      /*** 
97       * @see net.sf.pmr.agilePlanning.domain.iteration.IterationRepository#findByProjectPersistanceIdAndByDate(int, java.util.Date)
98       */
99      public Iteration findByProjectPersistanceIdAndByDate(final int projetPersistanceId, final Date date) {
100         return iterationMapper.findByProjectPersistanceIdAndByDate(projetPersistanceId, date);
101     }
102     
103     /***
104      * BasicProject est un proxy, il faut récupérer la target
105      * 
106      * @param object
107      *            basicProject proxy
108      * @return basicProject target
109      */
110     // TODO cette méthode est utilisée dans plusieurs repository: à factoriser
111     private BasicProject getTarget(final Object basicProject) {
112         
113         // BasicProject est un proxy, il faut récupérer la target
114         TargetSource targetSource = ((Advised) basicProject).getTargetSource();        
115         Object target = ((SingletonTargetSource) targetSource).getTarget();
116 
117         // retour de la target
118         return (BasicProject) target;
119         
120     }
121 
122 }