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.service.csv.AbstractTuttiImportExportModel;
27  import fr.ifremer.tutti.service.csv.TuttiCsvUtil;
28  import fr.ifremer.tutti.service.genericformat.GenericFormatImportEntityParserFactory;
29  
30  /**
31   * To export gear caracteristics.
32   *
33   * @author Tony Chemit - chemit@codelutin.com
34   * @since 2.3.2
35   */
36  public class GearCaracteristicModel extends AbstractTuttiImportExportModel<GearCaracteristicRow> {
37  
38      public static GearCaracteristicModel forExport(char separator) {
39  
40          GearCaracteristicModel exportModel = new GearCaracteristicModel(separator);
41          exportModel.forExport();
42          return exportModel;
43  
44      }
45  
46      public static GearCaracteristicModel forImport(char separator, GenericFormatImportEntityParserFactory parserFactory) {
47  
48          GearCaracteristicModel importModel = new GearCaracteristicModel(separator);
49          importModel.forImport(parserFactory);
50          return importModel;
51  
52      }
53  
54      @Override
55      public GearCaracteristicRow newEmptyInstance() {
56  
57          return GearCaracteristicRow.newEmptyInstance();
58  
59      }
60  
61      protected GearCaracteristicModel(char separator) {
62          super(separator);
63      }
64  
65      protected void forExport() {
66  
67          newColumnForExport("Annee", Cruise.PROPERTY_BEGIN_DATE, TuttiCsvUtil.YEAR);
68          newColumnForExport("Serie", Cruise.PROPERTY_PROGRAM, TuttiCsvUtil.PROGRAM_FORMATTER);
69          newColumnForExport("Serie_Partielle", Cruise.PROPERTY_SURVEY_PART);
70  
71          newColumnForExport("Engin", GearCaracteristicRow.PROPERTY_GEAR, TuttiCsvUtil.GEAR_FORMATTER);
72          newColumnForExport("Rang_Engin", GearCaracteristicRow.PROPERTY_RANK_ORDER, TuttiCsvUtil.SHORT);
73  
74          newColumnForExport("Code_PMFM", GearCaracteristicRow.PROPERTY_CARACTERISTIC, TuttiCsvUtil.CARACTERISTIC_TECHNICAL_FORMATTER);
75          newColumnForExport("Libelle_PMFM", GearCaracteristicRow.PROPERTY_CARACTERISTIC, TuttiCsvUtil.CARACTERISTIC_FORMATTER);
76          newColumnForExport("Valeur", GearCaracteristicRow.PROPERTY_VALUE, TuttiCsvUtil.CARACTERISTIC_VALUE_FORMATTER);
77  
78          newColumnForExport("Serie_Id", Cruise.PROPERTY_PROGRAM, TuttiCsvUtil.PROGRAM_TECHNICAL_FORMATTER);
79          newColumnForExport("Engin_Id", GearCaracteristicRow.PROPERTY_GEAR, TuttiCsvUtil.GEAR_TECHNICAL_FORMATTER);
80          newColumnForExport("Valeur_Id", GearCaracteristicRow.PROPERTY_VALUE, TuttiCsvUtil.CARACTERISTIC_VALUE_TECHNICAL_FORMATTER);
81  
82      }
83  
84      protected void forImport(GenericFormatImportEntityParserFactory parserFactory) {
85  
86          newMandatoryColumn("Annee", Cruise.PROPERTY_BEGIN_DATE, TuttiCsvUtil.YEAR);
87          newIgnoredColumn("Serie");
88          newMandatoryColumn("Serie_Partielle", Cruise.PROPERTY_SURVEY_PART);
89  
90          newIgnoredColumn("Engin");
91          newMandatoryColumn("Rang_Engin", GearCaracteristicRow.PROPERTY_RANK_ORDER, TuttiCsvUtil.SHORT);
92  
93          newMandatoryColumn("Code_PMFM", GearCaracteristicRow.PROPERTY_CARACTERISTIC, parserFactory.getCaracteristicParser());
94          newIgnoredColumn("Libelle_PMFM");
95          newIgnoredColumn("Valeur");
96  
97          newMandatoryColumn("Serie_Id", Cruise.PROPERTY_PROGRAM, parserFactory.getProgramParser());
98          newMandatoryColumn("Engin_Id", GearCaracteristicRow.PROPERTY_GEAR, parserFactory.getGearParser());
99          newMandatoryColumn("Valeur_Id", GearCaracteristicRow.PROPERTY_VALUE);
100 
101     }
102 
103 }