View Javadoc
1   package fr.ifremer.tutti.persistence.service.util.tree;
2   
3   /*
4    * #%L
5    * Tutti :: Persistence
6    * %%
7    * Copyright (C) 2012 - 2014 Ifremer
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
24  
25  import fr.ifremer.adagio.core.dao.data.batch.CatchBatch;
26  import fr.ifremer.adagio.core.dao.data.batch.SortingBatch;
27  import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmId;
28  import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueId;
29  import org.springframework.stereotype.Component;
30  
31  import javax.annotation.Resource;
32  
33  /**
34   * Helper to build or navigauet into the batch tree.
35   *
36   * Created on 4/20/14.
37   *
38   * @author Tony Chemit - chemit@codelutin.com
39   * @since 3.5
40   */
41  @Component("batchTreeHelper")
42  public class BatchTreeHelper extends BatchTreeHelperSupport {
43  
44  //    /** Logger. */
45  //    private static final Log log = LogFactory.getLog(BatchTreeHelper.class);
46  
47      @Resource(name = "benthosBatchTreeHelper")
48      protected BenthosBatchTreeHelper benthosBatchTreeHelper;
49  
50      @Resource(name = "speciesBatchTreeHelper")
51      protected SpeciesBatchTreeHelper speciesBatchTreeHelper;
52  
53      //------------------------------------------------------------------------//
54      //-- Get CatchBatch navigation methods                                  --//
55      //------------------------------------------------------------------------//
56  
57  //    public SortingBatch getSpeciesVracAliveItemizedRootBatch(CatchBatch batch) {
58  //        return speciesBatchTreeHelper.getVracAliveItemizedRootBatch(batch);
59  //    }
60  //
61  //    public SortingBatch getBenthosVracAliveItemizedRootBatch(CatchBatch batch) {
62  //        return benthosBatchTreeHelper.getVracAliveItemizedRootBatch(batch);
63  //    }
64  //
65  //    public SortingBatch getSpeciesHorsVracRootBatch(CatchBatch batch) {
66  //        return speciesBatchTreeHelper.getHorsVracRootBatch(batch);
67  //    }
68  //
69  //    public SortingBatch getBenthosHorsVracRootBatch(CatchBatch batch) {
70  //        return benthosBatchTreeHelper.getHorsVracRootBatch(batch);
71  //    }
72  
73      public SortingBatch getMarineLitterRootBatch(CatchBatch batch) {
74          return getSortingBatch(batch,
75                                 "Hors Vrac > Marine Litter",
76                                 PmfmId.SORTED_UNSORTED.getValue(),
77                                 QualitativeValueId.SORTED_HORS_VRAC.getValue(),
78                                 SORTING_TYPE_ID,
79                                 QualitativeValueId.SORTING_TYPE_MARINE_LITTER.getValue());
80      }
81  
82  //    public SortingBatch getVracBatch(CatchBatch batch) {
83  //        return getSortingBatch(
84  //                batch,
85  //                "Vrac",
86  //                PmfmId.SORTED_UNSORTED.getValue(),
87  //                QualitativeValueId.SORTED_VRAC.getValue()
88  //        );
89  //    }
90  
91  //    public SortingBatch getHorsVracBatch(CatchBatch batch) {
92  //        return getSortingBatch(
93  //                batch,
94  //                "Hors Vrac",
95  //                PmfmId.SORTED_UNSORTED.getValue(),
96  //                QualitativeValueId.SORTED_HORS_VRAC.getValue()
97  //        );
98  //    }
99  //
100     public SortingBatch getRejectedBatch(CatchBatch batch) {
101         return getSortingBatch(
102                 batch,
103                 "Unsorted",
104                 PmfmId.SORTED_UNSORTED.getValue(),
105                 QualitativeValueId.UNSORTED.getValue()
106         );
107     }
108 
109     //------------------------------------------------------------------------//
110     //-- Get SortingBatch navigation methods                                --//
111     //------------------------------------------------------------------------//
112 
113     public SortingBatch getSpeciesVracRootBatch(SortingBatch batch) {
114         return speciesBatchTreeHelper.getVracRootBatch(batch);
115     }
116 
117     public SortingBatch getBenthosVracRootBatch(SortingBatch batch) {
118         return benthosBatchTreeHelper.getVracRootBatch(batch);
119     }
120 
121     public SortingBatch getSpeciesVracAliveNotItemizedRootBatch(SortingBatch batch) {
122         return speciesBatchTreeHelper.getVracAliveNotItemizedRootBatch(batch);
123     }
124 
125     public SortingBatch getBenthosVracAliveNotItemizedRootBatch(SortingBatch batch) {
126         return benthosBatchTreeHelper.getVracAliveNotItemizedRootBatch(batch);
127     }
128 
129     public SortingBatch getSpeciesVracInertRootBatch(SortingBatch batch) {
130         return speciesBatchTreeHelper.getVracInertRootBatch(batch);
131     }
132 
133     public SortingBatch getBenthosVracInertRootBatch(SortingBatch batch) {
134         return benthosBatchTreeHelper.getVracInertRootBatch(batch);
135     }
136 
137     public SortingBatch getSpeciesVracAliveItemizedRootBatch(SortingBatch batch) {
138         return speciesBatchTreeHelper.getVracAliveItemizedRootBatch(batch);
139     }
140 
141     public SortingBatch getBenthosVracAliveItemizedRootBatch(SortingBatch batch) {
142         return benthosBatchTreeHelper.getVracAliveItemizedRootBatch(batch);
143     }
144 
145     public SortingBatch getSpeciesHorsVracRootBatch(SortingBatch batch) {
146         return speciesBatchTreeHelper.getHorsVracRootBatch(batch);
147     }
148 
149     public SortingBatch getBenthosHorsVracRootBatch(SortingBatch batch) {
150         return benthosBatchTreeHelper.getHorsVracRootBatch(batch);
151     }
152 
153     public SortingBatch getMarineLitterRootBatch(SortingBatch batch) {
154         return getSortingBatch(
155                 batch,
156                 "Hors Vrac > MarineLitter",
157                 SORTING_TYPE_ID,
158                 QualitativeValueId.SORTING_TYPE_MARINE_LITTER.getValue());
159     }
160 
161     //------------------------------------------------------------------------//
162     //-- getOrCreate methods                                                --//
163     //------------------------------------------------------------------------//
164 
165 //    public SortingBatch getOrCreateVracBatch(CatchBatch batch, Float weight, Float weightBeforeSampling) {
166 //        return getOrCreate(batch,
167 //                           batch,
168 //                           "Vrac",
169 //                           PmfmId.SORTED_UNSORTED.getValue(),
170 //                           QualitativeValueId.SORTED_VRAC.getValue(),
171 //                           weight,
172 //                           weightBeforeSampling,
173 //                           (short) 1);
174 //    }
175 
176     public SortingBatch getOrCreateSpeciesVracRootBatch(CatchBatch target, SortingBatch batch, Float totalWeight) {
177         return speciesBatchTreeHelper.getOrCreateVracRootBatch(target, batch, totalWeight);
178 //                target,
179 //                batch,
180 //                "Vrac > Species",
181 //                SORTING_TYPE_ID,
182 //                QualitativeValueId.SORTING_TYPE_SPECIES.getValue(),
183 //                totalWeight,
184 //                (short) 1
185 //        );
186     }
187 
188     public SortingBatch getOrCreateSpeciesVracAliveNotItemizedRootBatch(CatchBatch target, SortingBatch batch, Float totalWeight) {
189         return speciesBatchTreeHelper.getOrCreateVracAliveNotItemizedRootBatch(target, batch, totalWeight);
190 //        return getOrCreate(
191 //                target,
192 //                batch,
193 //                "Vrac > Species > Alive Not Itemized",
194 //                SORTING_TYPE2_ID,
195 //                QualitativeValueId.SORTING_TYPE2_ALIVE_NOT_ITEMIZED.getValue(),
196 //                totalWeight,
197 //                (short) 1
198 //        );
199     }
200 
201     public SortingBatch getOrCreateSpeciesVracInertRootBatch(CatchBatch target, SortingBatch batch, Float totalWeight) {
202         return speciesBatchTreeHelper.getOrCreateVracInertRootBatch(target, batch, totalWeight);
203 //        return getOrCreate(
204 //                target,
205 //                batch,
206 //                "Vrac > Species > Inert",
207 //                SORTING_TYPE2_ID,
208 //                QualitativeValueId.SORTING_TYPE2_INERT.getValue(),
209 //                totalWeight,
210 //                (short) 2
211 //        );
212     }
213 
214     public SortingBatch getOrCreateSpeciesVracAliveItemizedRootBatch(CatchBatch target, SortingBatch batch) {
215         return speciesBatchTreeHelper.getOrCreateVracAliveItemizedRootBatch(target, batch);
216 //        return getOrCreate(
217 //                target,
218 //                batch,
219 //                "Vrac > Benthos > Alive Itemized",
220 //                SORTING_TYPE2_ID,
221 //                QualitativeValueId.SORTING_TYPE2_ALIVE_ITEMIZED.getValue(),
222 //                (short) 3
223 //        );
224     }
225 
226     public SortingBatch getOrCreateBenthosVracRootBatch(CatchBatch target, SortingBatch batch, Float totalWeight) {
227         return benthosBatchTreeHelper.getOrCreateVracRootBatch(target, batch, totalWeight);
228 //        return getOrCreate(
229 //                target,
230 //                batch,
231 //                "Vrac > Benthos",
232 //                SORTING_TYPE_ID,
233 //                QualitativeValueId.SORTING_TYPE_BENTHOS.getValue(),
234 //                totalWeight,
235 //                (short) 2
236 //        );
237     }
238 
239     public SortingBatch getOrCreateBenthosVracAliveNotItemizedRootBatch(CatchBatch target, SortingBatch batch, Float totalWeight) {
240         return benthosBatchTreeHelper.getOrCreateVracAliveNotItemizedRootBatch(target, batch, totalWeight);
241 //        return getOrCreate(
242 //                target,
243 //                batch,
244 //                "Vrac > Benthos > Alive Not itemized",
245 //                SORTING_TYPE2_ID,
246 //                QualitativeValueId.SORTING_TYPE2_ALIVE_NOT_ITEMIZED.getValue(),
247 //                totalWeight,
248 //                (short) 1
249 //        );
250     }
251 
252     public SortingBatch getOrCreateBenthosVracInertRootBatch(CatchBatch target, SortingBatch batch, Float totalWeight) {
253         return benthosBatchTreeHelper.getOrCreateVracInertRootBatch(target, batch, totalWeight);
254 //        return getOrCreate(
255 //                target,
256 //                batch,
257 //                "Vrac > Benthos > Inert",
258 //                SORTING_TYPE2_ID,
259 //                QualitativeValueId.SORTING_TYPE2_INERT.getValue(),
260 //                totalWeight,
261 //                (short) 2
262 //        );
263     }
264 
265     public SortingBatch getOrCreateBenthosVracAliveItemizedRootBatch(CatchBatch target, SortingBatch batch) {
266         return benthosBatchTreeHelper.getOrCreateVracAliveItemizedRootBatch(target, batch);
267 //        return getOrCreate(
268 //                target,
269 //                batch,
270 //                "Vrac > Benthos > Alive Itemized",
271 //                SORTING_TYPE2_ID,
272 //                QualitativeValueId.SORTING_TYPE2_ALIVE_ITEMIZED.getValue(),
273 //                (short) 3
274 //        );
275     }
276 
277 //    public SortingBatch getOrCreateHorsVracBatch(CatchBatch batch) {
278 //        return getOrCreate(batch,
279 //                           batch,
280 //                "Hors Vrac",
281 //                PmfmId.SORTED_UNSORTED.getValue(),
282 //                QualitativeValueId.SORTED_HORS_VRAC.getValue(),
283 //                (short) 2);
284 //    }
285 
286     public SortingBatch getOrCreateSpeciesHorsVracRootBatch(CatchBatch target, SortingBatch batch) {
287         return speciesBatchTreeHelper.getOrCreateHorsVracRootBatch(target, batch);
288 //        return getOrCreate(
289 //                target,
290 //                batch,
291 //                "Hors Vrac > Species",
292 //                SORTING_TYPE_ID,
293 //                QualitativeValueId.SORTING_TYPE_SPECIES.getValue(),
294 //                (short) 1
295 //        );
296     }
297 
298     public SortingBatch getOrCreateBenthosHorsVracRootBatch(CatchBatch target, SortingBatch batch) {
299         return benthosBatchTreeHelper.getOrCreateHorsVracRootBatch(target, batch);
300 //        return getOrCreate(
301 //                target,
302 //                batch,
303 //                "Hors Vrac > Benthos",
304 //                SORTING_TYPE_ID,
305 //                QualitativeValueId.SORTING_TYPE_BENTHOS.getValue(),
306 //                (short) 2
307 //        );
308     }
309 
310     public SortingBatch getOrCreateMarineLitterRootBatch(CatchBatch target, SortingBatch batch, Float totalWeight) {
311         return getOrCreate(target,
312                            batch,
313                            "Hors Vrac > Marine Litter",
314                            SORTING_TYPE_ID,
315                            QualitativeValueId.SORTING_TYPE_MARINE_LITTER.getValue(),
316                            totalWeight,
317                            (short) 3);
318     }
319 
320     public SortingBatch getOrCreateRejectedBatch(CatchBatch batch, Float weight) {
321         return getOrCreate(batch,
322                            batch,
323                            "Unsorted",
324                            PmfmId.SORTED_UNSORTED.getValue(),
325                            QualitativeValueId.UNSORTED.getValue(),
326                            weight,
327                            (short) 3);
328     }
329 
330 }