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.release.Release;
42  import net.sf.pmr.agilePlanning.domain.release.ReleaseRepository;
43  import net.sf.pmr.agilePlanning.domain.release.ReleaseValidator;
44  import net.sf.pmr.keopsframework.domain.validation.Errors;
45  
46  /***
47   * @author Arnaud Prost (arnaud.prost@gmail.com)
48   */
49  public class ReleaseServiceImpl implements ReleaseService {
50  
51      /***
52       * Validator
53       */
54      private ReleaseValidator releaseValidator;
55  
56      /***
57       * Repository
58       */
59      private ReleaseRepository releaseRepository;
60  
61      /***
62       * constructor
63       * @param releaseValidator releaseValidator
64       * @param releaseRepository releaseValidator
65       */
66      public ReleaseServiceImpl(final ReleaseValidator releaseValidator, final ReleaseRepository releaseRepository) {
67          super();
68          this.releaseValidator = releaseValidator;
69          this.releaseRepository = releaseRepository;
70      }
71  
72      /***
73       * @see net.sf.pmr.agilePlanning.service.ReleaseService#add(int, String, java.util.Date)
74       */
75      public Errors add(final int projectPersistanceId, final String number, final Date date) {
76  
77          // Buid the object to persist
78          Release release = AgilePlanningObjectFactory.getRelease();
79          release.getBasicProject().setPersistanceId(projectPersistanceId);
80          release.setDate(date);
81          release.setNumber(number);
82  
83          // validate
84          Errors errors = releaseValidator.validate(release);
85  
86          // if there are no errors, persist iteration
87          if (!errors.hasErrors()) {
88              releaseRepository.addOrUpdate(release);
89          }
90  
91          return errors;
92      }
93  
94      //    public Errors delete(int persistanceId, long persistanceVersion) {
95      //        return null;
96      //    }
97  
98      /***
99       * @see net.sf.pmr.agilePlanning.service.ReleaseService#findByPersistanceId(int)
100      */
101     public Release findByPersistanceId(final int persistanceId) {
102         return releaseRepository.findByPersistanceId(persistanceId);
103     }
104 
105     /***
106      * @see net.sf.pmr.agilePlanning.service.ReleaseService#findByProjectPersistanceId(int)
107      */
108     public Set findByProjectPersistanceId(final int projectPersistanceId) {
109         return releaseRepository.findByProjectPersistanceId(projectPersistanceId);
110     }
111 
112     /***
113      * @see net.sf.pmr.agilePlanning.service.ReleaseService#update(int, java.lang.String, java.util.Date, int, long)
114      */
115     public Errors update(final int projectPersistanceId, final String number, final Date date, final int persistanceId, final long persistanceVersion) {
116 
117         // Buid the object to persist
118         Release release = AgilePlanningObjectFactory.getRelease();
119         release.getBasicProject().setPersistanceId(projectPersistanceId);
120         release.setDate(date);
121         release.setNumber(number);
122         release.setPersistanceId(persistanceId);
123         release.setPersistanceVersion(persistanceVersion);
124 
125         // validate
126         Errors errors = releaseValidator.validate(release);
127 
128         // if there are no errors, persist iteration
129         if (!errors.hasErrors()) {
130             releaseRepository.addOrUpdate(release);
131         }
132 
133         return errors;
134     }
135 
136 }