1 package fr.ifremer.tutti.service.pupitri.report;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 import com.google.common.base.Function;
28 import com.google.common.collect.ImmutableSet;
29 import com.google.common.collect.Ordering;
30 import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
31 import fr.ifremer.tutti.service.pupitri.PupitriImportResult;
32 import fr.ifremer.tutti.type.WeightUnit;
33 import fr.ifremer.tutti.util.Numbers;
34
35 import java.util.ArrayList;
36 import java.util.Collections;
37 import java.util.Date;
38 import java.util.List;
39 import java.util.Set;
40
41
42
43
44
45
46
47
48
49 public class PupitriImportReportModel {
50
51 private final FishingOperation operation;
52
53 private final PupitriImportResult importResult;
54
55 private final List<PupitriImportReportRow> rows;
56
57 public PupitriImportReportModel(FishingOperation operation, PupitriImportResult importResult) {
58 this.operation = operation;
59 this.importResult = importResult;
60 this.rows = new ArrayList<>();
61 }
62
63 public String getStationNumber() {
64 return operation.getStationNumber();
65 }
66
67 public Integer getFishingOperationNumber() {
68 return operation.getFishingOperationNumber();
69 }
70
71 public String getMultirigAggregation() {
72 return operation.getMultirigAggregation();
73 }
74
75 public Date getGearShootingStartDate() {
76 return operation.getGearShootingStartDate();
77 }
78
79 public Date getGearShootingEndDate() {
80 return operation.getGearShootingEndDate();
81 }
82
83 public Float getTrunkSortedWeight() {
84 Float sortedWeight = importResult.getSortedWeight();
85 return sortedWeight == null ? null : WeightUnit.KG.round(sortedWeight);
86 }
87
88 public Float getTrunkRejectedWeight() {
89 Float rejectedWeight = importResult.getRejectedWeight();
90 return rejectedWeight == null ? null : WeightUnit.KG.round(rejectedWeight);
91 }
92
93 public Float getTrunkTotalWeight() {
94 float trunkSortedWeight = Numbers.getValueOrComputedValue(importResult.getSortedWeight(), 0f);
95 float trunkRejectedWeight = Numbers.getValueOrComputedValue(importResult.getRejectedWeight(), 0f);
96
97 return WeightUnit.KG.round(trunkSortedWeight + trunkRejectedWeight);
98 }
99
100 public Float getCarrouselSortedWeight() {
101 Float carrouselSortedWeight = importResult.getCarrouselSortedWeight();
102 return carrouselSortedWeight == null ? null : WeightUnit.KG.round(carrouselSortedWeight);
103 }
104
105 public Float getCarrouselUnsortedWeight() {
106 Float carrouselUnsortedWeight = importResult.getCarrouselUnsortedWeight();
107 return carrouselUnsortedWeight == null ? null : WeightUnit.KG.round(carrouselUnsortedWeight);
108 }
109
110 public Float getCarrouselTotalWeight() {
111 float trunkSortedWeight = Numbers.getValueOrComputedValue(importResult.getCarrouselSortedWeight(), 0f);
112 float trunkRejectedWeight = Numbers.getValueOrComputedValue(importResult.getCarrouselUnsortedWeight(), 0f);
113
114 return WeightUnit.KG.round(trunkSortedWeight + trunkRejectedWeight);
115 }
116
117 public Set<String> getNotImportedSpeciesIds() {
118 return importResult.getNotImportedSpeciesIds();
119 }
120
121 public List<PupitriImportReportRow> getRows() {
122 return rows;
123 }
124
125 public void addRow(PupitriImportReportRow aCatch) {
126 rows.add(aCatch);
127 }
128
129 public void sortRows() {
130
131 Ordering<PupitriImportReportRow> o1 = Ordering.natural().reverse().onResultOf(new Function<PupitriImportReportRow, Boolean>() {
132 @Override
133 public Boolean apply(PupitriImportReportRow input) {
134 return input.isSorted();
135 }
136 });
137 Ordering<PupitriImportReportRow> o2 = Ordering.natural().onResultOf(new Function<PupitriImportReportRow, String>() {
138 @Override
139 public String apply(PupitriImportReportRow input) {
140 return input.getSpeciesCode();
141 }
142 });
143 Ordering<PupitriImportReportRow> ordering = Ordering.compound(ImmutableSet.of(o1, o2));
144
145 Collections.sort(rows, ordering);
146
147 }
148 }