View Javadoc
1   package fr.ifremer.tutti.service.genericformat;
2   
3   /*
4    * #%L
5    * Tutti :: Service
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2012 - 2015 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 fr.ifremer.tutti.persistence.entities.data.CatchBatch;
28  import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
29  import org.apache.commons.collections4.CollectionUtils;
30  import org.apache.commons.lang3.BooleanUtils;
31  
32  import java.io.Serializable;
33  import java.util.Set;
34  
35  /**
36   * Created on 2/22/15.
37   *
38   * @author Tony Chemit - chemit@codelutin.com
39   * @since 3.14
40   */
41  public class GenericFormatImportOperationResult implements Serializable {
42  
43      private static final long serialVersionUID = 1L;
44  
45      private final FishingOperation fishingOperation;
46  
47      private final CatchBatch catchBatch;
48  
49      private final String label;
50  
51      private final Set<String> checkErrors;
52  
53      private final boolean weightsDeleted;
54  
55      private int nbGearFeatures;
56  
57      private int nbVesselFeatures;
58  
59      private int nbAccidentalCatches;
60  
61      private int nbMarineLitters;
62  
63      private int nbIndividualObservations;
64  
65      private int nbSpeciesTaxon;
66  
67      private int nbBenthosTaxon;
68  
69      private final boolean override;
70  
71      public GenericFormatImportOperationResult(GenericFormatImportOperationContext operationContext) {
72          this.fishingOperation = operationContext.getFishingOperation();
73          this.label = operationContext.getFishingOperationLabel();
74          this.override = operationContext.isOverride();
75          this.catchBatch = operationContext.getCatchBatch();
76          this.checkErrors = operationContext.getCheckErrors();
77          this.weightsDeleted = operationContext.isWeightsDeleted();
78          flushContext(operationContext);
79      }
80  
81      public boolean isOverride() {
82          return override;
83      }
84  
85      public String getLabel() {
86          return label;
87      }
88  
89      public String getId() {
90          return fishingOperation.getId();
91      }
92  
93      public boolean isValid() {
94          return BooleanUtils.isTrue(fishingOperation.getFishingOperationValid());
95      }
96  
97      public boolean isWithInvalidWeights() {
98          return CollectionUtils.isNotEmpty(checkErrors);
99      }
100 
101     public boolean isWeightsDeleted() {
102         return weightsDeleted;
103     }
104     public Set<String> getCheckErrors() {
105         return checkErrors;
106     }
107 
108     public Float getCatchTotalWeight() {
109         return catchBatch.getCatchTotalWeight();
110     }
111 
112     public Float getCatchTotalRejectedWeight() {
113         return catchBatch.getCatchTotalRejectedWeight();
114     }
115 
116     public Float getSpeciesTotalSortedWeight() {
117         return catchBatch.getSpeciesTotalSortedWeight();
118     }
119 
120     public Float getBenthosTotalSortedWeight() {
121         return catchBatch.getBenthosTotalSortedWeight();
122     }
123 
124     public boolean isWithAccidentalCatches() {
125         return nbAccidentalCatches > 0;
126     }
127 
128     public boolean isWithMarineLitter() {
129         return nbMarineLitters > 0;
130     }
131 
132     public FishingOperation getFishingOperation() {
133         return fishingOperation;
134     }
135 
136     public CatchBatch getCatchBatch() {
137         return catchBatch;
138     }
139 
140     public int getNbGearFeatures() {
141         return nbGearFeatures;
142     }
143 
144     public int getNbVesselFeatures() {
145         return nbVesselFeatures;
146     }
147 
148     public int getNbAccidentalCatches() {
149         return nbAccidentalCatches;
150     }
151 
152     public int getNbMarineLitters() {
153         return nbMarineLitters;
154     }
155 
156     public int getNbIndividualObservations() {
157         return nbIndividualObservations;
158     }
159 
160     public int getNbSpeciesTaxon() {
161         return nbSpeciesTaxon;
162     }
163 
164     public int getNbBenthosTaxon() {
165         return nbBenthosTaxon;
166     }
167 
168     protected void flushContext(GenericFormatImportOperationContext operationContext) {
169 
170         //TODO See what else to set here (catch stuff ?)
171         if (operationContext.withGearFeatures()) {
172             nbGearFeatures = operationContext.getGearUseFeatures().size();
173         }
174         if (operationContext.withVesselFeatures()) {
175             nbVesselFeatures = operationContext.getVesselUseFeatures().size();
176         }
177         if (operationContext.withAccidentalBatches()) {
178             nbAccidentalCatches = operationContext.getAccidentalBatches().size();
179         }
180         if (operationContext.withMarineLitterBatches()) {
181             nbMarineLitters = operationContext.getMarineLitterBatches().size();
182         }
183         if (operationContext.withIndividualObservationBatches()) {
184             nbIndividualObservations = operationContext.getIndividualObservationBatches().size();
185         }
186 
187         if (operationContext.withSpeciesBatches(true)) {
188             nbSpeciesTaxon = operationContext.getNbSpeciesTaxon();
189         }
190         if (operationContext.withBenthosBatches(true)) {
191             nbBenthosTaxon = operationContext.getNbBenthosTaxon();
192         }
193 
194     }
195 
196 }