View Javadoc
1   package fr.ifremer.tutti.ui.swing.content.operation.catches.species;
2   
3   /*
4    * #%L
5    * Tutti :: UI
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2012 - 2016 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.collect.ImmutableMap;
28  import fr.ifremer.tutti.persistence.entities.data.BatchContainer;
29  import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
30  import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch;
31  import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency;
32  import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol;
33  import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
34  import fr.ifremer.tutti.persistence.entities.referential.Species;
35  import fr.ifremer.tutti.service.catches.multipost.MultiPostImportResult;
36  import fr.ifremer.tutti.type.WeightUnit;
37  import fr.ifremer.tutti.ui.swing.TuttiUIContext;
38  import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel;
39  import fr.ifremer.tutti.ui.swing.util.computable.ComputableData;
40  
41  import java.io.File;
42  import java.util.Collections;
43  import java.util.List;
44  import java.util.Map;
45  
46  import static org.nuiton.i18n.I18n.n;
47  
48  /**
49   * Created on 17/03/16.
50   *
51   * @author Tony Chemit - chemit@codelutin.com
52   */
53  public class SpeciesBatchUISupportImpl extends SpeciesOrBenthosBatchUISupport {
54  
55      protected static final Map<String, String> CATCHES_UI_MODEL_PROPERTIES_MAPPING =
56              ImmutableMap.<String, String>builder()
57                      .put(EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, PROPERTY_TOTAL_COMPUTED_WEIGHT)
58                      .put(EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, PROPERTY_TOTAL_SORTED_WEIGHT)
59                      .put(EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_UNSORTED_COMPUTED_WEIGHT, PROPERTY_TOTAL_UNSORTED_COMPUTED_WEIGHT)
60                      .put(EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, PROPERTY_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT)
61                      .put(EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_INERT_WEIGHT, PROPERTY_TOTAL_INERT_WEIGHT)
62                      .put(EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT, PROPERTY_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT)
63                      .build();
64  
65      public SpeciesBatchUISupportImpl(TuttiUIContext context, EditCatchesUIModel catchesUIModel, WeightUnit weightUnit) {
66          super(context, catchesUIModel, CATCHES_UI_MODEL_PROPERTIES_MAPPING, weightUnit);
67      }
68  
69      @Override
70      public BatchContainer<SpeciesBatch> getRootSpeciesBatch(Integer batchId) {
71          return getPersistenceService().getRootSpeciesBatch(batchId, true);
72      }
73  
74      @Override
75      public String getTitle() {
76          return n("tutti.label.tab.species");
77      }
78  
79      @Override
80      public boolean canPupitriImport() {
81          return true;
82      }
83  
84      @Override
85      public boolean canPsionImport() {
86          return true;
87      }
88  
89      @Override
90      public boolean canBigfinImport() {
91          return true;
92      }
93  
94      @Override
95      public Float getTotalComputedWeight() {
96          return catchesUIModel.getSpeciesTotalComputedWeight();
97      }
98  
99      @Override
100     public void setTotalComputedWeight(Float totalComputedWeight) {
101         catchesUIModel.setSpeciesTotalComputedWeight(totalComputedWeight);
102     }
103 
104     @Override
105     public ComputableData<Float> getTotalSortedComputedOrNotWeight() {
106         return catchesUIModel.getSpeciesTotalSortedComputedOrNotWeight();
107     }
108 
109     @Override
110     public Float getTotalSortedWeight() {
111         return catchesUIModel.getSpeciesTotalSortedWeight();
112     }
113 
114     @Override
115     public void setTotalSortedWeight(Float totalSortedWeight) {
116         catchesUIModel.setSpeciesTotalSortedWeight(totalSortedWeight);
117     }
118 
119     @Override
120     public Float getTotalSortedComputedWeight() {
121         return catchesUIModel.getSpeciesTotalSortedComputedWeight();
122     }
123 
124     @Override
125     public void setTotalSortedComputedWeight(Float totalSortedComputedWeight) {
126         catchesUIModel.setSpeciesTotalSortedComputedWeight(totalSortedComputedWeight);
127     }
128 
129     @Override
130     public Float getTotalUnsortedComputedWeight() {
131         return catchesUIModel.getSpeciesTotalUnsortedComputedWeight();
132     }
133 
134     @Override
135     public void setTotalUnsortedComputedWeight(Float totalUnsortedComputedWeight) {
136         catchesUIModel.setSpeciesTotalUnsortedComputedWeight(totalUnsortedComputedWeight);
137     }
138 
139     @Override
140     public Float getTotalSampleSortedComputedWeight() {
141         return catchesUIModel.getSpeciesTotalSampleSortedComputedWeight();
142     }
143 
144     @Override
145     public void setTotalSampleSortedComputedWeight(Float totalSampleSortedComputedWeight) {
146         catchesUIModel.setSpeciesTotalSampleSortedComputedWeight(totalSampleSortedComputedWeight);
147     }
148 
149     @Override
150     public ComputableData<Float> getTotalInertComputedOrNotWeight() {
151         return catchesUIModel.getSpeciesTotalInertComputedOrNotWeight();
152     }
153 
154     @Override
155     public Float getTotalInertWeight() {
156         return catchesUIModel.getSpeciesTotalInertWeight();
157     }
158 
159     @Override
160     public void setTotalInertWeight(Float totalInertWeight) {
161         catchesUIModel.setSpeciesTotalInertWeight(totalInertWeight);
162     }
163 
164     @Override
165     public Float getTotalInertComputedWeight() {
166         return catchesUIModel.getSpeciesTotalInertComputedWeight();
167     }
168 
169     @Override
170     public void setTotalInertComputedWeight(Float totalInertComputedWeight) {
171         catchesUIModel.setSpeciesTotalInertComputedWeight(totalInertComputedWeight);
172     }
173 
174     @Override
175     public ComputableData<Float> getTotalLivingNotItemizedComputedOrNotWeight() {
176         return catchesUIModel.getSpeciesTotalLivingNotItemizedComputedOrNotWeight();
177     }
178 
179     @Override
180     public Float getTotalLivingNotItemizedWeight() {
181         return catchesUIModel.getSpeciesTotalLivingNotItemizedWeight();
182     }
183 
184     @Override
185     public void setTotalLivingNotItemizedWeight(Float totalLivingNotItemizedWeight) {
186         catchesUIModel.setSpeciesTotalLivingNotItemizedWeight(totalLivingNotItemizedWeight);
187     }
188 
189     @Override
190     public Float getTotalLivingNotItemizedComputedWeight() {
191         return catchesUIModel.getSpeciesTotalLivingNotItemizedComputedWeight();
192     }
193 
194     @Override
195     public void setTotalLivingNotItemizedComputedWeight(Float totalLivingNotItemizedComputedWeight) {
196         catchesUIModel.setSpeciesTotalLivingNotItemizedComputedWeight(totalLivingNotItemizedComputedWeight);
197     }
198 
199     @Override
200     public Integer getDistinctSortedSpeciesCount() {
201         return catchesUIModel.getSpeciesDistinctSortedSpeciesCount();
202     }
203 
204     @Override
205     public void setDistinctSortedSpeciesCount(Integer distinctSortedSpeciesCount) {
206         catchesUIModel.setSpeciesDistinctSortedSpeciesCount(distinctSortedSpeciesCount);
207     }
208 
209     @Override
210     public Integer getDistinctUnsortedSpeciesCount() {
211         return catchesUIModel.getSpeciesDistinctUnsortedSpeciesCount();
212     }
213 
214     @Override
215     public void setDistinctUnsortedSpeciesCount(Integer distinctUnsortedSpeciesCount) {
216         catchesUIModel.setSpeciesDistinctUnsortedSpeciesCount(distinctUnsortedSpeciesCount);
217     }
218 
219     @Override
220     public Map<String, Object> importMultiPost(File file, FishingOperation operation, boolean importFrequencies, boolean importIndivudalObservations) {
221         return context.getMultiPostImportService().importSpecies(file, operation, importFrequencies, importIndivudalObservations);
222     }
223 
224     @Override
225     public MultiPostImportResult importMultiPost(File file, FishingOperation operation, SpeciesBatch speciesBatch, boolean importFrequencies, boolean importIndivudalObservations) {
226         return context.getMultiPostImportService().importSpeciesBatch(file, operation, speciesBatch, importFrequencies, importIndivudalObservations);
227     }
228 
229     @Override
230     public void exportMultiPost(File file, FishingOperation operation, boolean importFrequencies, boolean importIndivudalObservations) {
231         context.getMultiPostExportService().exportSpecies(file, operation, importFrequencies, importIndivudalObservations);
232     }
233 
234     @Override
235     public void exportMultiPost(File file, FishingOperation operation, SpeciesBatch speciesBatch, boolean importFrequencies, boolean importIndivudalObservations) {
236         context.getMultiPostExportService().exportBatch(file, operation, speciesBatch, importFrequencies, importIndivudalObservations);
237     }
238 
239     @Override
240     public SpeciesBatch createBatch(SpeciesBatch speciesBatch, Integer parentBatchId) {
241         return getPersistenceService().createSpeciesBatch(speciesBatch, parentBatchId, true);
242     }
243 
244     @Override
245     public SpeciesBatch saveBatch(SpeciesBatch speciesBatch) {
246         return getPersistenceService().saveSpeciesBatch(speciesBatch);
247     }
248 
249     @Override
250     public List<SpeciesBatchFrequency> saveBatchFrequencies(Integer speciesBatchId, List<SpeciesBatchFrequency> frequency) {
251         return getPersistenceService().saveSpeciesBatchFrequency(speciesBatchId, frequency);
252     }
253 
254     @Override
255     public List<Species> getReferentSpeciesWithSurveyCode(boolean restrictToProtocol) {
256         return context.getDataContext().getReferentSpeciesWithSurveyCode(restrictToProtocol);
257     }
258 
259     @Override
260     public List<Species> getReferentOtherSpeciesWithSurveyCode(boolean restrictToProtocol) {
261         return context.getDataContext().getReferentBenthosWithSurveyCode(restrictToProtocol);
262     }
263 
264     @Override
265     public List<SpeciesProtocol> getSpeciesFromProtocol() {
266         List<SpeciesProtocol> result;
267         TuttiProtocol p = context.getDataContext().getProtocol();
268         if (p != null) {
269             result = p.getSpecies();
270         } else {
271             result = Collections.EMPTY_LIST;
272         }
273         return result;
274     }
275 
276     @Override
277     public void deleteSpeciesSubBatch(Integer speciesBatchId) {
278         getPersistenceService().deleteSpeciesSubBatch(speciesBatchId);
279     }
280 
281     @Override
282     public void deleteSpeciesBatch(Integer speciesBatchId) {
283         getPersistenceService().deleteSpeciesBatch(speciesBatchId);
284     }
285 }