1 package fr.ifremer.tutti.service.genericformat.csv;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import com.google.common.base.Preconditions;
26 import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry;
27 import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency;
28 import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
29 import fr.ifremer.tutti.persistence.entities.referential.Species;
30
31 import java.util.ArrayList;
32 import java.util.List;
33 import java.util.Objects;
34 import java.util.stream.Collectors;
35
36
37
38
39
40
41
42 public class CatchRow extends RowWithOperationContextSupport {
43
44 private static final long serialVersionUID = 1L;
45
46 public static final String PROPERTY_BENTHOS = "benthos";
47
48 public static final String PROPERTY_SPECIES_TO_CONFIRM = "speciesToConfirm";
49
50 public static final String FREQUENCY_LENGTH_STEP = "frequencyLengthStep";
51
52 public static final String FREQUENCY_WEIGHT = "frequencyWeight";
53
54 public static final String FREQUENCY_LENGTH_STEP_CARACTERISTIC = "frequencyLengthStepCaracteristic";
55
56 public static final String FREQUENCY_RANK_ORDER = "frequencyRankOrder";
57
58 public static final String SAMPLE_CATEGORY = "sampleCategory";
59
60 public static final String REFERENCE_WEIGHT = "referenceWeight";
61
62 public static final String RAISING_FACTOR = "raisingFactor";
63
64 public static final String BATCH_NUMBER = "batchNumber";
65
66 public static final String BATCH_NUMBER_COMPUTED = "batchNumberComputed";
67
68 public static final String BATCH_WEIGHT_UNIT = "batchWeightUnit";
69
70 public static final String FINAL_RAISING_FACTOR = "finalRaisingFactor";
71
72 public static CatchRow newEmptyInstance() {
73 CatchRow row = new CatchRow();
74 row.forImport();
75 return row;
76 }
77
78 protected final List<ExportSampleCategory> sampleCategory = new ArrayList<>();
79
80 protected Species species;
81
82 protected Float referenceWeight;
83
84 protected float raisingFactor;
85
86 protected Float finalRaisingFactor;
87
88 protected Integer batchNumber;
89
90 protected Boolean batchNumberComputed;
91
92 protected String batchWeightUnit;
93
94 protected boolean benthos;
95
96 protected boolean vrac;
97
98 protected boolean speciesToConfirm;
99
100 protected Caracteristic frequencyLengthStepCaracteristic;
101
102 protected Float frequencyLengthStep;
103
104 protected Float frequencyWeight;
105
106 protected Float computedFrequencyTotalWeight;
107
108 protected Integer frequencyRankOrder;
109
110 public void setBenthos(boolean benthos) {
111 this.benthos = benthos;
112 }
113
114 public void setVrac(boolean vrac) {
115 this.vrac = vrac;
116 }
117
118 public void setReferenceWeight(Float referenceWeight) {
119 this.referenceWeight = referenceWeight;
120 }
121
122 public void setRaisingFactor(float raisingFactor) {
123 this.raisingFactor = raisingFactor;
124 }
125
126 public void setBatchNumber(Integer batchNumber) {
127 this.batchNumber = batchNumber;
128 }
129
130 public void setBatchNumberComputed(Boolean batchNumberComputed) {
131 this.batchNumberComputed = batchNumberComputed;
132 }
133
134 public void setComputedFrequencyTotalWeight(Float computedFrequencyTotalWeight) {
135 this.computedFrequencyTotalWeight = computedFrequencyTotalWeight;
136 }
137
138 public void addSampleCategory(ExportSampleCategory sampleCategory) {
139 int order = sampleCategory.getCategoryDef().getOrder();
140 while (this.sampleCategory.size() <= order) {
141 this.sampleCategory.add(null);
142 }
143 this.sampleCategory.set(order, sampleCategory);
144 }
145
146 public void setFrequency(SpeciesBatchFrequency frequency) {
147 Preconditions.checkNotNull(frequency);
148 setFrequencyLengthStepCaracteristic(frequency.getLengthStepCaracteristic());
149 setFrequencyLengthStep(frequency.getLengthStep());
150 setBatchNumber(frequency.getNumber());
151 setBatchNumberComputed(false);
152 setFrequencyRankOrder(frequency.getRankOrder());
153 setFrequencyWeight(frequency.getWeight());
154 }
155
156 public void setFinalRaisingFactor(Float finalRaisingFactor) {
157 this.finalRaisingFactor = finalRaisingFactor;
158 }
159
160 public void setFrequencyLengthStepCaracteristic(Caracteristic frequencyLengthStepCaracteristic) {
161 this.frequencyLengthStepCaracteristic = frequencyLengthStepCaracteristic;
162 }
163
164 public void setFrequencyLengthStep(Float frequencyLengthStep) {
165 this.frequencyLengthStep = frequencyLengthStep;
166 }
167
168 public void setFrequencyWeight(Float frequencyWeight) {
169 this.frequencyWeight = frequencyWeight;
170 }
171
172 public void setFrequencyRankOrder(Integer frequencyRankOrder) {
173 this.frequencyRankOrder = frequencyRankOrder;
174 }
175
176 public void setSpecies(Species species) {
177 this.species = species;
178 }
179
180 public void setSpeciesToConfirm(boolean speciesToConfirm) {
181 this.speciesToConfirm = speciesToConfirm;
182 }
183
184 public List<ExportSampleCategory> getSampleCategory() {
185 return sampleCategory;
186 }
187
188 public ExportSampleCategory getLastSampleCategoryFilled() {
189 List<ExportSampleCategory> list = sampleCategory.stream().filter(Objects::nonNull).collect(Collectors.toList());
190 return list.isEmpty() ? null:list.get(list.size()-1);
191 }
192
193 public Float getFinalRaisingFactor() {
194 return finalRaisingFactor;
195 }
196
197 public boolean isFrequencyWithWeight() {
198 return frequencyLengthStepCaracteristic!=null && frequencyWeight!=null;
199 }
200
201 public Caracteristic getFrequencyLengthStepCaracteristic() {
202 return frequencyLengthStepCaracteristic;
203 }
204
205 public Float getFrequencyLengthStep() {
206 return frequencyLengthStep;
207 }
208
209 public Float getFrequencyWeight() {
210 return frequencyWeight;
211 }
212
213 public Float getComputedFrequencyTotalWeight() {
214 return computedFrequencyTotalWeight;
215 }
216
217 public Species getSpecies() {
218 return species;
219 }
220
221 public Integer getFrequencyRankOrder() {
222 return frequencyRankOrder;
223 }
224
225 public Float getReferenceWeight() {
226 return referenceWeight;
227 }
228
229 public float getRaisingFactor() {
230 return raisingFactor;
231 }
232
233 public Integer getBatchNumber() {
234 return batchNumber;
235 }
236
237 public Boolean getBatchNumberComputed() {
238 return batchNumberComputed;
239 }
240
241 public String getBatchWeightUnit() {
242 return batchWeightUnit;
243 }
244
245 public boolean isSpeciesToConfirm() {
246 return speciesToConfirm;
247 }
248
249 public void setBatchWeightUnit(String batchWeightUnit) {
250 this.batchWeightUnit = batchWeightUnit;
251 }
252
253 public boolean isVrac() {
254 return vrac;
255 }
256
257 public boolean isHorsVrac() {
258 return !isVrac();
259 }
260
261 public boolean isBenthos() {
262 return benthos;
263 }
264
265 public CatchRow copy() {
266 CatchRow result = new CatchRow();
267 result.setVrac(vrac);
268 result.setBenthos(benthos);
269 result.setCruise(getCruise());
270 result.setFishingOperation(getFishingOperation());
271 result.sampleCategory.addAll(sampleCategory);
272 result.setFrequencyLengthStep(frequencyLengthStep);
273 result.setFrequencyLengthStepCaracteristic(frequencyLengthStepCaracteristic);
274 result.setFrequencyRankOrder(frequencyRankOrder);
275 result.setFrequencyWeight(frequencyWeight);
276
277 result.setSpecies(species);
278 result.setSpeciesToConfirm(speciesToConfirm);
279 result.setRaisingFactor(raisingFactor);
280 result.setReferenceWeight(referenceWeight);
281 result.setBatchNumber(batchNumber);
282 result.setBatchWeightUnit(batchWeightUnit);
283 result.setFinalRaisingFactor(finalRaisingFactor);
284
285 return result;
286 }
287
288 public boolean withFrequency() {
289 return frequencyLengthStep != null;
290 }
291
292 public ExportSampleCategory getSampleCategory(SampleCategoryModelEntry sampleCategoryModelEntry) {
293
294 int categoryOrder = sampleCategoryModelEntry.getOrder();
295 if (sampleCategory.size() == categoryOrder) {
296 ExportSampleCategory exportSampleCategory = new ExportSampleCategory();
297 exportSampleCategory.setCategoryDef(sampleCategoryModelEntry);
298 sampleCategory.add(categoryOrder, exportSampleCategory);
299 }
300 return sampleCategory.get(categoryOrder);
301
302 }
303
304 public List<ExportSampleCategory> getFilledSampleCategories() {
305
306 List<ExportSampleCategory> result = new ArrayList<>();
307 for (ExportSampleCategory exportSampleCategory : sampleCategory) {
308 if (exportSampleCategory.isFilled()) {
309 result.add(exportSampleCategory);
310 }
311 }
312 return result;
313
314 }
315
316 }