View Javadoc
1   package fr.ifremer.tutti.service.pupitri.report;
2   
3   /*
4    * #%L
5    * Tutti :: Service
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2012 - 2014 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU General Public License as
13   * published by the Free Software Foundation, either version 3 of the
14   * License, or (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU General Public
22   * License along with this program.  If not, see
23   * <http://www.gnu.org/licenses/gpl-3.0.html>.
24   * #L%
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   * Modèle du rapport d'import Pupitri.
43   *
44   * Created on 11/22/14.
45   *
46   * @author Tony Chemit - chemit@codelutin.com
47   * @since 3.11
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 }