View Javadoc
1   package fr.ifremer.tutti.service.referential.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.referential.Gear;
26  import fr.ifremer.tutti.persistence.entities.referential.Gears;
27  import fr.ifremer.tutti.service.csv.AbstractTuttiImportExportModel;
28  import fr.ifremer.tutti.service.csv.TuttiCsvUtil;
29  import org.nuiton.csv.Common;
30  
31  import static org.nuiton.i18n.I18n.t;
32  
33  /**
34   * Model to import / export {@link Gear} in csv format.
35   *
36   * @author Tony Chemit - chemit@codelutin.com
37   * @since 1.0
38   */
39  public class GearModel extends AbstractTuttiImportExportModel<GearRow> {
40  
41      public static GearModel forExport(char separator) {
42  
43          GearModel exportModel = new GearModel(separator);
44          exportModel.forExport();
45          return exportModel;
46  
47      }
48  
49      public static GearModel forImport(char separator) {
50  
51          GearModel importModel = new GearModel(separator);
52          importModel.forImport();
53          return importModel;
54  
55      }
56  
57      @Override
58      public GearRow newEmptyInstance() {
59          return new GearRow();
60      }
61  
62      protected GearModel(char separator) {
63          super(separator);
64      }
65  
66      protected void forImport() {
67  
68          newMandatoryColumn(GearRow.PROPERTY_ID, new TemporaryReferentialEntityIdParser(
69                  t("tutti.service.referential.import.gear.error.idNotNegative")){
70  
71              @Override
72              protected boolean isTemporaryId(String parse) {
73                  int id = Integer.parseInt(parse);
74                  return Gears.isTemporaryId(id);
75              }
76          });
77          newMandatoryColumn(GearRow.PROPERTY_NAME);
78          newMandatoryColumn(GearRow.PROPERTY_LABEL);
79          newMandatoryColumn(GearRow.PROPERTY_SCIENTIFIC_GEAR, Common.PRIMITIVE_BOOLEAN);
80          newMandatoryColumn(GearRow.PROPERTY_TO_DELETE, TuttiCsvUtil.BOOLEAN);
81  
82      }
83  
84      protected void forExport() {
85  
86          newColumnForExport(GearRow.PROPERTY_ID);
87          newColumnForExport(GearRow.PROPERTY_NAME);
88          newColumnForExport(GearRow.PROPERTY_LABEL);
89          newColumnForExport(GearRow.PROPERTY_SCIENTIFIC_GEAR, Common.PRIMITIVE_BOOLEAN);
90          newColumnForExport(GearRow.PROPERTY_TO_DELETE);
91  
92      }
93  
94  }