View Javadoc
1   /*
2    * #%L
3    * Tutti :: Service
4    * %%
5    * Copyright (C) 2012 - 2014 Ifremer
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as
9    * published by the Free Software Foundation, either version 3 of the 
10   * License, or (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Public 
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/gpl-3.0.html>.
20   * #L%
21   */
22  package fr.ifremer.tutti.service.protocol;
23  
24  
25  import fr.ifremer.tutti.persistence.entities.protocol.CaracteristicType;
26  import fr.ifremer.tutti.persistence.entities.referential.Caracteristic;
27  import fr.ifremer.tutti.service.csv.AbstractTuttiImportExportModel;
28  import fr.ifremer.tutti.service.csv.TuttiCsvUtil;
29  
30  import java.util.Map;
31  
32  /**
33   * Model to import / export {@link CaracteristicRow}.
34   *
35   * @author Tony Chemit - chemit@codelutin.com
36   * @since 1.0
37   */
38  public class CaracteristicRowModel extends AbstractTuttiImportExportModel<CaracteristicRow> {
39  
40      public static CaracteristicRowModel forImport(char separator, Map<String, Caracteristic> caracteristicMap) {
41  
42          CaracteristicRowModel result = new CaracteristicRowModel(separator);
43  
44          result.newForeignKeyColumn(CaracteristicRow.PROPERTY_PMFM_ID,
45                                     CaracteristicRow.PROPERTY_PMFM,
46                                     Caracteristic.class,
47                                     Caracteristic.PROPERTY_ID,
48                                     caracteristicMap);
49  
50          result.newMandatoryColumn(CaracteristicRow.PROPERTY_PMFM_TYPE,
51                                    CaracteristicRow.PROPERTY_PMFM_TYPE,
52                                    TuttiCsvUtil.newEnumByNameParserFormatter(CaracteristicType.class, true));
53  
54          result.newMandatoryColumn(CaracteristicRow.PROPERTY_MATURE_STATE_IDS, TuttiCsvUtil.STRING_SET_PARSER_FORMATTER);
55  
56          result.newIgnoredColumn(CaracteristicRow.PROPERTY_PMFM_PARAMETER_NAME);
57          result.newIgnoredColumn(CaracteristicRow.PROPERTY_PMFM_MATRIX_NAME);
58          result.newIgnoredColumn(CaracteristicRow.PROPERTY_PMFM_FRACTION_NAME);
59          result.newIgnoredColumn(CaracteristicRow.PROPERTY_PMFM_METHOD_NAME);
60  
61          return result;
62  
63      }
64  
65      public static CaracteristicRowModel forExport(char separator) {
66  
67          CaracteristicRowModel result = new CaracteristicRowModel(separator);
68  
69          result.newColumnForExport(CaracteristicRow.PROPERTY_PMFM_ID);
70          result.newColumnForExport(CaracteristicRow.PROPERTY_PMFM_TYPE, TuttiCsvUtil.newEnumByNameParserFormatter(CaracteristicType.class, true));
71          result.newColumnForExport(CaracteristicRow.PROPERTY_PMFM_PARAMETER_NAME);
72          result.newColumnForExport(CaracteristicRow.PROPERTY_PMFM_MATRIX_NAME);
73          result.newColumnForExport(CaracteristicRow.PROPERTY_PMFM_FRACTION_NAME);
74          result.newColumnForExport(CaracteristicRow.PROPERTY_PMFM_METHOD_NAME);
75          result.newColumnForExport(CaracteristicRow.PROPERTY_MATURE_STATE_IDS, TuttiCsvUtil.STRING_SET_PARSER_FORMATTER);
76          return result;
77  
78      }
79  
80      @Override
81      public CaracteristicRow newEmptyInstance() {
82          return new CaracteristicRow();
83      }
84  
85      private CaracteristicRowModel(char separator) {
86          super(separator);
87      }
88  
89  }