View Javadoc
1   package fr.ifremer.tutti.service.export.cps;
2   
3   /*
4    * #%L
5    * Tutti :: Service
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 fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue;
28  import fr.ifremer.tutti.persistence.entities.referential.Species;
29  import fr.ifremer.tutti.service.csv.AbstractTuttiImportExportModel;
30  import fr.ifremer.tutti.service.csv.TuttiCsvUtil;
31  import fr.ifremer.tutti.service.sampling.CacheExtractedKey;
32  import org.nuiton.csv.ValueFormatter;
33  import org.nuiton.decorator.Decorator;
34  
35  import static org.nuiton.i18n.I18n.t;
36  
37  /**
38   * @author Kevin Morin (Code Lutin)
39   * @since 4.5
40   */
41  public class SamplingNumberRowModel extends AbstractTuttiImportExportModel<CacheExtractedKey> {
42  
43      public SamplingNumberRowModel(char separator, Decorator<Species> speciesCodeDecorator) {
44          super(separator);
45  
46          newColumnForExport(t("tutti.service.calcifiedPiecesSamplingReport.header.surveyCode"), CacheExtractedKey.PROPERTY_SPECIES, new ValueFormatter<Species>() {
47  
48              @Override
49              public String format(Species species) {
50                  return speciesCodeDecorator.toString(species);
51              }
52          });
53          newColumnForExport(t("tutti.service.calcifiedPiecesSamplingReport.header.geniusName"), CacheExtractedKey.PROPERTY_SPECIES, new ValueFormatter<Species>() {
54  
55              @Override
56              public String format(Species species) {
57                  return species.getName();
58              }
59          });
60          newColumnForExport(t("tutti.service.calcifiedPiecesSamplingReport.header.lengthStep"), CacheExtractedKey.PROPERTY_LENGTH_STEP, TuttiCsvUtil.PRIMITIVE_INTEGER);
61          newColumnForExport(t("tutti.service.calcifiedPiecesSamplingReport.header.maturity"), CacheExtractedKey.PROPERTY_MATURITY, new ValueFormatter<Boolean>() {
62  
63              @Override
64              public String format(Boolean maturity) {
65                  if (maturity == null) {
66                      return "";
67                  }
68                  return maturity ? t("tutti.maturity.mature") : t("tutti.maturity.immature");
69              }
70          });
71          newColumnForExport(t("tutti.service.calcifiedPiecesSamplingReport.header.gender"), CacheExtractedKey.PROPERTY_SEX, new ValueFormatter<CaracteristicQualitativeValue>() {
72              @Override
73              public String format(CaracteristicQualitativeValue value) {
74                  return value == null ? "" : t(value.getDescription());
75              }
76          });
77          newColumnForExport(t("tutti.service.calcifiedPiecesSamplingReport.header.samplingNb"), CacheExtractedKey.PROPERTY_SAMPLING_NB, TuttiCsvUtil.PRIMITIVE_INTEGER);
78          newColumnForExport(t("tutti.service.calcifiedPiecesSamplingReport.header.maxByLengthStep"), CacheExtractedKey.PROPERTY_MAX_BY_LENGTH_STEP, TuttiCsvUtil.INTEGER);
79      }
80  
81      @Override
82      public CacheExtractedKey newEmptyInstance() {
83          return new CacheExtractedKey();
84      }
85  }