1 package fr.ifremer.tutti.persistence.service;
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.collect.Multimap;
26 import fr.ifremer.tutti.persistence.InvalidBatchModelException;
27 import fr.ifremer.tutti.persistence.TuttiPersistenceServiceImplementor;
28 import fr.ifremer.tutti.persistence.entities.data.BatchContainer;
29 import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch;
30 import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency;
31 import fr.ifremer.tutti.persistence.entities.referential.Species;
32 import org.springframework.transaction.annotation.Transactional;
33
34 import java.util.Collection;
35 import java.util.List;
36 import java.util.Set;
37
38 /**
39 * Service to persist {@link SpeciesBatch}.
40 *
41 * FIXME Merge it with speciesBatch.
42 *
43 * @author Tony Chemit - chemit@codelutin.com
44 * @since 1.2
45 */
46 @Transactional(readOnly = true)
47 public interface BenthosBatchPersistenceService extends TuttiPersistenceServiceImplementor {
48
49 //------------------------------------------------------------------------//
50 //-- BenthosBatch methods --//
51 //------------------------------------------------------------------------//
52
53 /**
54 * Get all root {@link SpeciesBatch} for the given fishing operation.
55 *
56 * <strong>Note:</strong> All childs of the batch should be loaded here.
57 *
58 * @param fishingOperationId if of the fishing operation to seek
59 * @param validateTree flag to validate sample category model
60 * @return the list of root {@link SpeciesBatch}
61 * @throws InvalidBatchModelException if batch does not respect the sample category model
62 * @since 1.0
63 */
64 BatchContainer<SpeciesBatch> getRootBenthosBatch(Integer fishingOperationId, boolean validateTree) throws InvalidBatchModelException;
65
66 /**
67 * Récupérer les identifiants de tous les lots de la descendance du lot donné.
68 *
69 * @param id identifiant du lot parent
70 * @return l'ensemble des identifiants de toute la descendance d'un lot
71 */
72 Set<Integer> getBatchChildIds(Integer id);
73
74 @Transactional(readOnly = false)
75 SpeciesBatch createBenthosBatch(SpeciesBatch bean, Integer parentBatchId, boolean computeRankOrder);
76
77 @Transactional(readOnly = false)
78 Collection<SpeciesBatch> createBenthosBatches(Integer fishingOperationId, Collection<SpeciesBatch> beans);
79
80 @Transactional(readOnly = false)
81 SpeciesBatch saveBenthosBatch(SpeciesBatch bean);
82
83 @Transactional(readOnly = false)
84 void deleteBenthosBatch(Integer id);
85
86 @Transactional(readOnly = false)
87 void deleteBenthosSubBatch(Integer id);
88
89 /**
90 * Change the species in the given {@code batchId} and in all his
91 * sub batches.
92 *
93 * @param batchId id of the root Benthos batch to treat
94 * @param species species to affect to all batches
95 */
96 @Transactional(readOnly = false)
97 void changeBenthosBatchSpecies(Integer batchId, Species species);
98
99 /**
100 * Get all the batches to confirm
101 *
102 * @param fishingOperationId if of the fishing operation to seek
103 * @return the list of {@link fr.ifremer.tutti.persistence.entities.data.SpeciesBatch} to confirm
104 * @throws InvalidBatchModelException if batch does not respect the sample category model
105 * @since 3.13
106 */
107 List<SpeciesBatch> getAllBenthosBatchToConfirm(Integer fishingOperationId) throws InvalidBatchModelException;
108
109 //------------------------------------------------------------------------//
110 //-- BenthosBatchFrequency methods --//
111 //------------------------------------------------------------------------//
112
113 /**
114 * Get all frequencies for the given species batch.
115 *
116 * @param benthosBatchId the id of the species batch to seek.
117 * @return the list of frequencies for the given benthos batch id
118 * @since 1.0
119 */
120 List<SpeciesBatchFrequency> getAllBenthosBatchFrequency(Integer benthosBatchId);
121
122 /**
123 * Get all frequencies for the given root benthos batch container.
124 *
125 * @param batchContainer the root batch containter
126 * @return the list of benthos frequencies indexed by their species
127 * @since 3.3
128 */
129 Multimap<Species, SpeciesBatchFrequency> getAllBenthosBatchFrequencyForBatch(BatchContainer<SpeciesBatch> batchContainer);
130
131 /**
132 * Save all given {@link SpeciesBatchFrequency} into the given
133 * {@code benthosBatchId}. If some are not existing then creates them.
134 *
135 * <strong>Note:</strong> This will as a side effect remove all previous
136 * frequency for this benthos batch.
137 *
138 * @param benthosBatchId id of the {@link SpeciesBatch} to use
139 * @param frequencies list of frequencies to create or update
140 * @return the persisted list of frequencies
141 * @since 1.0
142 */
143 @Transactional(readOnly = false)
144 List<SpeciesBatchFrequency> saveBenthosBatchFrequency(Integer benthosBatchId,
145 List<SpeciesBatchFrequency> frequencies);
146 }