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 com.google.common.base.Preconditions;
26  import fr.ifremer.tutti.persistence.entities.referential.Species;
27  import org.apache.commons.lang3.StringUtils;
28  
29  import java.io.Serializable;
30  
31  /**
32   * @author Kevin Morin - kmorin@codelutin.com
33   * @since 1.2
34   */
35  public class SpeciesRow implements Serializable {
36  
37      private static final long serialVersionUID = 1L;
38  
39      public static final String PROPERTY_CODE_FIRST_PART = "codeFirstPart";
40  
41      public static final String PROPERTY_CODE_SECOND_PART = "codeSecondPart";
42  
43      public static final String PROPERTY_SCIENTIFIC_NAME = "scientificName";
44  
45      protected final String codeFirstPart;
46  
47      protected final String codeSecondPart;
48  
49      protected final String scientificName;
50  
51      public SpeciesRow(Species species) {
52  
53          String surveyCode = species.getSurveyCode();
54  
55          Preconditions.checkNotNull(surveyCode,
56                                     "Unable to export a species with a null survey code : " + species);
57  
58          int signIndex = surveyCode.indexOf("-");
59  
60          if (signIndex == -1) {
61  
62              // surveyCode is XXXXYYY
63              codeFirstPart = StringUtils.rightPad(StringUtils.substring(surveyCode, 0, 4), 4);
64              codeSecondPart = StringUtils.rightPad(StringUtils.substring(surveyCode, 4, 7), 3);
65  
66          } else {
67  
68              // surveycode is XXXX-YYY
69              codeFirstPart = StringUtils.rightPad(StringUtils.substring(surveyCode, 0, 4), 4);
70              codeSecondPart = StringUtils.rightPad(StringUtils.substring(surveyCode, 5, 8), 3);
71  
72          }
73  
74          scientificName = species.getName();
75  
76      }
77  
78      public String getCodeFirstPart() {
79          return codeFirstPart;
80      }
81  
82      public String getCodeSecondPart() {
83          return codeSecondPart;
84      }
85  
86      public String getScientificName() {
87          return scientificName;
88      }
89  
90  }