View Javadoc
1   package fr.ifremer.tutti.service.genericformat.csv;
2   
3   /*
4    * #%L
5    * Tutti :: Service
6    * %%
7    * Copyright (C) 2012 - 2014 Ifremer
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the 
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public 
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
24  
25  import fr.ifremer.tutti.persistence.entities.data.Cruise;
26  import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
27  import fr.ifremer.tutti.service.csv.AbstractTuttiImportExportModel;
28  import fr.ifremer.tutti.service.csv.TuttiCsvUtil;
29  import fr.ifremer.tutti.service.genericformat.GenericFormatImportEntityParserFactory;
30  
31  /**
32   * Model of a parameter export.
33   *
34   * @author Tony Chemit - chemit@codelutin.com
35   * @since 1.3
36   */
37  public class ParameterModel extends AbstractTuttiImportExportModel<ParameterRow> {
38  
39      public static ParameterModel forExport(char separator) {
40  
41          ParameterModel exportModel = new ParameterModel(separator);
42          exportModel.forExport();
43          return exportModel;
44  
45      }
46  
47      public static ParameterModel forImport(char separator, GenericFormatImportEntityParserFactory parserFactory) {
48  
49          ParameterModel importModel = new ParameterModel(separator);
50          importModel.forImport(parserFactory);
51          return importModel;
52  
53      }
54  
55      @Override
56      public ParameterRow newEmptyInstance() {
57  
58          return ParameterRow.newEmptyInstance();
59  
60      }
61  
62      protected ParameterModel(char separator) {
63          super(separator);
64      }
65  
66      protected void forExport() {
67  
68          newColumnForExport("Annee", Cruise.PROPERTY_BEGIN_DATE, TuttiCsvUtil.YEAR);
69          newColumnForExport("Serie", Cruise.PROPERTY_PROGRAM, TuttiCsvUtil.PROGRAM_FORMATTER);
70          newColumnForExport("Serie_Partielle", Cruise.PROPERTY_SURVEY_PART);
71  
72          newColumnForExport("Code_Station", FishingOperation.PROPERTY_STATION_NUMBER);
73          newColumnForExport("Id_Operation", FishingOperation.PROPERTY_FISHING_OPERATION_NUMBER, TuttiCsvUtil.INTEGER);
74          newColumnForExport("Poche", FishingOperation.PROPERTY_MULTIRIG_AGGREGATION);
75  
76          newColumnForExport("Code_PMFM", ParameterRow.PROPERTY_CARACTERISTIC, TuttiCsvUtil.CARACTERISTIC_TECHNICAL_FORMATTER);
77          newColumnForExport("Libelle_PMFM", ParameterRow.PROPERTY_CARACTERISTIC, TuttiCsvUtil.CARACTERISTIC_FORMATTER);
78          newColumnForExport("Valeur", ParameterRow.PROPERTY_VALUE, TuttiCsvUtil.CARACTERISTIC_VALUE_FORMATTER);
79  
80          newColumnForExport("Type", ParameterRow.PROPERTY_PARAMETER_TYPE, TuttiCsvUtil.newEnumByNameParserFormatter(ParameterRow.ParameterType.class));
81          newColumnForExport("Serie_Id", Cruise.PROPERTY_PROGRAM, TuttiCsvUtil.PROGRAM_TECHNICAL_FORMATTER);
82          newColumnForExport("Valeur_Id", ParameterRow.PROPERTY_VALUE, TuttiCsvUtil.CARACTERISTIC_VALUE_TECHNICAL_FORMATTER);
83  
84      }
85  
86      protected void forImport(GenericFormatImportEntityParserFactory parserFactory) {
87  
88          newMandatoryColumn("Annee", Cruise.PROPERTY_BEGIN_DATE, TuttiCsvUtil.YEAR);
89          newIgnoredColumn("Serie");
90          newMandatoryColumn("Serie_Partielle", Cruise.PROPERTY_SURVEY_PART);
91  
92          newMandatoryColumn("Code_Station", FishingOperation.PROPERTY_STATION_NUMBER);
93          newMandatoryColumn("Id_Operation", FishingOperation.PROPERTY_FISHING_OPERATION_NUMBER, TuttiCsvUtil.INTEGER);
94          newMandatoryColumn("Poche", FishingOperation.PROPERTY_MULTIRIG_AGGREGATION);
95  
96          newMandatoryColumn("Code_PMFM", ParameterRow.PROPERTY_CARACTERISTIC, parserFactory.getCaracteristicParser());
97          newIgnoredColumn("Libelle_PMFM");
98          newIgnoredColumn("Valeur");
99  
100         newMandatoryColumn("Type", ParameterRow.PROPERTY_PARAMETER_TYPE, TuttiCsvUtil.newEnumByNameParserFormatter(ParameterRow.ParameterType.class));
101         newMandatoryColumn("Serie_Id", Cruise.PROPERTY_PROGRAM, parserFactory.getProgramParser());
102         newMandatoryColumn("Valeur_Id", ParameterRow.PROPERTY_VALUE);
103 
104     }
105 
106 }