View Javadoc
1   package fr.ifremer.tutti.service.pupitri.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.service.csv.TuttiCsvUtil;
26  import fr.ifremer.tutti.service.csv.ImportModelWithHeader;
27  import fr.ifremer.tutti.service.pupitri.BoxType;
28  import fr.ifremer.tutti.service.pupitri.Directions;
29  import fr.ifremer.tutti.service.pupitri.Signs;
30  import org.nuiton.csv.Common;
31  import org.nuiton.csv.ValueParser;
32  
33  import java.text.ParseException;
34  
35  /**
36   * @author Kevin Morin - kmorin@codelutin.com
37   * @since 1.2
38   */
39  public class CarrouselRowModel extends ImportModelWithHeader<CarrouselRow> {
40  
41      public CarrouselRowModel(char separator) {
42          super(separator);
43  
44          newMandatoryColumn(CarrouselRow.PROPERTY_OPERATION_CODE);
45          newMandatoryColumn(CarrouselRow.PROPERTY_DATE, new Common.DateValue("dd/MM/yy"));
46          newMandatoryColumn(CarrouselRow.PROPERTY_SPECIES_ID);
47          newMandatoryColumn(CarrouselRow.PROPERTY_SIGN,
48                             new ValueParser<Signs>() {
49                                 @Override
50                                 public Signs parse(String value) throws ParseException {
51                                     Signs result = Signs.getSign(value.toUpperCase());
52                                     if (result == null) {
53                                         throw new ParseException("Could not parse Sign value: " + value, 0);
54                                     }
55                                     return result;
56                                 }
57                             }
58          );
59          newMandatoryColumn(CarrouselRow.PROPERTY_BOX_TYPE,
60                             new ValueParser<BoxType>() {
61                                 @Override
62                                 public BoxType parse(String value) throws ParseException {
63                                     BoxType result = BoxType.getBoxType(value.toUpperCase());
64                                     if (result == null) {
65                                         throw new ParseException("Could not parse BoxType value: " + value, 0);
66                                     }
67                                     return result;
68                                 }
69                             });
70          newMandatoryColumn(CarrouselRow.PROPERTY_DIRECTION, TuttiCsvUtil.newEnumByNameParserFormatter(Directions.class));
71          newMandatoryColumn(CarrouselRow.PROPERTY_WEIGHT, TuttiCsvUtil.WEIGHT_PARSER_FORMATTER);
72  
73          newIgnoredColumn(CarrouselRow.PROPERTY_FILE_ORIGIN);
74          newIgnoredColumn(CarrouselRow.PROPERTY_RIG_NUMBER);
75          newIgnoredColumn(CarrouselRow.PROPERTY_TIME);
76          newIgnoredColumn(CarrouselRow.PROPERTY_BALANCE_ID);
77          newIgnoredColumn(CarrouselRow.PROPERTY_TO_CONFIRM);
78      }
79  
80      @Override
81      public String[] getHeader() {
82          return new String[]{
83                  CarrouselRow.PROPERTY_FILE_ORIGIN,
84                  CarrouselRow.PROPERTY_DATE,
85                  CarrouselRow.PROPERTY_TIME,
86                  CarrouselRow.PROPERTY_BALANCE_ID,
87                  CarrouselRow.PROPERTY_TO_CONFIRM,
88                  CarrouselRow.PROPERTY_OPERATION_CODE,
89                  CarrouselRow.PROPERTY_RIG_NUMBER,
90                  CarrouselRow.PROPERTY_BOX_TYPE,
91                  CarrouselRow.PROPERTY_SPECIES_ID,
92                  CarrouselRow.PROPERTY_SIGN,
93                  CarrouselRow.PROPERTY_DIRECTION,
94                  CarrouselRow.PROPERTY_WEIGHT
95          };
96      }
97  
98      @Override
99      public CarrouselRow newEmptyInstance() {
100         return new CarrouselRow();
101     }
102 
103 }