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.AccidentalBatch;
26  import fr.ifremer.tutti.persistence.entities.data.Cruise;
27  import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
28  import fr.ifremer.tutti.service.csv.AbstractTuttiImportExportModel;
29  import fr.ifremer.tutti.service.csv.TuttiCsvUtil;
30  import fr.ifremer.tutti.service.genericformat.GenericFormatImportEntityParserFactory;
31  
32  /**
33   * TODO
34   *
35   * @author Tony Chemit - chemit@codelutin.com
36   * @since 2.2
37   */
38  public class AccidentalCatchModel extends AbstractTuttiImportExportModel<AccidentalCatchRow> {
39  
40      public static AccidentalCatchModel forExport(char separator) {
41  
42          AccidentalCatchModel exportModel = new AccidentalCatchModel(separator);
43          exportModel.forExport();
44          return exportModel;
45  
46      }
47  
48      public static AccidentalCatchModel forImport(char separator, GenericFormatImportEntityParserFactory parserFactory) {
49  
50          AccidentalCatchModel importModel = new AccidentalCatchModel(separator);
51          importModel.forImport(parserFactory);
52          return importModel;
53  
54      }
55  
56      @Override
57      public AccidentalCatchRow newEmptyInstance() {
58  
59          return AccidentalCatchRow.newEmptyInstance();
60  
61      }
62  
63      protected AccidentalCatchModel(char separator) {
64          super(separator);
65      }
66  
67      protected void forExport() {
68  
69          newColumnForExport("Annee", Cruise.PROPERTY_BEGIN_DATE, TuttiCsvUtil.YEAR);
70          newColumnForExport("Serie", Cruise.PROPERTY_PROGRAM, TuttiCsvUtil.PROGRAM_FORMATTER);
71          newColumnForExport("Serie_Partielle", Cruise.PROPERTY_SURVEY_PART);
72  
73          newColumnForExport("Code_Station", FishingOperation.PROPERTY_STATION_NUMBER);
74          newColumnForExport("Id_Operation", FishingOperation.PROPERTY_FISHING_OPERATION_NUMBER, TuttiCsvUtil.INTEGER);
75          newColumnForExport("Poche", FishingOperation.PROPERTY_MULTIRIG_AGGREGATION);
76  
77          newColumnForExport("Id_Lot", AccidentalCatchRow.PROPERTY_BATCH_ID, TuttiCsvUtil.PRIMITIVE_INTEGER);
78          newColumnForExport("Code_Taxon", AccidentalBatch.PROPERTY_SPECIES, TuttiCsvUtil.SPECIES_TECHNICAL_FORMATTER);
79          newColumnForExport("Nom_Scientifique", AccidentalBatch.PROPERTY_SPECIES, TuttiCsvUtil.SPECIES_FORMATTER);
80          newColumnForExport("Commentaire", AccidentalBatch.PROPERTY_COMMENT, TuttiCsvUtil.COMMENT_PARSER_FORMATTER);
81          newColumnForExport("Code_PMFM", AccidentalCatchRow.PROPERTY_CARACTERISTIC, TuttiCsvUtil.CARACTERISTIC_TECHNICAL_FORMATTER);
82          newColumnForExport("Libelle_PMFM", AccidentalCatchRow.PROPERTY_CARACTERISTIC, TuttiCsvUtil.CARACTERISTIC_FORMATTER);
83          newColumnForExport("Valeur", AccidentalCatchRow.PROPERTY_CARACTERISTIC_VALUE, TuttiCsvUtil.CARACTERISTIC_VALUE_FORMATTER);
84  
85          newColumnForExport("Serie_Id", Cruise.PROPERTY_PROGRAM, TuttiCsvUtil.PROGRAM_TECHNICAL_FORMATTER);
86          newColumnForExport("Valeur_Id", AccidentalCatchRow.PROPERTY_CARACTERISTIC_VALUE, TuttiCsvUtil.CARACTERISTIC_VALUE_TECHNICAL_FORMATTER);
87  
88      }
89  
90      protected void forImport(GenericFormatImportEntityParserFactory parserFactory) {
91  
92          newMandatoryColumn("Annee", Cruise.PROPERTY_BEGIN_DATE, TuttiCsvUtil.YEAR);
93          newIgnoredColumn("Serie");
94          newMandatoryColumn("Serie_Partielle", Cruise.PROPERTY_SURVEY_PART);
95  
96          newMandatoryColumn("Code_Station", FishingOperation.PROPERTY_STATION_NUMBER);
97          newMandatoryColumn("Id_Operation", FishingOperation.PROPERTY_FISHING_OPERATION_NUMBER, TuttiCsvUtil.INTEGER);
98          newMandatoryColumn("Poche", FishingOperation.PROPERTY_MULTIRIG_AGGREGATION);
99  
100         newMandatoryColumn("Id_Lot", AccidentalCatchRow.PROPERTY_BATCH_ID, TuttiCsvUtil.PRIMITIVE_INTEGER);
101         newMandatoryColumn("Code_Taxon", AccidentalBatch.PROPERTY_SPECIES, parserFactory.getSpeciesParser());
102         newIgnoredColumn("Nom_Scientifique");
103         newMandatoryColumn("Commentaire", AccidentalBatch.PROPERTY_COMMENT, TuttiCsvUtil.COMMENT_PARSER_FORMATTER);
104         newMandatoryColumn("Code_PMFM", AccidentalCatchRow.PROPERTY_CARACTERISTIC, parserFactory.getCaracteristicWithProtectedParser());
105         newIgnoredColumn("Libelle_PMFM");
106         newIgnoredColumn("Valeur");
107 
108         newMandatoryColumn("Serie_Id", Cruise.PROPERTY_PROGRAM, parserFactory.getProgramParser());
109         newMandatoryColumn("Valeur_Id", AccidentalCatchRow.PROPERTY_CARACTERISTIC_VALUE);
110 
111     }
112 
113 }