View Javadoc
1   package fr.ifremer.tutti.persistence;
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 com.google.common.base.Predicate;
26  import com.google.common.collect.ImmutableSet;
27  import com.google.common.collect.Lists;
28  import com.google.common.collect.Maps;
29  import com.google.common.collect.Multimap;
30  import fr.ifremer.adagio.core.dao.referential.ObjectTypeCode;
31  import fr.ifremer.tutti.TuttiConfiguration;
32  import fr.ifremer.tutti.persistence.entities.CaracteristicMap;
33  import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch;
34  import fr.ifremer.tutti.persistence.entities.data.Attachment;
35  import fr.ifremer.tutti.persistence.entities.data.BatchContainer;
36  import fr.ifremer.tutti.persistence.entities.data.CatchBatch;
37  import fr.ifremer.tutti.persistence.entities.data.Cruise;
38  import fr.ifremer.tutti.persistence.entities.data.Cruises;
39  import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
40  import fr.ifremer.tutti.persistence.entities.data.FishingOperations;
41  import fr.ifremer.tutti.persistence.entities.data.IndividualObservationBatch;
42  import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch;
43  import fr.ifremer.tutti.persistence.entities.data.Program;
44  import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch;
45  import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency;
46  import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol;
47  import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
48  import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocols;
49  import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
50  import fr.ifremer.tutti.persistence.entities.referential.Gear;
51  import fr.ifremer.tutti.persistence.entities.referential.ObjectType;
52  import fr.ifremer.tutti.persistence.entities.referential.Person;
53  import fr.ifremer.tutti.persistence.entities.referential.Species;
54  import fr.ifremer.tutti.persistence.entities.referential.TuttiLocation;
55  import fr.ifremer.tutti.persistence.entities.referential.TuttiReferentialEntity;
56  import fr.ifremer.tutti.persistence.entities.referential.Vessel;
57  import fr.ifremer.tutti.persistence.model.CruiseDataModel;
58  import fr.ifremer.tutti.persistence.model.OperationDataModel;
59  import fr.ifremer.tutti.persistence.model.ProgramDataModel;
60  import fr.ifremer.tutti.persistence.service.AccidentalBatchPersistenceService;
61  import fr.ifremer.tutti.persistence.service.AttachmentPersistenceService;
62  import fr.ifremer.tutti.persistence.service.BenthosBatchPersistenceService;
63  import fr.ifremer.tutti.persistence.service.CatchBatchPersistenceService;
64  import fr.ifremer.tutti.persistence.service.CruisePersistenceService;
65  import fr.ifremer.tutti.persistence.service.FishingOperationPersistenceService;
66  import fr.ifremer.tutti.persistence.service.IndividualObservationBatchPersistenceService;
67  import fr.ifremer.tutti.persistence.service.MarineLitterBatchPersistenceService;
68  import fr.ifremer.tutti.persistence.service.ProgramPersistenceService;
69  import fr.ifremer.tutti.persistence.service.ProtocolPersistenceService;
70  import fr.ifremer.tutti.persistence.service.SpeciesBatchPersistenceService;
71  import fr.ifremer.tutti.persistence.service.TechnicalPersistenceService;
72  import fr.ifremer.tutti.persistence.service.TuttiPersistenceServiceLocator;
73  import fr.ifremer.tutti.persistence.service.UpdateSchemaContextSupport;
74  import fr.ifremer.tutti.persistence.service.referential.CaracteristicPersistenceService;
75  import fr.ifremer.tutti.persistence.service.referential.GearPersistenceService;
76  import fr.ifremer.tutti.persistence.service.referential.LocationPersistenceService;
77  import fr.ifremer.tutti.persistence.service.referential.ObjectTypePersistenceService;
78  import fr.ifremer.tutti.persistence.service.referential.PersonPersistenceService;
79  import fr.ifremer.tutti.persistence.service.referential.SpeciesPersistenceService;
80  import fr.ifremer.tutti.persistence.service.referential.VesselPersistenceService;
81  import fr.ifremer.tutti.util.Jdbcs;
82  import org.apache.commons.lang3.StringUtils;
83  import org.apache.commons.logging.Log;
84  import org.apache.commons.logging.LogFactory;
85  import org.nuiton.version.Version;
86  
87  import javax.annotation.Resource;
88  import java.io.File;
89  import java.io.IOException;
90  import java.sql.SQLException;
91  import java.util.ArrayList;
92  import java.util.Arrays;
93  import java.util.Collection;
94  import java.util.Collections;
95  import java.util.LinkedHashSet;
96  import java.util.List;
97  import java.util.Map;
98  import java.util.Set;
99  import java.util.concurrent.Callable;
100 
101 /**
102  * @author Tony Chemit - chemit@codelutin.com
103  * @since 0.2
104  */
105 public class TuttiPersistenceImpl implements TuttiPersistence {
106 
107     /** Logger. */
108     private static final Log log =
109             LogFactory.getLog(TuttiPersistenceImpl.class);
110 
111     @Resource(name = "caracteristicPersistenceService")
112     protected CaracteristicPersistenceService caracteristicService;
113 
114     @Resource(name = "gearPersistenceService")
115     protected GearPersistenceService gearService;
116 
117     @Resource(name = "locationPersistenceService")
118     protected LocationPersistenceService locationService;
119 
120     @Resource(name = "objectTypePersistenceService")
121     protected ObjectTypePersistenceService objectTypeService;
122 
123     @Resource(name = "personPersistenceService")
124     protected PersonPersistenceService personService;
125 
126     @Resource(name = "speciesPersistenceService")
127     protected SpeciesPersistenceService speciesService;
128 
129     @Resource(name = "vesselPersistenceService")
130     protected VesselPersistenceService vesselService;
131 
132     @Resource(name = "programPersistenceService")
133     protected ProgramPersistenceService programService;
134 
135     @Resource(name = "cruisePersistenceService")
136     protected CruisePersistenceService cruiseService;
137 
138     @Resource(name = "fishingOperationPersistenceService")
139     protected FishingOperationPersistenceService fishingOperationService;
140 
141     @Resource(name = "batchPersistenceService")
142     protected CatchBatchPersistenceService catchBatchService;
143 
144     @Resource(name = "speciesBatchPersistenceService")
145     protected SpeciesBatchPersistenceService speciesBatchService;
146 
147     @Resource(name = "benthosBatchPersistenceService")
148     protected BenthosBatchPersistenceService benthosBatchService;
149 
150     @Resource(name = "marineLitterBatchPersistenceService")
151     protected MarineLitterBatchPersistenceService marineLitterBatchService;
152 
153     @Resource(name = "accidentalBatchPersistenceService")
154     protected AccidentalBatchPersistenceService accidentalBatchService;
155 
156     @Resource(name = "individualObservationBatchPersistenceService")
157     protected IndividualObservationBatchPersistenceService individualObservationBatchService;
158 
159     @Resource(name = "protocolPersistenceService")
160     protected ProtocolPersistenceService protocolService;
161 
162     @Resource(name = "attachmentPersistenceService")
163     protected AttachmentPersistenceService attachmentService;
164 
165     @Resource(name = "technicalPersistenceService")
166     protected TechnicalPersistenceService technicalPersistenceService;
167 
168     private boolean skipShutdownDbWhenClosing;
169 
170     @Override
171     public String getImplementationName() {
172         return "Persistence Adagio implementation";
173     }
174 
175     @Override
176     public void setSkipShutdownDbWhenClosing() {
177         this.skipShutdownDbWhenClosing = true;
178     }
179 
180     @Override
181     public void lazyInit() {
182         // this service does not used lazy init
183     }
184 
185     @Override
186     public void clearAllCaches() {
187         getTechnicalPersistenceService().clearAllCaches();
188     }
189 
190     @Override
191     public <V> V invoke(Callable<V> call) {
192         return getTechnicalPersistenceService().invoke(call);
193     }
194 
195     @Override
196     public <U extends UpdateSchemaContextSupport> void prepareUpdateSchemaContext(U context) {
197         getTechnicalPersistenceService().prepareUpdateSchemaContext(context);
198     }
199 
200     @Override
201     public Version getSchemaVersion() {
202         return getTechnicalPersistenceService().getSchemaVersion();
203     }
204 
205     @Override
206     public Version getSchemaVersionIfUpdate() {
207         return getTechnicalPersistenceService().getSchemaVersionIfUpdate();
208     }
209 
210     @Override
211     public void updateSchema() {
212         getTechnicalPersistenceService().updateSchema();
213     }
214 
215     @Override
216     public void sanityDb() {
217         getTechnicalPersistenceService().sanityDb();
218     }
219 
220     @Override
221     public boolean isTemporary(TuttiReferentialEntity entity) {
222         return getTechnicalPersistenceService().isTemporary(entity);
223     }
224 
225     @Override
226     public void init() {
227         if (log.isInfoEnabled()) {
228             log.info("Open persistence driver " + getImplementationName());
229         }
230 
231     }
232 
233     protected boolean close;
234 
235     @Override
236     public void close() throws IOException {
237 
238         if (!close) {
239 
240             close = true;
241             synchronized (this) {
242                 if (log.isInfoEnabled()) {
243                     log.info("Close persistence driver " + getImplementationName());
244                 }
245 
246                 caracteristicService.close();
247                 gearService.close();
248                 locationService.close();
249                 objectTypeService.close();
250                 personService.close();
251                 speciesService.close();
252                 vesselService.close();
253 
254                 programService.close();
255                 cruiseService.close();
256                 fishingOperationService.close();
257                 catchBatchService.close();
258                 speciesBatchService.close();
259                 benthosBatchService.close();
260                 marineLitterBatchService.close();
261                 accidentalBatchService.close();
262                 individualObservationBatchService.close();
263                 protocolService.close();
264                 attachmentService.close();
265 
266                 if (skipShutdownDbWhenClosing) {
267 
268                     if (log.isInfoEnabled()) {
269                         log.info("Skip to shutdown db while closing, lucky you...");
270                     }
271 
272                 } else {
273 
274                     if (log.isInfoEnabled()) {
275                         log.info("Do shutdown db nicely");
276                     }
277                     try {
278                         Jdbcs.shutdown(TuttiConfiguration.getInstance());
279                     } catch (SQLException e) {
280                         if (log.isErrorEnabled()) {
281                             log.error("Could not shutdown the database", e);
282                         }
283                     }
284 
285                 }
286 
287 
288                 TuttiPersistenceServiceLocator.shutdownTutti();
289             }
290         }
291     }
292 
293     @Override
294     public ProgramDataModel loadProgram(String programId, boolean loadFishingOperation) {
295 
296         Program program = getProgram(programId);
297 
298         Set<CruiseDataModel> cruiseModels = new LinkedHashSet<>();
299         List<Cruise> cruises = new ArrayList<>(getAllCruise(programId));
300         Cruises.sort(cruises);
301         for (Cruise cruise : cruises) {
302             List<Integer> fishingOperationIds = loadFishingOperation ? getAllFishingOperationIds(cruise.getIdAsInt()) : Collections.<Integer>emptyList();
303             CruiseDataModel model = loadCruise(cruise, fishingOperationIds);
304             cruiseModels.add(model);
305         }
306 
307         return new ProgramDataModel(program, cruiseModels);
308 
309     }
310 
311     @Override
312     public ProgramDataModel loadCruises(String programId, boolean loadFishingOperation, Integer... cruiseIds) {
313 
314         Program program = getProgram(programId);
315 
316         Set<CruiseDataModel> cruiseModels = new LinkedHashSet<>();
317         for (Integer cruiseId : cruiseIds) {
318             Cruise cruise = getCruise(cruiseId);
319             List<Integer> fishingOperationIds = loadFishingOperation ? getAllFishingOperationIds(cruise.getIdAsInt()) : Collections.<Integer>emptyList();
320             CruiseDataModel model = loadCruise(cruise, fishingOperationIds);
321             cruiseModels.add(model);
322         }
323 
324         return new ProgramDataModel(program, cruiseModels);
325 
326     }
327 
328     @Override
329     public ProgramDataModel loadCruise(String programId, Integer cruiseId, Integer... fishingOperationIds) {
330 
331         Program program = getProgram(programId);
332 
333         Set<CruiseDataModel> cruiseModels = new LinkedHashSet<>();
334         Cruise cruise = getCruise(cruiseId);
335         CruiseDataModel model = loadCruise(cruise, Arrays.asList(fishingOperationIds));
336         cruiseModels.add(model);
337 
338         return new ProgramDataModel(program, cruiseModels);
339 
340     }
341 
342     protected CruiseDataModel loadCruise(Cruise cruise, List<Integer> fishingOperationIds) {
343 
344         Set<OperationDataModel> fishingOperationModels = new LinkedHashSet<>();
345 
346         List<FishingOperation> fishingOperations = new ArrayList<>(getAllFishingOperation(cruise.getIdAsInt()));
347         FishingOperations.sort(fishingOperations);
348         fishingOperations.stream().filter(fishingOperation -> fishingOperationIds.contains(fishingOperation.getIdAsInt())).forEach(fishingOperation -> {
349             OperationDataModel model = new OperationDataModel(fishingOperation);
350             fishingOperationModels.add(model);
351         });
352 
353         return new CruiseDataModel(cruise, fishingOperationModels);
354 
355     }
356 
357     //------------------------------------------------------------------------//
358     //-- CaracteristicPersistenceService methods                            --//
359     //------------------------------------------------------------------------//
360 
361     @Override
362     public List<Caracteristic> getAllCaracteristic() {
363         return getCaracteristicService().getAllCaracteristic();
364     }
365 
366     @Override
367     public List<Caracteristic> getAllCaracteristicWithProtected() {
368         return getCaracteristicService().getAllCaracteristicWithProtected();
369     }
370 
371     @Override
372     public List<Caracteristic> getAllCaracteristicForSampleCategory() {
373         return getCaracteristicService().getAllCaracteristicForSampleCategory();
374     }
375 
376     @Override
377     public List<Caracteristic> getAllNumericCaracteristic() {
378         return getCaracteristicService().getAllNumericCaracteristic();
379     }
380 
381     @Override
382     public Caracteristic getSizeCategoryCaracteristic() {
383         return getCaracteristicService().getSizeCategoryCaracteristic();
384     }
385 
386     @Override
387     public Caracteristic getSexCaracteristic() {
388         return getCaracteristicService().getSexCaracteristic();
389     }
390 
391     @Override
392     public Caracteristic getSortedUnsortedCaracteristic() {
393         return getCaracteristicService().getSortedUnsortedCaracteristic();
394     }
395 
396     @Override
397     public Caracteristic getMaturityCaracteristic() {
398         return getCaracteristicService().getMaturityCaracteristic();
399     }
400 
401     @Override
402     public Caracteristic getAgeCaracteristic() {
403         return getCaracteristicService().getAgeCaracteristic();
404     }
405 
406     @Override
407     public Caracteristic getMarineLitterCategoryCaracteristic() {
408         return getCaracteristicService().getMarineLitterCategoryCaracteristic();
409     }
410 
411     @Override
412     public Caracteristic getMarineLitterSizeCategoryCaracteristic() {
413         return getCaracteristicService().getMarineLitterSizeCategoryCaracteristic();
414     }
415 
416     @Override
417     public Caracteristic getVerticalOpeningCaracteristic() {
418         return getCaracteristicService().getVerticalOpeningCaracteristic();
419     }
420 
421     @Override
422     public Caracteristic getHorizontalOpeningWingsCaracteristic() {
423         return getCaracteristicService().getHorizontalOpeningWingsCaracteristic();
424     }
425 
426     @Override
427     public Caracteristic getHorizontalOpeningDoorCaracteristic() {
428         return getCaracteristicService().getHorizontalOpeningDoorCaracteristic();
429     }
430 
431     @Override
432     public Caracteristic getDeadOrAliveCaracteristic() {
433         return getCaracteristicService().getDeadOrAliveCaracteristic();
434     }
435 
436     @Override
437     public Caracteristic getCalcifiedStructureCaracteristic() {
438         return getCaracteristicService().getCalcifiedStructureCaracteristic();
439     }
440 
441     @Override
442     public Caracteristic getPmfmIdCaracteristic() {
443         return getCaracteristicService().getPmfmIdCaracteristic();
444     }
445 
446     @Override
447     public Caracteristic getWeightMeasuredCaracteristic() {
448         return getCaracteristicService().getWeightMeasuredCaracteristic();
449     }
450 
451     @Override
452     public Caracteristic getCopyIndividualObservationModeCaracteristic() {
453         return getCaracteristicService().getCopyIndividualObservationModeCaracteristic();
454     }
455 
456     @Override
457     public Caracteristic getSampleCodeCaracteristic() {
458         return getCaracteristicService().getSampleCodeCaracteristic();
459     }
460 
461     @Override
462     public Caracteristic getCaracteristic(Integer pmfmId) {
463         return getCaracteristicService().getCaracteristic(pmfmId);
464     }
465 
466     @Override
467     public boolean isVracBatch(SpeciesBatch speciesBatch) {
468         return getCaracteristicService().isVracBatch(speciesBatch);
469     }
470 
471     @Override
472     public Predicate<SpeciesBatch> getVracBatchPredicate() {
473         return getCaracteristicService().getVracBatchPredicate();
474     }
475 
476     @Override
477     public boolean isHorsVracBatch(SpeciesBatch speciesBatch) {
478         return getCaracteristicService().isHorsVracBatch(speciesBatch);
479     }
480 
481     //------------------------------------------------------------------------//
482     //-- LocationPersistenceService methods                                 --//
483     //------------------------------------------------------------------------//
484 
485     @Override
486     public List<TuttiLocation> getAllProgramZone() {
487         return getLocationService().getAllProgramZone();
488     }
489 
490     @Override
491     public List<TuttiLocation> getAllCountry() {
492         return getLocationService().getAllCountry();
493     }
494 
495     @Override
496     public List<TuttiLocation> getAllHarbour() {
497         return getLocationService().getAllHarbour();
498     }
499 
500     @Override
501     public List<TuttiLocation> getAllHarbourWithObsoletes() {
502         return getLocationService().getAllHarbourWithObsoletes();
503     }
504 
505     @Override
506     public ImmutableSet<Integer> getAllFishingOperationStratasAndSubstratasIdsForProgram(String zoneId) {
507         return getLocationService().getAllFishingOperationStratasAndSubstratasIdsForProgram(zoneId);
508     }
509 
510     @Override
511     public Multimap<TuttiLocation, TuttiLocation> getAllFishingOperationStratasAndSubstratas(String zoneId) {
512         return getLocationService().getAllFishingOperationStratasAndSubstratas(zoneId);
513     }
514 
515     @Override
516     public List<TuttiLocation> getAllFishingOperationStrata(String zoneId) {
517         return getLocationService().getAllFishingOperationStrata(zoneId);
518     }
519 
520     @Override
521     public List<TuttiLocation> getAllFishingOperationStrataWithObsoletes(String zoneId) {
522         return getLocationService().getAllFishingOperationStrataWithObsoletes(zoneId);
523     }
524 
525     @Override
526     public List<TuttiLocation> getAllFishingOperationSubStrata(String zoneId,
527                                                                String strataId) {
528         return getLocationService().getAllFishingOperationSubStrata(zoneId, strataId);
529     }
530 
531     @Override
532     public List<TuttiLocation> getAllFishingOperationSubStrataWithObsoletes(String zoneId, String strataId) {
533         return getLocationService().getAllFishingOperationSubStrataWithObsoletes(zoneId, strataId);
534     }
535 
536     @Override
537     public List<TuttiLocation> getAllFishingOperationLocation(String zoneId,
538                                                               String strataId,
539                                                               String subStrataId) {
540         return getLocationService().getAllFishingOperationLocation(zoneId,
541                                                                    strataId,
542                                                                    subStrataId);
543     }
544 
545     @Override
546     public List<TuttiLocation> getAllFishingOperationLocationWithObsoletes(String zoneId, String strataId, String subStrataId) {
547         return getLocationService().getAllFishingOperationLocationWithObsoletes(zoneId,
548                 strataId,
549                 subStrataId);
550     }
551 
552     @Override
553     public String getLocationLabelByLatLong(Float latitude, Float longitude) {
554         return getLocationService().getLocationLabelByLatLong(latitude, longitude);
555     }
556 
557     @Override
558     public Integer getLocationIdByLatLong(Float latitude, Float longitude) {
559         return getLocationService().getLocationIdByLatLong(latitude, longitude);
560     }
561 
562     @Override
563     public TuttiLocation getLocation(String id) {
564         return getLocationService().getLocation(id);
565     }
566 
567     //------------------------------------------------------------------------//
568     //-- ObjectTypePersistenceService methods                               --//
569     //------------------------------------------------------------------------//
570 
571     @Override
572     public List<ObjectType> getAllObjectType() {
573         return getObjectTypeService().getAllObjectType();
574     }
575 
576     @Override
577     public ObjectType getObjectType(String objectTypeCode) {
578         return getObjectTypeService().getObjectType(objectTypeCode);
579     }
580 
581     //------------------------------------------------------------------------//
582     //-- GearPersistenceService methods                                     --//
583     //------------------------------------------------------------------------//
584 
585     @Override
586     public List<Gear> getAllScientificGear() {
587         return getGearService().getAllScientificGear();
588     }
589 
590     @Override
591     public List<Gear> getAllFishingGear() {
592         return getGearService().getAllFishingGear();
593     }
594 
595     @Override
596     public List<Gear> getAllGearWithObsoletes() {
597         return getGearService().getAllGearWithObsoletes();
598     }
599 
600     @Override
601     public Gear getGear(Integer gearId) {
602         return getGearService().getGear(gearId);
603     }
604 
605     @Override
606     public boolean isTemporaryGearUsed(Integer id) {
607         return getGearService().isTemporaryGearUsed(id);
608     }
609 
610     @Override
611     public List<Gear> addTemporaryGears(List<Gear> gears) {
612         return getGearService().addTemporaryGears(gears);
613     }
614 
615     @Override
616     public List<Gear> updateTemporaryGears(List<Gear> gears) {
617         return getGearService().updateTemporaryGears(gears);
618     }
619 
620     @Override
621     public List<Gear> linkTemporaryGears(List<Gear> gears) {
622         return getGearService().linkTemporaryGears(gears);
623     }
624 
625     @Override
626     public void replaceGear(Gear source, Gear target, boolean delete) {
627         getGearService().replaceGear(source, target, delete);
628     }
629 
630     @Override
631     public void deleteTemporaryGear(Integer id) {
632         getGearService().deleteTemporaryGear(id);
633     }
634 
635     @Override
636     public void deleteTemporaryGears(Collection<Integer> id) {
637         getGearService().deleteTemporaryGears(id);
638     }
639 
640     //------------------------------------------------------------------------//
641     //-- SpeciesPersistenceService methods                                  --//
642     //------------------------------------------------------------------------//
643 
644     @Override
645     public List<Species> getAllSpecies() {
646         List<Species> result = getSpeciesService().getAllSpecies();
647         setSpeciesSurveyCode(result, getProtocol());
648         return result;
649     }
650 
651     @Override
652     public List<Species> getAllReferentSpecies() {
653         List<Species> result = getSpeciesService().getAllReferentSpecies();
654         setSpeciesSurveyCode(result, getProtocol());
655         return result;
656     }
657 
658     @Override
659     public List<Species> getAllReferentSpeciesWithObsoletes() {
660         List<Species> result = getSpeciesService().getAllReferentSpeciesWithObsoletes();
661         setSpeciesSurveyCode(result, getProtocol());
662         return result;
663     }
664 
665     @Override
666     public Species getSpeciesByReferenceTaxonIdWithVernacularCode(Integer referenceTaxonId) {
667         return getSpeciesService().getSpeciesByReferenceTaxonIdWithVernacularCode(referenceTaxonId);
668     }
669 
670     @Override
671     public Species getSpeciesByReferenceTaxonId(Integer referenceTaxonId) {
672         return getSpeciesService().getSpeciesByReferenceTaxonId(referenceTaxonId);
673     }
674 
675     @Override
676     public Map<Integer, Integer> getAllObsoleteReferentTaxons() {
677         return getSpeciesService().getAllObsoleteReferentTaxons();
678     }
679 
680     @Override
681     public boolean isTemporarySpeciesUsed(Integer referenceTaxonId) {
682 
683         TuttiProtocol protocol = getProtocol();
684 
685         if (protocol != null) {
686 
687             // check first if species is used in protocol
688 
689             SpeciesProtocol speciesProtocol = TuttiProtocols.getSpeciesOrBenthosProtocol(protocol, referenceTaxonId);
690             if (speciesProtocol != null) {
691 
692                 // used in species or benthos protocol
693                 return true;
694             }
695 
696         }
697         return getSpeciesService().isTemporarySpeciesUsed(referenceTaxonId);
698     }
699 
700     @Override
701     public List<Species> addTemporarySpecies(List<Species> species) {
702         return getSpeciesService().addTemporarySpecies(species);
703     }
704 
705     @Override
706     public List<Species> updateTemporarySpecies(List<Species> species) {
707         return getSpeciesService().updateTemporarySpecies(species);
708     }
709 
710     @Override
711     public List<Species> linkTemporarySpecies(List<Species> species) {
712         return getSpeciesService().linkTemporarySpecies(species);
713     }
714 
715     @Override
716     public void replaceSpecies(Species source, Species target, boolean delete) {
717 
718         getSpeciesService().replaceSpecies(source, target, delete);
719 
720         if (delete) {
721             removeSpeciesFromProtocol(Lists.newArrayList(source.getReferenceTaxonId()));
722         }
723 
724     }
725 
726     @Override
727     public void deleteTemporarySpecies(Integer referenceTaxonId) {
728 
729         getSpeciesService().deleteTemporarySpecies(referenceTaxonId);
730         removeSpeciesFromProtocol(Lists.newArrayList(referenceTaxonId));
731 
732     }
733 
734     @Override
735     public void deleteTemporarySpecies(Collection<Integer> referenceTaxonIds) {
736 
737         getSpeciesService().deleteTemporarySpecies(referenceTaxonIds);
738 
739         removeSpeciesFromProtocol(referenceTaxonIds);
740 
741     }
742 
743     protected void removeSpeciesFromProtocol(Collection<Integer> referenceTaxonIds) {
744 
745         TuttiProtocol protocol = getProtocol();
746 
747         if (protocol != null) {
748 
749             boolean wasRemoved = false;
750 
751             for (Integer referenceTaxonId : referenceTaxonIds) {
752 
753                 wasRemoved |= TuttiProtocols.removeSpeciesOrBenthosProtocol(protocol, referenceTaxonId);
754 
755             }
756 
757             if (wasRemoved) {
758 
759                 if (log.isInfoEnabled()) {
760                     log.info("Save protocol (some species or benthos were removed from it.)");
761                 }
762                 saveProtocol(protocol);
763 
764             }
765 
766         }
767 
768     }
769 
770     //------------------------------------------------------------------------//
771     //-- PersonPersistenceService methods                                   --//
772     //------------------------------------------------------------------------//
773 
774     @Override
775     public List<Person> getAllPerson() {
776         return getPersonService().getAllPerson();
777     }
778 
779     @Override
780     public List<Person> getAllPersonWithObsoletes() {
781         return getPersonService().getAllPersonWithObsoletes();
782     }
783 
784     @Override
785     public Person getPerson(Integer personId) {
786         return getPersonService().getPerson(personId);
787     }
788 
789     @Override
790     public boolean isTemporaryPersonUsed(Integer id) {
791         return getPersonService().isTemporaryPersonUsed(id);
792     }
793 
794     @Override
795     public List<Person> addTemporaryPersons(List<Person> persons) {
796         return getPersonService().addTemporaryPersons(persons);
797     }
798 
799     @Override
800     public List<Person> updateTemporaryPersons(List<Person> persons) {
801         return getPersonService().updateTemporaryPersons(persons);
802     }
803 
804     @Override
805     public List<Person> linkTemporaryPersons(List<Person> persons) {
806         return getPersonService().linkTemporaryPersons(persons);
807     }
808 
809     @Override
810     public void replacePerson(Person source, Person target, boolean delete) {
811         getPersonService().replacePerson(source, target, delete);
812     }
813 
814     @Override
815     public void deleteTemporaryPerson(Integer id) {
816         getPersonService().deleteTemporaryPerson(id);
817     }
818 
819     @Override
820     public void deleteTemporaryPersons(Collection<Integer> ids) {
821         getPersonService().deleteTemporaryPersons(ids);
822     }
823 
824     //------------------------------------------------------------------------//
825     //-- VesselPersistenceService methods                                   --//
826     //------------------------------------------------------------------------//
827 
828     @Override
829     public List<Vessel> getAllScientificVessel() {
830         return getVesselService().getAllScientificVessel();
831     }
832 
833     @Override
834     public List<Vessel> getAllFishingVessel() {
835         return getVesselService().getAllFishingVessel();
836     }
837 
838     @Override
839     public List<Vessel> getAllVesselWithObsoletes() {
840         return getVesselService().getAllVesselWithObsoletes();
841     }
842 
843     @Override
844     public Vessel getVessel(String vesselCode) {
845         return getVesselService().getVessel(vesselCode);
846     }
847 
848     @Override
849     public boolean isTemporaryVesselUsed(String code) {
850         return getVesselService().isTemporaryVesselUsed(code);
851     }
852 
853     @Override
854     public List<Vessel> addTemporaryVessels(List<Vessel> vessels) {
855         return getVesselService().addTemporaryVessels(vessels);
856     }
857 
858     @Override
859     public List<Vessel> updateTemporaryVessels(List<Vessel> vessels) {
860         return getVesselService().updateTemporaryVessels(vessels);
861     }
862 
863     @Override
864     public List<Vessel> linkTemporaryVessels(List<Vessel> vessels) {
865         return getVesselService().linkTemporaryVessels(vessels);
866     }
867 
868     @Override
869     public void replaceVessel(Vessel source, Vessel target, boolean delete) {
870         getVesselService().replaceVessel(source, target, delete);
871     }
872 
873     @Override
874     public void deleteTemporaryVessel(String code) {
875         getVesselService().deleteTemporaryVessel(code);
876     }
877 
878     @Override
879     public void deleteTemporaryVessels(Collection<String> codes) {
880         getVesselService().deleteTemporaryVessels(codes);
881     }
882 
883     //------------------------------------------------------------------------//
884     //-- Attachment methods                                                 --//
885     //------------------------------------------------------------------------//
886 
887     @Override
888     public List<Attachment> getAllAttachments(ObjectTypeCode objectType,
889                                               Integer objectId) {
890         return getAttachmentService().getAllAttachments(objectType, objectId);
891     }
892 
893     @Override
894     public File getAttachmentFile(String attachmentId) {
895         return getAttachmentService().getAttachmentFile(attachmentId);
896     }
897 
898     @Override
899     public Attachment createAttachment(Attachment attachment, File file) {
900         return getAttachmentService().createAttachment(attachment, file);
901     }
902 
903     @Override
904     public Attachment saveAttachment(Attachment attachment) {
905         return getAttachmentService().saveAttachment(attachment);
906     }
907 
908     @Override
909     public void deleteAttachment(String attachmentId) {
910         getAttachmentService().deleteAttachment(attachmentId);
911     }
912 
913     @Override
914     public void deleteAllAttachment(ObjectTypeCode objectType, Integer objectId) {
915         getAttachmentService().deleteAllAttachment(objectType, objectId);
916     }
917 
918     @Override
919     public void deleteAllAttachment(ObjectTypeCode objectType, Set<Integer> objectIds) {
920         getAttachmentService().deleteAllAttachment(objectType, objectIds);
921     }
922 
923     //------------------------------------------------------------------------//
924     //-- Program methods                                                    --//
925     //------------------------------------------------------------------------//
926 
927     @Override
928     public List<Program> getAllProgram() {
929         return getProgramService().getAllProgram();
930     }
931 
932     @Override
933     public Program getProgram(String id) {
934         return getProgramService().getProgram(id);
935     }
936 
937     @Override
938     public Program createProgram(Program bean) {
939         return getProgramService().createProgram(bean);
940     }
941 
942     @Override
943     public Program saveProgram(Program bean) {
944         return getProgramService().saveProgram(bean);
945     }
946 
947     //------------------------------------------------------------------------//
948     //-- Cruise methods                                                     --//
949     //------------------------------------------------------------------------//
950 
951 
952     @Override
953     public List<Integer> getAllCruiseId(String programId) {
954         return getCruiseService().getAllCruiseId(programId);
955     }
956 
957     @Override
958     public List<Cruise> getAllCruise(String programId) {
959         return getCruiseService().getAllCruise(programId);
960     }
961 
962     @Override
963     public Cruise getCruise(Integer id) {
964         return getCruiseService().getCruise(id);
965     }
966 
967     @Override
968     public Cruise createCruise(Cruise bean) {
969         return getCruiseService().createCruise(bean);
970     }
971 
972     @Override
973     public Cruise saveCruise(Cruise bean,
974                              boolean updateVessel,
975                              boolean updateGear) {
976         return getCruiseService().saveCruise(bean, updateVessel, updateGear);
977     }
978 
979     @Override
980     public void setCruiseReadyToSynch(Integer cruiseId) {
981         getCruiseService().setCruiseReadyToSynch(cruiseId);
982     }
983 
984     @Override
985     public CaracteristicMap getGearCaracteristics(Integer cruiseId, Integer gearId, short rankOrder) {
986         return getCruiseService().getGearCaracteristics(cruiseId, gearId, rankOrder);
987     }
988 
989     @Override
990     public boolean isOperationUseGears(Integer cruiseId, Collection<Gear> gears) {
991         return getCruiseService().isOperationUseGears(cruiseId, gears);
992     }
993 
994     @Override
995     public void saveGearCaracteristics(Gear gear, Cruise cruise) {
996         getCruiseService().saveGearCaracteristics(gear, cruise);
997     }
998 
999     //------------------------------------------------------------------------//
1000     //-- Protocol methods                                                   --//
1001     //------------------------------------------------------------------------//
1002 
1003     @Override
1004     public TuttiProtocol getProtocol() {
1005         return getProtocolService().getProtocol();
1006     }
1007 
1008     @Override
1009     public void setProtocol(TuttiProtocol protocol) {
1010         getProtocolService().setProtocol(protocol);
1011     }
1012 
1013     @Override
1014     public boolean isProtocolExist(String id) {
1015         return getProtocolService().isProtocolExist(id);
1016     }
1017 
1018     @Override
1019     public String getFirstAvailableName(String protocolName) {
1020         return getProtocolService().getFirstAvailableName(protocolName);
1021     }
1022 
1023     @Override
1024     public List<String> getAllProtocolNames() {
1025         return getProtocolService().getAllProtocolNames();
1026     }
1027 
1028     @Override
1029     public TuttiProtocol getProtocolByName(String protocolName) {
1030         return getProtocolService().getProtocolByName(protocolName);
1031     }
1032 
1033 
1034     @Override
1035     public List<TuttiProtocol> getAllProtocol() {
1036         return getProtocolService().getAllProtocol();
1037     }
1038 
1039     @Override
1040     public List<TuttiProtocol> getAllProtocol(String programId) {
1041         return getProtocolService().getAllProtocol(programId);
1042     }
1043 
1044     @Override
1045     public List<String> getAllProtocolId() {
1046         return getProtocolService().getAllProtocolId();
1047     }
1048 
1049     @Override
1050     public TuttiProtocol saveProtocol(TuttiProtocol bean) {
1051         return getProtocolService().saveProtocol(bean);
1052     }
1053 
1054     @Override
1055     public void deleteProtocol(String id) {
1056         getProtocolService().deleteProtocol(id);
1057     }
1058 
1059     @Override
1060     public TuttiProtocol createProtocol(TuttiProtocol bean) {
1061         return protocolService.createProtocol(bean);
1062     }
1063 
1064     @Override
1065     public TuttiProtocol getProtocol(String id) {
1066         TuttiProtocol protocol = getProtocolService().getProtocol(id);
1067 
1068         // translate obsolete referent taxons (See https://forge.codelutin.com/issues/7846)
1069         Map<Integer, Integer> allObsoleteReferentTaxons = getAllObsoleteReferentTaxons();
1070         TuttiProtocols.translateReferenceTaxonIds(protocol, allObsoleteReferentTaxons);
1071 
1072         // sanity it (remove all bad species and benthos)
1073         // see http://forge.codelutin.com/issues/4154
1074 
1075         List<Species> allReferentSpecies = getAllReferentSpecies();
1076 
1077         Map<Integer, String> missingSpecies = TuttiProtocols.detectMissingSpecies(protocol, allReferentSpecies);
1078         TuttiProtocols.removeBadSpecies(protocol, missingSpecies);
1079 
1080         Map<Integer, String> missingBenthos = TuttiProtocols.detectMissingBenthos(protocol, allReferentSpecies);
1081         TuttiProtocols.removeBadBenthos(protocol, missingBenthos);
1082 
1083         return protocol;
1084     }
1085 
1086     //------------------------------------------------------------------------//
1087     //-- Fishing operation methods                                          --//
1088     //------------------------------------------------------------------------//
1089 
1090     @Override
1091     public int getFishingOperationCount(Integer cruiseId) {
1092         return getFishingOperationService().getFishingOperationCount(cruiseId);
1093     }
1094 
1095     @Override
1096     public List<Integer> getAllFishingOperationIds(Integer cruiseId) {
1097         return getFishingOperationService().getAllFishingOperationIds(cruiseId);
1098     }
1099 
1100     @Override
1101     public List<FishingOperation> getAllFishingOperation(Integer cruiseId) {
1102         return getFishingOperationService().getAllFishingOperation(cruiseId);
1103     }
1104 
1105     @Override
1106     public FishingOperation getFishingOperation(Integer id) {
1107         return getFishingOperationService().getFishingOperation(id);
1108     }
1109 
1110     @Override
1111     public List<Vessel> getFishingOperationSecondaryVessel(Integer fishingOperationId) {
1112         return getFishingOperationService().getFishingOperationSecondaryVessel(fishingOperationId);
1113     }
1114 
1115     @Override
1116     public FishingOperation createFishingOperation(FishingOperation bean) {
1117         return getFishingOperationService().createFishingOperation(bean);
1118     }
1119 
1120     @Override
1121     public FishingOperation saveFishingOperation(FishingOperation bean) {
1122         return getFishingOperationService().saveFishingOperation(bean);
1123     }
1124 
1125     @Override
1126     public Collection<FishingOperation> saveFishingOperations(Collection<FishingOperation> beans) {
1127         return getFishingOperationService().saveFishingOperations(beans);
1128     }
1129 
1130     @Override
1131     public void deleteFishingOperation(Integer id) {
1132         getFishingOperationService().deleteFishingOperation(id);
1133     }
1134 
1135     //------------------------------------------------------------------------//
1136     //-- CatchBatch methods                                                 --//
1137     //------------------------------------------------------------------------//
1138 
1139     @Override
1140     public boolean isFishingOperationWithCatchBatch(Integer operationId) {
1141         return getCatchBatchService().isFishingOperationWithCatchBatch(operationId);
1142     }
1143 
1144     @Override
1145     public CatchBatch getCatchBatchFromFishingOperation(Integer id) throws InvalidBatchModelException {
1146         return getCatchBatchService().getCatchBatchFromFishingOperation(id);
1147     }
1148 
1149     @Override
1150     public CatchBatch createCatchBatch(CatchBatch bean) {
1151         return getCatchBatchService().createCatchBatch(bean);
1152     }
1153 
1154     @Override
1155     public CatchBatch saveCatchBatch(CatchBatch bean) {
1156         return getCatchBatchService().saveCatchBatch(bean);
1157     }
1158 
1159     @Override
1160     public void deleteCatchBatch(Integer fishingOperationId) {
1161         getCatchBatchService().deleteCatchBatch(fishingOperationId);
1162     }
1163 
1164     @Override
1165     public void recomputeCatchBatchSampleRatios(Integer fishingOperationId) {
1166         getCatchBatchService().recomputeCatchBatchSampleRatios(fishingOperationId);
1167     }
1168 
1169     @Override
1170     public Map getPrevOperationNameAndBatchId(int operationId, int taxonId) {
1171         return getCatchBatchService().getPrevOperationNameAndBatchId(operationId, taxonId);
1172     }
1173 
1174     @Override
1175     public Map getNextOperationNameAndBatchId(int operationId, int taxonId) {
1176         return getCatchBatchService().getNextOperationNameAndBatchId(operationId, taxonId);
1177     }
1178 
1179     //------------------------------------------------------------------------//
1180     //-- Species Batch methods                                              --//
1181     //------------------------------------------------------------------------//
1182 
1183     @Override
1184     public BatchContainer<SpeciesBatch> getRootSpeciesBatch(Integer fishingOperationId, boolean validateTree) throws InvalidBatchModelException {
1185         return getSpeciesBatchService().getRootSpeciesBatch(fishingOperationId, validateTree);
1186     }
1187 
1188     @Override
1189     public Set<Integer> getBatchChildIds(Integer id) {
1190         return getSpeciesBatchService().getBatchChildIds(id);
1191     }
1192 
1193     @Override
1194     public SpeciesBatch createSpeciesBatch(SpeciesBatch bean, Integer parentBatchId, boolean computeRankOrder) {
1195         return getSpeciesBatchService().createSpeciesBatch(bean, parentBatchId, computeRankOrder);
1196     }
1197 
1198     @Override
1199     public Collection<SpeciesBatch> createSpeciesBatches(Integer fishingOperationId, Collection<SpeciesBatch> beans) {
1200         return getSpeciesBatchService().createSpeciesBatches(fishingOperationId, beans);
1201     }
1202 
1203     @Override
1204     public SpeciesBatch saveSpeciesBatch(SpeciesBatch bean) {
1205         return getSpeciesBatchService().saveSpeciesBatch(bean);
1206     }
1207 
1208     @Override
1209     public void deleteSpeciesBatch(Integer id) {
1210         getSpeciesBatchService().deleteSpeciesBatch(id);
1211     }
1212 
1213     @Override
1214     public void deleteSpeciesSubBatch(Integer id) {
1215         getSpeciesBatchService().deleteSpeciesSubBatch(id);
1216     }
1217 
1218     @Override
1219     public void changeSpeciesBatchSpecies(Integer batchId, Species species) {
1220         getSpeciesBatchService().changeSpeciesBatchSpecies(batchId, species);
1221     }
1222 
1223     @Override
1224     public List<SpeciesBatch> getAllSpeciesBatchToConfirm(Integer fishingOperationId) throws InvalidBatchModelException {
1225         return getSpeciesBatchService().getAllSpeciesBatchToConfirm(fishingOperationId);
1226     }
1227 
1228     @Override
1229     public List<SpeciesBatchFrequency> getAllSpeciesBatchFrequency(Integer speciesBatchId) {
1230         return getSpeciesBatchService().getAllSpeciesBatchFrequency(speciesBatchId);
1231     }
1232 
1233     @Override
1234     public Multimap<Species, SpeciesBatchFrequency> getAllSpeciesBatchFrequencyForBatch(BatchContainer<SpeciesBatch> batchContainer) {
1235         return getSpeciesBatchService().getAllSpeciesBatchFrequencyForBatch(batchContainer);
1236     }
1237 
1238     @Override
1239     public List<SpeciesBatchFrequency> saveSpeciesBatchFrequency(Integer speciesBatchId, List<SpeciesBatchFrequency> frequencies) {
1240         return getSpeciesBatchService().saveSpeciesBatchFrequency(speciesBatchId, frequencies);
1241     }
1242 
1243     //------------------------------------------------------------------------//
1244     //-- Benthos Batch methods                                              --//
1245     //------------------------------------------------------------------------//
1246 
1247     @Override
1248     public BatchContainer<SpeciesBatch> getRootBenthosBatch(Integer fishingOperationId, boolean validateTree) throws InvalidBatchModelException {
1249         return getBenthosBatchService().getRootBenthosBatch(fishingOperationId, validateTree);
1250     }
1251 
1252     @Override
1253     public SpeciesBatch createBenthosBatch(SpeciesBatch bean, Integer parentBatchId, boolean computeRankOrder) {
1254         return getBenthosBatchService().createBenthosBatch(bean, parentBatchId, computeRankOrder);
1255     }
1256 
1257     @Override
1258     public Collection<SpeciesBatch> createBenthosBatches(Integer fishingOperationId, Collection<SpeciesBatch> beans) {
1259         return getBenthosBatchService().createBenthosBatches(fishingOperationId, beans);
1260     }
1261 
1262     @Override
1263     public SpeciesBatch saveBenthosBatch(SpeciesBatch bean) {
1264         return getBenthosBatchService().saveBenthosBatch(bean);
1265     }
1266 
1267     @Override
1268     public void deleteBenthosBatch(Integer id) {
1269         getBenthosBatchService().deleteBenthosBatch(id);
1270     }
1271 
1272     @Override
1273     public void deleteBenthosSubBatch(Integer id) {
1274         getBenthosBatchService().deleteBenthosSubBatch(id);
1275     }
1276 
1277     @Override
1278     public void changeBenthosBatchSpecies(Integer batchId, Species species) {
1279         getBenthosBatchService().changeBenthosBatchSpecies(batchId, species);
1280     }
1281 
1282     @Override
1283     public List<SpeciesBatch> getAllBenthosBatchToConfirm(Integer fishingOperationId) throws InvalidBatchModelException {
1284         return getBenthosBatchService().getAllBenthosBatchToConfirm(fishingOperationId);
1285     }
1286 
1287     @Override
1288     public List<SpeciesBatchFrequency> getAllBenthosBatchFrequency(Integer benthosBatchId) {
1289         return getBenthosBatchService().getAllBenthosBatchFrequency(benthosBatchId);
1290     }
1291 
1292     @Override
1293     public Multimap<Species, SpeciesBatchFrequency> getAllBenthosBatchFrequencyForBatch(BatchContainer<SpeciesBatch> batchContainer) {
1294         return getBenthosBatchService().getAllBenthosBatchFrequencyForBatch(batchContainer);
1295     }
1296 
1297     @Override
1298     public List<SpeciesBatchFrequency> saveBenthosBatchFrequency(Integer benthosBatchId,
1299                                                                  List<SpeciesBatchFrequency> frequencies) {
1300         return getBenthosBatchService().saveBenthosBatchFrequency(benthosBatchId, frequencies);
1301     }
1302 
1303     //------------------------------------------------------------------------//
1304     //-- MarineLitter Batch methods                                         --//
1305     //------------------------------------------------------------------------//
1306 
1307     @Override
1308     public BatchContainer<MarineLitterBatch> getRootMarineLitterBatch(Integer fishingOperationId) {
1309         return getMarineLitterBatchService().getRootMarineLitterBatch(fishingOperationId);
1310     }
1311 
1312     @Override
1313     public MarineLitterBatch createMarineLitterBatch(MarineLitterBatch bean) {
1314         return getMarineLitterBatchService().createMarineLitterBatch(bean);
1315     }
1316 
1317     @Override
1318     public Collection<MarineLitterBatch> createMarineLitterBatches(Integer fishingOperationId, Collection<MarineLitterBatch> beans) {
1319         return getMarineLitterBatchService().createMarineLitterBatches(fishingOperationId, beans);
1320     }
1321 
1322     @Override
1323     public MarineLitterBatch saveMarineLitterBatch(MarineLitterBatch bean) {
1324         return getMarineLitterBatchService().saveMarineLitterBatch(bean);
1325     }
1326 
1327     @Override
1328     public void deleteMarineLitterBatch(Integer id) {
1329         getMarineLitterBatchService().deleteMarineLitterBatch(id);
1330     }
1331 
1332     //------------------------------------------------------------------------//
1333     //-- Accidental Batch methods                                           --//
1334     //------------------------------------------------------------------------//
1335 
1336     @Override
1337     public List<AccidentalBatch> getAllAccidentalBatch(Integer fishingOperationId) {
1338         return getAccidentalBatchService().getAllAccidentalBatch(fishingOperationId);
1339     }
1340 
1341     @Override
1342     public AccidentalBatch createAccidentalBatch(AccidentalBatch bean) {
1343         return getAccidentalBatchService().createAccidentalBatch(bean);
1344     }
1345 
1346     @Override
1347     public Collection<AccidentalBatch> createAccidentalBatches(Collection<AccidentalBatch> beans) {
1348         return getAccidentalBatchService().createAccidentalBatches(beans);
1349     }
1350 
1351     @Override
1352     public AccidentalBatch saveAccidentalBatch(AccidentalBatch bean) {
1353         return getAccidentalBatchService().saveAccidentalBatch(bean);
1354     }
1355 
1356     @Override
1357     public void deleteAccidentalBatch(String id) {
1358         getAccidentalBatchService().deleteAccidentalBatch(id);
1359     }
1360 
1361     @Override
1362     public void deleteAccidentalBatchForFishingOperation(Integer fishingOperationId) {
1363         getAccidentalBatchService().deleteAccidentalBatchForFishingOperation(fishingOperationId);
1364     }
1365 
1366     //------------------------------------------------------------------------//
1367     //-- IndividualObservation Batch methods                                --//
1368     //------------------------------------------------------------------------//
1369 
1370     @Override
1371     public List<IndividualObservationBatch> getAllIndividualObservationBatchsForBatch(Integer batchId) {
1372         return getIndividualObservationBatchService().getAllIndividualObservationBatchsForBatch(batchId);
1373     }
1374 
1375     @Override
1376     public List<IndividualObservationBatch> getAllIndividualObservationBatchsForFishingOperation(Integer fishingOperationId) {
1377         return getIndividualObservationBatchService().getAllIndividualObservationBatchsForFishingOperation(fishingOperationId);
1378     }
1379 
1380     @Override
1381     public List<IndividualObservationBatch> getAllIndividualObservationBatchsForCruise(Integer cruiseId) {
1382         return getIndividualObservationBatchService().getAllIndividualObservationBatchsForCruise(cruiseId);
1383     }
1384 
1385     @Override
1386     public boolean isSamplingCodeAvailable(Integer cruiseId, Integer referenceTaxonId, String samplingCodeSuffix) {
1387         return getIndividualObservationBatchService().isSamplingCodeAvailable(cruiseId, referenceTaxonId, samplingCodeSuffix);
1388     }
1389 
1390     @Override
1391     public List<IndividualObservationBatch> createIndividualObservationBatches(FishingOperation fishingOperation, Collection<IndividualObservationBatch> individualObservations) {
1392         return getIndividualObservationBatchService().createIndividualObservationBatches(fishingOperation, individualObservations);
1393     }
1394 
1395     public List<IndividualObservationBatch> saveBatchIndividualObservation(Integer batchId,
1396                                                                            List<IndividualObservationBatch> individualObservation) {
1397         return getIndividualObservationBatchService().saveBatchIndividualObservation(batchId, individualObservation);
1398     }
1399 
1400     @Override
1401     public void deleteAllIndividualObservationsForFishingOperation(Integer fishingOperationId) {
1402         getIndividualObservationBatchService().deleteAllIndividualObservationsForFishingOperation(fishingOperationId);
1403     }
1404 
1405     @Override
1406     public void deleteAllIndividualObservationsForBatch(Integer speciesBatchId) {
1407         getIndividualObservationBatchService().deleteAllIndividualObservationsForBatch(speciesBatchId);
1408     }
1409 
1410     //------------------------------------------------------------------------//
1411     //-- Internal methods                                                   --//
1412     //------------------------------------------------------------------------//
1413 
1414     protected void setSpeciesSurveyCode(List<Species> speciesList, TuttiProtocol protocol) {
1415         if (protocol != null && !protocol.isSpeciesEmpty()) {
1416 
1417             Map<Integer, String> surveyCodeByTaxonId = Maps.newTreeMap();
1418 
1419             if (!protocol.isSpeciesEmpty()) {
1420                 for (SpeciesProtocol speciesProtocol : protocol.getSpecies()) {
1421                     String surveyCode = speciesProtocol.getSpeciesSurveyCode();
1422                     if (StringUtils.isNotBlank(surveyCode)) {
1423                         Integer taxonId =
1424                                 speciesProtocol.getSpeciesReferenceTaxonId();
1425                         surveyCodeByTaxonId.put(taxonId, surveyCode);
1426                     }
1427                 }
1428             }
1429             if (!protocol.isBenthosEmpty()) {
1430                 for (SpeciesProtocol speciesProtocol : protocol.getBenthos()) {
1431                     String surveyCode = speciesProtocol.getSpeciesSurveyCode();
1432                     if (StringUtils.isNotBlank(surveyCode)) {
1433                         Integer taxonId =
1434                                 speciesProtocol.getSpeciesReferenceTaxonId();
1435                         String oldSurveyCode = surveyCodeByTaxonId.put(taxonId, surveyCode);
1436                         if (oldSurveyCode != null) {
1437                             if (log.isWarnEnabled()) {
1438                                 log.warn(String.format("Detect a species in both species and benthos protocol: taxonId=%d, species surveyCode=%s, benthos surveyCode=%s", taxonId, oldSurveyCode, surveyCode));
1439                             }
1440                         }
1441                     }
1442                 }
1443             }
1444             for (Species species : speciesList) {
1445                 Integer taxonId = species.getReferenceTaxonId();
1446                 String surveyCode = surveyCodeByTaxonId.get(taxonId);
1447                 species.setSurveyCode(surveyCode);
1448             }
1449         }
1450     }
1451 
1452     public AccidentalBatchPersistenceService getAccidentalBatchService() {
1453         return getServiceInitialized(accidentalBatchService);
1454     }
1455 
1456     public AttachmentPersistenceService getAttachmentService() {
1457         return getServiceInitialized(attachmentService);
1458     }
1459 
1460     public BenthosBatchPersistenceService getBenthosBatchService() {
1461         return getServiceInitialized(benthosBatchService);
1462     }
1463 
1464     public CaracteristicPersistenceService getCaracteristicService() {
1465         return getServiceInitialized(caracteristicService);
1466     }
1467 
1468     public CatchBatchPersistenceService getCatchBatchService() {
1469         return getServiceInitialized(catchBatchService);
1470     }
1471 
1472     public CruisePersistenceService getCruiseService() {
1473         return getServiceInitialized(cruiseService);
1474     }
1475 
1476     public FishingOperationPersistenceService getFishingOperationService() {
1477         return getServiceInitialized(fishingOperationService);
1478     }
1479 
1480     public GearPersistenceService getGearService() {
1481         return getServiceInitialized(gearService);
1482     }
1483 
1484     public IndividualObservationBatchPersistenceService getIndividualObservationBatchService() {
1485         return getServiceInitialized(individualObservationBatchService);
1486     }
1487 
1488     public LocationPersistenceService getLocationService() {
1489         return getServiceInitialized(locationService);
1490     }
1491 
1492     public MarineLitterBatchPersistenceService getMarineLitterBatchService() {
1493         return getServiceInitialized(marineLitterBatchService);
1494     }
1495 
1496     public ObjectTypePersistenceService getObjectTypeService() {
1497         return getServiceInitialized(objectTypeService);
1498     }
1499 
1500     public PersonPersistenceService getPersonService() {
1501         return getServiceInitialized(personService);
1502     }
1503 
1504     public ProtocolPersistenceService getProtocolService() {
1505         return getServiceInitialized(protocolService);
1506     }
1507 
1508     public ProgramPersistenceService getProgramService() {
1509         return getServiceInitialized(programService);
1510     }
1511 
1512     public SpeciesBatchPersistenceService getSpeciesBatchService() {
1513         return getServiceInitialized(speciesBatchService);
1514     }
1515 
1516     public SpeciesPersistenceService getSpeciesService() {
1517         return getServiceInitialized(speciesService);
1518     }
1519 
1520     public TechnicalPersistenceService getTechnicalPersistenceService() {
1521         return getServiceInitialized(technicalPersistenceService);
1522     }
1523 
1524     public VesselPersistenceService getVesselService() {
1525         return getServiceInitialized(vesselService);
1526     }
1527 
1528     protected <S extends TuttiPersistenceServiceImplementor> S getServiceInitialized(S service) {
1529         service.lazyInit();
1530         return service;
1531     }
1532 
1533 }