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  package net.sf.pmr.agilePlanning.service;
36  
37  import java.util.Date;
38  import java.util.Set;
39  
40  import net.sf.pmr.agilePlanning.AgilePlanningObjectFactory;
41  import net.sf.pmr.agilePlanning.domain.iteration.Iteration;
42  import net.sf.pmr.agilePlanning.domain.iteration.IterationRepository;
43  import net.sf.pmr.agilePlanning.domain.iteration.IterationValidator;
44  import net.sf.pmr.keopsframework.domain.validation.Errors;
45  
46  /***
47   * @author Arnaud Prost (arnaud.prost@gmail.com)
48   */
49  public class IterationServiceImpl implements IterationService {
50  
51      /***
52       * Validator
53       */
54      private IterationValidator iterationValidator;
55  
56      /***
57       * Repository
58       */
59      private IterationRepository iterationRepository;
60  
61      /***
62       * Constructor
63       * @param iterationValidator iterationValidator
64       * @param iterationRepository iterationRepository
65       */
66      public IterationServiceImpl(final IterationValidator iterationValidator, final IterationRepository iterationRepository) {
67          super();
68          this.iterationValidator = iterationValidator;
69          this.iterationRepository = iterationRepository;
70      }
71  
72      /***
73       * @see net.sf.pmr.agilePlanning.service.IterationService#add(int, java.util.Date, java.util.Date, int)
74       */
75      public Errors add(final int projetPersistanceId, final Date start, final Date end, final int releasePersistanceId) {
76  
77          // Buid the object to persist
78          Iteration iteration = AgilePlanningObjectFactory.getIteration();
79          iteration.getBasicProject().setPersistanceId(projetPersistanceId);
80          iteration.setEnd(end);
81          iteration.getRelease().setPersistanceId(releasePersistanceId);
82          iteration.setStart(start);
83  
84          // validate
85          Errors errors = iterationValidator.validate(iteration);
86  
87          // if there are no errors, persist iteration
88          if (!errors.hasErrors()) {
89              iterationRepository.addOrUpdate(iteration);
90          }
91  
92          return errors;
93  
94      }
95  
96      //    public Errors delete(int persistanceId, long persistanceVersion) {
97      //        return null;
98      //    }
99  
100     /***
101      * @see net.sf.pmr.agilePlanning.service.IterationService#findByPersistanceId(int)
102      */
103     public Iteration findByPersistanceId(final int persistanceId) {
104 
105         return iterationRepository.findByPersistanceId(persistanceId);
106 
107     }
108 
109     /***
110      * @see net.sf.pmr.agilePlanning.service.IterationService#findByProjectPersistanceId(int)
111      */
112     public Set findByProjectPersistanceId(final int projectPersistanceId) {
113 
114         return iterationRepository.findByProjectPersistanceId(projectPersistanceId);
115 
116     }
117     
118     /*** 
119      * @see net.sf.pmr.agilePlanning.service.IterationService#findByProjectPersistanceIdAndByDate(int, java.util.Date)
120      */
121     public Iteration findByProjectPersistanceIdAndByDate(final int projetPersistanceId, final Date date) {
122         return iterationRepository.findByProjectPersistanceIdAndByDate(projetPersistanceId, date);
123     }
124 
125     /***
126      * @see net.sf.pmr.agilePlanning.service.IterationService#update(int, java.util.Date, java.util.Date, int, int, long)
127      */
128     public Errors update(final int projectPersistanceId, final Date start, final Date end, final int releasePersistanceId, final int persistanceId,
129             final long persistanceVersion) {
130 
131         // Build the projet to persist
132         Iteration iteration = AgilePlanningObjectFactory.getIteration();
133         iteration.getBasicProject().setPersistanceId(projectPersistanceId);
134         iteration.setEnd(end);
135         iteration.setPersistanceId(persistanceId);
136         iteration.setPersistanceVersion(persistanceVersion);
137         iteration.getRelease().setPersistanceId(persistanceId);
138         iteration.setStart(start);
139 
140         // validate
141         Errors errors = iterationValidator.validate(iteration);
142 
143         // if there are no errors, persist iteration
144         if (!errors.hasErrors()) {
145             iterationRepository.addOrUpdate(iteration);
146         }
147 
148         return errors;
149 
150     }
151 }