Commit cb4f854b authored by Matija Obreza's avatar Matija Obreza
Browse files

Fixed #2: Genus name Qualifier as enum

parent 409a9c21
......@@ -26,6 +26,7 @@ import com.opencsv.CSVParser;
import com.opencsv.CSVReader;
import org.genesys2.gringlobal.taxonomy.model.GenusRow;
import org.genesys2.gringlobal.taxonomy.model.Qualifier;
import org.genesys2.gringlobal.taxonomy.model.SpeciesRow;
/**
......@@ -78,7 +79,7 @@ public class TaxonomyReader {
genusRow.setGenusId(toLong(row[0]));
genusRow.setCurrentGenusId(toLong(row[1]));
genusRow.setFamilyId(toLong(row[2]));
genusRow.setQualifyingCode(row[3]);
genusRow.setQualifyingCode(Qualifier.fromString(row[3]));
genusRow.setHybrid(toBoolean(row[4]));
genusRow.setGenusName(row[5]);
genusRow.setGenusAuthority(row[6]);
......
......@@ -34,19 +34,21 @@ public class GenusRow implements Serializable {
/** The genus id. */
@CsvBind
Long genusId;
/** The current genus id. */
@CsvBind
Long currentGenusId;
/** The family id. */
@CsvBind
Long familyId;
/** The qualifying code. */
/**
* The qualifying code: GRIN genus name qualifier "qual"
*/
@CsvBind
String qualifyingCode;
private Qualifier qualifyingCode;
/** The hybrid. */
@CsvBind
private Boolean hybrid;
......@@ -54,55 +56,55 @@ public class GenusRow implements Serializable {
/** The genus name. */
@CsvBind
private String genusName;
/** The genus authority. */
@CsvBind
private String genusAuthority;
/** The sub genus name. */
@CsvBind
private String subGenusName;
/** The section name. */
@CsvBind
private String sectionName;
/** The sub section name. */
@CsvBind
private String subSectionName;
/** The series name. */
@CsvBind
private String seriesName;
/** The sub series name. */
@CsvBind
private String subSeriesName;
/** The note. */
@CsvBind
private String note;
/** The created date. */
@CsvBind
private Date createdDate;
/** The created by id. */
@CsvBind
private Long createdById;
/** The modified date. */
@CsvBind
private Date modifiedDate;
/** The modified by id. */
@CsvBind
private Long modifiedById;
/** The owned date. */
@CsvBind
private Date ownedDate;
/** The owned by id. */
@CsvBind
private Long ownedById;
......@@ -166,7 +168,7 @@ public class GenusRow implements Serializable {
*
* @return the qualifying code
*/
public String getQualifyingCode() {
public Qualifier getQualifyingCode() {
return qualifyingCode;
}
......@@ -175,7 +177,7 @@ public class GenusRow implements Serializable {
*
* @param qualifyingCode the new qualifying code
*/
public void setQualifyingCode(String qualifyingCode) {
public void setQualifyingCode(Qualifier qualifyingCode) {
this.qualifyingCode = qualifyingCode;
}
......@@ -457,4 +459,9 @@ public class GenusRow implements Serializable {
public boolean isCurrent() {
return genusId.equals(currentGenusId);
}
@Override
public String toString() {
return getGenusName() + " " + getGenusAuthority() + " " + getSubGenusName() + " " + getSubSectionName() + " current=" + isCurrent();
}
}
/*
* Copyright 2016 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.genesys2.gringlobal.taxonomy.model;
/**
* GRIN name qualifier:
* <ul>
* <li>blank if name is accepted without qualification</li>
* <li>"=" if always synonym</li>
* <li>"=~" if mostly a synonym</li>
* <li>"~" if sometimes a synonym</li>
* </ul>
* .
*/
public enum Qualifier {
/** Name accepted without qualification. */
ACCEPTED(""),
/** Always synonym */
ALWAYS_SYNONYM("="),
/** Mostly synonym. */
MOSTLY_SYNONYM("=~"),
/** Sometimes synonym. */
SOMETIMES_SYNONYM("~");
private String value;
/**
* Instantiates a new qualifier.
*
* @param value the value
*/
Qualifier(String value) {
this.value = value;
}
/**
* Gets the String value.
*
* @return the value
*/
public String getValue() {
return value;
}
/**
* Get Qualifier from string code
*
* @param value the value
* @return the qualifier
*/
public static Qualifier fromString(String value) {
if ("~".equals(value)) {
return SOMETIMES_SYNONYM;
} else if ("=~".equals(value)) {
return MOSTLY_SYNONYM;
} else if ("=".equals(value)) {
return Qualifier.ALWAYS_SYNONYM;
} else if ("".equals(value) || null == value) {
return ACCEPTED;
} else {
throw new RuntimeException("No qualifier with code " + value);
}
}
}
......@@ -35,6 +35,7 @@ import com.opencsv.CSVReader;
import org.genesys2.gringlobal.taxonomy.component.TaxonomyReader;
import org.genesys2.gringlobal.taxonomy.model.GenusRow;
import org.genesys2.gringlobal.taxonomy.model.Qualifier;
import org.junit.Test;
/**
......@@ -111,7 +112,7 @@ public class GenusTest {
assertThat(genusRow.getGenusId(), equalTo(2l));
assertThat(genusRow.getCurrentGenusId(), equalTo(2l));
assertThat(genusRow.getFamilyId(), equalTo(1579l));
assertThat(genusRow.getQualifyingCode(), nullValue());
assertThat(genusRow.getQualifyingCode(), equalTo(Qualifier.ACCEPTED));
assertThat(genusRow.getHybrid(), equalTo(true));
assertThat(genusRow.getGenusName(), equalTo("Laburnocytisus"));
assertThat(genusRow.getGenusAuthority(), equalTo("C. K. Schneid."));
......@@ -158,7 +159,7 @@ public class GenusTest {
*/
@Test
public void fullScan() throws UnsupportedEncodingException, FileNotFoundException, IOException, ParseException {
File file = new File("taxonomy_data", "TAXONOMY_GENUS.txt");
File file = new File("../taxonomy_data", "TAXONOMY_GENUS.txt");
if (!file.exists()) {
return;
}
......
......@@ -100,4 +100,15 @@ public class InMemoryDatabaseTest {
assertThat(DATABASE.containsSubtaxa("Vigna", "unguiculata", "var. protracta"), equalTo(true));
assertThat(DATABASE.getSubtaxaAuthority("Vigna", "unguiculata", "var. protracta"), equalTo("(E. Mey.) Verdc."));
}
@Test
public void testTriticosecale() {
if (DATABASE == null) {
return;
}
assertThat(DATABASE.containsGenus("Triticosecale"), equalTo(true));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment