Skip to content

Commit

Permalink
allow for schema column type [path.kingdom.name] to populate value ev…
Browse files Browse the repository at this point in the history
…en though no path ids are available; related to #177
  • Loading branch information
Jorrit Poelen committed Jun 14, 2024
1 parent 0e13e60 commit 3fd3a56
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,19 @@ public static String valueForTaxonProperty(Taxon taxon,
} else if (StringUtils.equalsIgnoreCase(taxonPropertyName, "path.authorship")) {
colValue = taxon.getPathAuthorships();
} else if (StringUtils.startsWith(taxonPropertyName, "path.")
&& ranks.size() > 0
&& ranks.size() == ids.size()
&& names.size() == ids.size()) {
&& ranks.size() > 0) {
String[] split = StringUtils.split(taxonPropertyName, '.');
if (split != null && split.length > 1) {
String rank = split[1];
int i1 = ranks.indexOf(rank);
if (i1 > -1) {
if (split.length > 2) {
String propertyName = split[2];
if ("id".equalsIgnoreCase(propertyName)) {
if ("id".equalsIgnoreCase(propertyName) && ranks.size() == ids.size()) {
colValue = ids.get(i1);
} else if ("name".equalsIgnoreCase(propertyName)) {
} else if ("name".equalsIgnoreCase(propertyName) && ranks.size() == names.size()) {
colValue = names.get(i1);
} else if ("authorship".equalsIgnoreCase(propertyName)) {
} else if ("authorship".equalsIgnoreCase(propertyName) && ranks.size() == authorships.size()) {
colValue = authorships.get(i1);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ public void getKingdomFromPath() {
assertThat(kingdomName, is("someKingdom"));
}

@Test
public void getKingdomFromPath2() {
TaxonImpl taxon = new TaxonImpl("someName", "someId");
taxon.setPath("Animalia | Arthropoda | Insecta | Hymenoptera | Apidae | Apinae | Apini | None | Apis | Apis | Apis mellifera");
taxon.setPathNames("kingdom | phylum | class | order | family | subfamily | tribe | subtribe | genus | subgenus | species");
String kingdomName = AppenderUtil.valueForTaxonProperty(
taxon,
"path.kingdom.name");

assertThat(kingdomName, is("Animalia"));
}

@Test
public void getUnknownKingdomFromPath() {
TaxonImpl taxon = new TaxonImpl("someName", "someId");
Expand Down

0 comments on commit 3fd3a56

Please sign in to comment.