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.persistence.entities.data.MarineLitterBatch;
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   * Model of a marine litter export.
34   *
35   * @author Tony Chemit - chemit@codelutin.com
36   * @since 2.0.1
37   */
38  public class MarineLitterModel extends AbstractTuttiImportExportModel<MarineLitterRow> {
39  
40      public static MarineLitterModel forExport(char separator) {
41  
42          MarineLitterModel exportModel = new MarineLitterModel(separator);
43          exportModel.forExport();
44          return exportModel;
45  
46      }
47  
48      public static MarineLitterModel forImport(char separator, GenericFormatImportEntityParserFactory parserFactory) {
49  
50          MarineLitterModel importModel = new MarineLitterModel(separator);
51          importModel.forImport(parserFactory);
52          return importModel;
53  
54      }
55  
56      @Override
57      public MarineLitterRow newEmptyInstance() {
58  
59          return MarineLitterRow.newEmptyInstance();
60  
61      }
62  
63      protected MarineLitterModel(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("Categorie", MarineLitterBatch.PROPERTY_MARINE_LITTER_CATEGORY, TuttiCsvUtil.CARACTERISTIC_VALUE_FORMATTER);
78          newColumnForExport("Categorie_Taille", MarineLitterBatch.PROPERTY_MARINE_LITTER_SIZE_CATEGORY, TuttiCsvUtil.CARACTERISTIC_VALUE_FORMATTER);
79          newColumnForExport("Nombre", MarineLitterBatch.PROPERTY_NUMBER, TuttiCsvUtil.INTEGER);
80          newColumnForExport("Poids", MarineLitterBatch.PROPERTY_WEIGHT, TuttiCsvUtil.FLOAT);
81          newColumnForExport("Commentaire", MarineLitterBatch.PROPERTY_COMMENT, TuttiCsvUtil.COMMENT_PARSER_FORMATTER);
82  
83          newColumnForExport("Serie_Id", Cruise.PROPERTY_PROGRAM, TuttiCsvUtil.PROGRAM_TECHNICAL_FORMATTER);
84          newColumnForExport("Lot_Id", MarineLitterRow.PROPERTY_MARINE_LITTER_ID, TuttiCsvUtil.INTEGER);
85          newColumnForExport("Categorie_Id", MarineLitterBatch.PROPERTY_MARINE_LITTER_CATEGORY, TuttiCsvUtil.CARACTERISTIC_VALUE_TECHNICAL_FORMATTER);
86          newColumnForExport("Categorie_Taille_Id", MarineLitterBatch.PROPERTY_MARINE_LITTER_SIZE_CATEGORY, 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         newIgnoredColumn("Categorie");
101         newIgnoredColumn("Categorie_Taille");
102         newMandatoryColumn("Nombre", MarineLitterBatch.PROPERTY_NUMBER, TuttiCsvUtil.INTEGER);
103         newMandatoryColumn("Poids", MarineLitterBatch.PROPERTY_WEIGHT, TuttiCsvUtil.FLOAT);
104         newMandatoryColumn("Commentaire", MarineLitterBatch.PROPERTY_COMMENT, TuttiCsvUtil.COMMENT_PARSER_FORMATTER);
105 
106         newMandatoryColumn("Serie_Id", Cruise.PROPERTY_PROGRAM, parserFactory.getProgramParser());
107         newMandatoryColumn("Lot_Id", MarineLitterRow.PROPERTY_MARINE_LITTER_ID, TuttiCsvUtil.INTEGER);
108         newMandatoryColumn("Categorie_Id", MarineLitterBatch.PROPERTY_MARINE_LITTER_CATEGORY, parserFactory.getMarineLitterCategoryValueParser());
109         newMandatoryColumn("Categorie_Taille_Id", MarineLitterBatch.PROPERTY_MARINE_LITTER_SIZE_CATEGORY, parserFactory.getMarineLitterSizeCategoryValueParser());
110 
111     }
112 
113 }