@Test public void taxonMapperTest() { List<RankedName> classification = new ArrayList<>(); classification.add( RankedName.newBuilder().setKey(2).setRank(Rank.KINGDOM).setName("Archaea").build()); classification.add( RankedName.newBuilder().setKey(79).setRank(Rank.PHYLUM).setName("Crenarchaeota").build()); classification.add( RankedName.newBuilder() .setKey(8016360) .setRank(Rank.ORDER) .setName("Acidilobales") .build()); classification.add( RankedName.newBuilder().setKey(292).setRank(Rank.CLASS).setName("Thermoprotei").build()); classification.add( RankedName.newBuilder() .setKey(7785) .setRank(Rank.FAMILY) .setName("Caldisphaeraceae") .build()); classification.add( RankedName.newBuilder() .setKey(1000002) .setRank(Rank.GENUS) .setName("Caldisphaera") .build()); classification.add( RankedName.newBuilder() .setKey(1000003) .setRank(Rank.SPECIES) .setName("Caldisphaera lagunensis") .build()); ParsedName parsedName = ParsedName.newBuilder() .setType(NameType.SCIENTIFIC) .setAbbreviated(Boolean.FALSE) .setBasionymAuthorship( Authorship.newBuilder() .setYear("2003") .setAuthors(Collections.singletonList("Itoh & al.")) .setExAuthors(Collections.emptyList()) .setEmpty(Boolean.FALSE) .build()) .setAutonym(Boolean.FALSE) .setBinomial(Boolean.TRUE) .setGenus("Caldisphaera") .setSpecificEpithet("lagunensis") .setNotho(NamePart.SPECIFIC) .setState(State.COMPLETE) .build(); TaxonRecord taxonRecord = new TaxonRecord(); RankedName rankedName = RankedName.newBuilder() .setKey(2492483) .setRank(Rank.SPECIES) .setName("Caldisphaera lagunensis Itoh & al., 2003") .build(); taxonRecord.setUsage(rankedName); taxonRecord.setUsage(rankedName); taxonRecord.setAcceptedUsage(rankedName); taxonRecord.setSynonym(Boolean.FALSE); taxonRecord.setClassification(classification); taxonRecord.setUsageParsedName(parsedName); taxonRecord.setNomenclature(Nomenclature.newBuilder().setSource("nothing").build()); OccurrenceHdfsRecord hdfsRecord = toOccurrenceHdfsRecord(taxonRecord); Assert.assertEquals("Archaea", hdfsRecord.getKingdom()); Assert.assertEquals(Integer.valueOf(2), hdfsRecord.getKingdomkey()); Assert.assertEquals("Crenarchaeota", hdfsRecord.getPhylum()); Assert.assertEquals(Integer.valueOf(79), hdfsRecord.getPhylumkey()); Assert.assertEquals("Acidilobales", hdfsRecord.getOrder()); Assert.assertEquals(Integer.valueOf(8016360), hdfsRecord.getOrderkey()); Assert.assertEquals("Thermoprotei", hdfsRecord.getClass$()); Assert.assertEquals(Integer.valueOf(292), hdfsRecord.getClasskey()); Assert.assertEquals("Caldisphaeraceae", hdfsRecord.getFamily()); Assert.assertEquals(Integer.valueOf(7785), hdfsRecord.getFamilykey()); Assert.assertEquals("Caldisphaera", hdfsRecord.getGenus()); Assert.assertEquals(Integer.valueOf(1000002), hdfsRecord.getGenuskey()); Assert.assertEquals("Caldisphaera lagunensis", hdfsRecord.getSpecies()); Assert.assertEquals(Integer.valueOf(1000003), hdfsRecord.getSpecieskey()); Assert.assertEquals("2492483", hdfsRecord.getAcceptednameusageid()); Assert.assertEquals( "Caldisphaera lagunensis Itoh & al., 2003", hdfsRecord.getAcceptedscientificname()); Assert.assertEquals(Integer.valueOf(2492483), hdfsRecord.getAcceptedtaxonkey()); Assert.assertEquals("Caldisphaera", hdfsRecord.getGenericname()); Assert.assertEquals("lagunensis", hdfsRecord.getSpecificepithet()); }
private static BiConsumer<OccurrenceHdfsRecord, SpecificRecordBase> taxonMapper() { return (hr, sr) -> { TaxonRecord tr = (TaxonRecord) sr; Optional.ofNullable(tr.getUsage()).ifPresent(x -> hr.setTaxonkey(x.getKey())); if (Objects.nonNull(tr.getClassification())) { tr.getClassification() .forEach( rankedName -> { switch (rankedName.getRank()) { case KINGDOM: hr.setKingdom(rankedName.getName()); hr.setKingdomkey(rankedName.getKey()); break; case PHYLUM: hr.setPhylum(rankedName.getName()); hr.setPhylumkey(rankedName.getKey()); break; case CLASS: hr.setClass$(rankedName.getName()); hr.setClasskey(rankedName.getKey()); break; case ORDER: hr.setOrder(rankedName.getName()); hr.setOrderkey(rankedName.getKey()); break; case FAMILY: hr.setFamily(rankedName.getName()); hr.setFamilykey(rankedName.getKey()); break; case GENUS: hr.setGenus(rankedName.getName()); hr.setGenuskey(rankedName.getKey()); break; case SUBGENUS: hr.setSubgenus(rankedName.getName()); hr.setSubgenuskey(rankedName.getKey()); break; case SPECIES: hr.setSpecies(rankedName.getName()); hr.setSpecieskey(rankedName.getKey()); break; default: break; } }); } if (Objects.nonNull(tr.getAcceptedUsage())) { hr.setAcceptedscientificname(tr.getAcceptedUsage().getName()); hr.setAcceptednameusageid(tr.getAcceptedUsage().getKey().toString()); if (Objects.nonNull(tr.getAcceptedUsage().getKey())) { hr.setAcceptedtaxonkey(tr.getAcceptedUsage().getKey()); } Optional.ofNullable(tr.getAcceptedUsage().getRank()) .ifPresent(r -> hr.setTaxonrank(r.name())); } else if (Objects.nonNull(tr.getUsage()) && tr.getUsage().getKey() != 0) { hr.setAcceptedtaxonkey(tr.getUsage().getKey()); hr.setAcceptedscientificname(tr.getUsage().getName()); hr.setAcceptednameusageid(tr.getUsage().getKey().toString()); } if (Objects.nonNull(tr.getUsage())) { hr.setTaxonkey(tr.getUsage().getKey()); hr.setScientificname(tr.getUsage().getName()); Optional.ofNullable(tr.getUsage().getRank()).ifPresent(r -> hr.setTaxonrank(r.name())); } if (Objects.nonNull(tr.getUsageParsedName())) { hr.setGenericname( Objects.nonNull(tr.getUsageParsedName().getGenus()) ? tr.getUsageParsedName().getGenus() : tr.getUsageParsedName().getUninomial()); hr.setSpecificepithet(tr.getUsageParsedName().getSpecificEpithet()); hr.setInfraspecificepithet(tr.getUsageParsedName().getInfraspecificEpithet()); } Optional.ofNullable(tr.getDiagnostics()) .map(Diagnostic::getStatus) .ifPresent(d -> hr.setTaxonomicstatus(d.name())); setCreatedIfGreater(hr, tr.getCreated()); addIssues(tr.getIssues(), hr); }; }
OccurrenceHdfsRecordConverter { private static BiConsumer<OccurrenceHdfsRecord, SpecificRecordBase> taxonMapper() { return (hr, sr) -> { TaxonRecord tr = (TaxonRecord) sr; Optional.ofNullable(tr.getUsage()).ifPresent(x -> hr.setTaxonkey(x.getKey())); if (Objects.nonNull(tr.getClassification())) { tr.getClassification() .forEach( rankedName -> { switch (rankedName.getRank()) { case KINGDOM: hr.setKingdom(rankedName.getName()); hr.setKingdomkey(rankedName.getKey()); break; case PHYLUM: hr.setPhylum(rankedName.getName()); hr.setPhylumkey(rankedName.getKey()); break; case CLASS: hr.setClass$(rankedName.getName()); hr.setClasskey(rankedName.getKey()); break; case ORDER: hr.setOrder(rankedName.getName()); hr.setOrderkey(rankedName.getKey()); break; case FAMILY: hr.setFamily(rankedName.getName()); hr.setFamilykey(rankedName.getKey()); break; case GENUS: hr.setGenus(rankedName.getName()); hr.setGenuskey(rankedName.getKey()); break; case SUBGENUS: hr.setSubgenus(rankedName.getName()); hr.setSubgenuskey(rankedName.getKey()); break; case SPECIES: hr.setSpecies(rankedName.getName()); hr.setSpecieskey(rankedName.getKey()); break; default: break; } }); } if (Objects.nonNull(tr.getAcceptedUsage())) { hr.setAcceptedscientificname(tr.getAcceptedUsage().getName()); hr.setAcceptednameusageid(tr.getAcceptedUsage().getKey().toString()); if (Objects.nonNull(tr.getAcceptedUsage().getKey())) { hr.setAcceptedtaxonkey(tr.getAcceptedUsage().getKey()); } Optional.ofNullable(tr.getAcceptedUsage().getRank()) .ifPresent(r -> hr.setTaxonrank(r.name())); } else if (Objects.nonNull(tr.getUsage()) && tr.getUsage().getKey() != 0) { hr.setAcceptedtaxonkey(tr.getUsage().getKey()); hr.setAcceptedscientificname(tr.getUsage().getName()); hr.setAcceptednameusageid(tr.getUsage().getKey().toString()); } if (Objects.nonNull(tr.getUsage())) { hr.setTaxonkey(tr.getUsage().getKey()); hr.setScientificname(tr.getUsage().getName()); Optional.ofNullable(tr.getUsage().getRank()).ifPresent(r -> hr.setTaxonrank(r.name())); } if (Objects.nonNull(tr.getUsageParsedName())) { hr.setGenericname( Objects.nonNull(tr.getUsageParsedName().getGenus()) ? tr.getUsageParsedName().getGenus() : tr.getUsageParsedName().getUninomial()); hr.setSpecificepithet(tr.getUsageParsedName().getSpecificEpithet()); hr.setInfraspecificepithet(tr.getUsageParsedName().getInfraspecificEpithet()); } Optional.ofNullable(tr.getDiagnostics()) .map(Diagnostic::getStatus) .ifPresent(d -> hr.setTaxonomicstatus(d.name())); setCreatedIfGreater(hr, tr.getCreated()); addIssues(tr.getIssues(), hr); }; } }
OccurrenceHdfsRecordConverter { private static BiConsumer<OccurrenceHdfsRecord, SpecificRecordBase> taxonMapper() { return (hr, sr) -> { TaxonRecord tr = (TaxonRecord) sr; Optional.ofNullable(tr.getUsage()).ifPresent(x -> hr.setTaxonkey(x.getKey())); if (Objects.nonNull(tr.getClassification())) { tr.getClassification() .forEach( rankedName -> { switch (rankedName.getRank()) { case KINGDOM: hr.setKingdom(rankedName.getName()); hr.setKingdomkey(rankedName.getKey()); break; case PHYLUM: hr.setPhylum(rankedName.getName()); hr.setPhylumkey(rankedName.getKey()); break; case CLASS: hr.setClass$(rankedName.getName()); hr.setClasskey(rankedName.getKey()); break; case ORDER: hr.setOrder(rankedName.getName()); hr.setOrderkey(rankedName.getKey()); break; case FAMILY: hr.setFamily(rankedName.getName()); hr.setFamilykey(rankedName.getKey()); break; case GENUS: hr.setGenus(rankedName.getName()); hr.setGenuskey(rankedName.getKey()); break; case SUBGENUS: hr.setSubgenus(rankedName.getName()); hr.setSubgenuskey(rankedName.getKey()); break; case SPECIES: hr.setSpecies(rankedName.getName()); hr.setSpecieskey(rankedName.getKey()); break; default: break; } }); } if (Objects.nonNull(tr.getAcceptedUsage())) { hr.setAcceptedscientificname(tr.getAcceptedUsage().getName()); hr.setAcceptednameusageid(tr.getAcceptedUsage().getKey().toString()); if (Objects.nonNull(tr.getAcceptedUsage().getKey())) { hr.setAcceptedtaxonkey(tr.getAcceptedUsage().getKey()); } Optional.ofNullable(tr.getAcceptedUsage().getRank()) .ifPresent(r -> hr.setTaxonrank(r.name())); } else if (Objects.nonNull(tr.getUsage()) && tr.getUsage().getKey() != 0) { hr.setAcceptedtaxonkey(tr.getUsage().getKey()); hr.setAcceptedscientificname(tr.getUsage().getName()); hr.setAcceptednameusageid(tr.getUsage().getKey().toString()); } if (Objects.nonNull(tr.getUsage())) { hr.setTaxonkey(tr.getUsage().getKey()); hr.setScientificname(tr.getUsage().getName()); Optional.ofNullable(tr.getUsage().getRank()).ifPresent(r -> hr.setTaxonrank(r.name())); } if (Objects.nonNull(tr.getUsageParsedName())) { hr.setGenericname( Objects.nonNull(tr.getUsageParsedName().getGenus()) ? tr.getUsageParsedName().getGenus() : tr.getUsageParsedName().getUninomial()); hr.setSpecificepithet(tr.getUsageParsedName().getSpecificEpithet()); hr.setInfraspecificepithet(tr.getUsageParsedName().getInfraspecificEpithet()); } Optional.ofNullable(tr.getDiagnostics()) .map(Diagnostic::getStatus) .ifPresent(d -> hr.setTaxonomicstatus(d.name())); setCreatedIfGreater(hr, tr.getCreated()); addIssues(tr.getIssues(), hr); }; }  }
OccurrenceHdfsRecordConverter { private static BiConsumer<OccurrenceHdfsRecord, SpecificRecordBase> taxonMapper() { return (hr, sr) -> { TaxonRecord tr = (TaxonRecord) sr; Optional.ofNullable(tr.getUsage()).ifPresent(x -> hr.setTaxonkey(x.getKey())); if (Objects.nonNull(tr.getClassification())) { tr.getClassification() .forEach( rankedName -> { switch (rankedName.getRank()) { case KINGDOM: hr.setKingdom(rankedName.getName()); hr.setKingdomkey(rankedName.getKey()); break; case PHYLUM: hr.setPhylum(rankedName.getName()); hr.setPhylumkey(rankedName.getKey()); break; case CLASS: hr.setClass$(rankedName.getName()); hr.setClasskey(rankedName.getKey()); break; case ORDER: hr.setOrder(rankedName.getName()); hr.setOrderkey(rankedName.getKey()); break; case FAMILY: hr.setFamily(rankedName.getName()); hr.setFamilykey(rankedName.getKey()); break; case GENUS: hr.setGenus(rankedName.getName()); hr.setGenuskey(rankedName.getKey()); break; case SUBGENUS: hr.setSubgenus(rankedName.getName()); hr.setSubgenuskey(rankedName.getKey()); break; case SPECIES: hr.setSpecies(rankedName.getName()); hr.setSpecieskey(rankedName.getKey()); break; default: break; } }); } if (Objects.nonNull(tr.getAcceptedUsage())) { hr.setAcceptedscientificname(tr.getAcceptedUsage().getName()); hr.setAcceptednameusageid(tr.getAcceptedUsage().getKey().toString()); if (Objects.nonNull(tr.getAcceptedUsage().getKey())) { hr.setAcceptedtaxonkey(tr.getAcceptedUsage().getKey()); } Optional.ofNullable(tr.getAcceptedUsage().getRank()) .ifPresent(r -> hr.setTaxonrank(r.name())); } else if (Objects.nonNull(tr.getUsage()) && tr.getUsage().getKey() != 0) { hr.setAcceptedtaxonkey(tr.getUsage().getKey()); hr.setAcceptedscientificname(tr.getUsage().getName()); hr.setAcceptednameusageid(tr.getUsage().getKey().toString()); } if (Objects.nonNull(tr.getUsage())) { hr.setTaxonkey(tr.getUsage().getKey()); hr.setScientificname(tr.getUsage().getName()); Optional.ofNullable(tr.getUsage().getRank()).ifPresent(r -> hr.setTaxonrank(r.name())); } if (Objects.nonNull(tr.getUsageParsedName())) { hr.setGenericname( Objects.nonNull(tr.getUsageParsedName().getGenus()) ? tr.getUsageParsedName().getGenus() : tr.getUsageParsedName().getUninomial()); hr.setSpecificepithet(tr.getUsageParsedName().getSpecificEpithet()); hr.setInfraspecificepithet(tr.getUsageParsedName().getInfraspecificEpithet()); } Optional.ofNullable(tr.getDiagnostics()) .map(Diagnostic::getStatus) .ifPresent(d -> hr.setTaxonomicstatus(d.name())); setCreatedIfGreater(hr, tr.getCreated()); addIssues(tr.getIssues(), hr); }; }  static OccurrenceHdfsRecord toOccurrenceHdfsRecord(SpecificRecordBase... records); }
OccurrenceHdfsRecordConverter { private static BiConsumer<OccurrenceHdfsRecord, SpecificRecordBase> taxonMapper() { return (hr, sr) -> { TaxonRecord tr = (TaxonRecord) sr; Optional.ofNullable(tr.getUsage()).ifPresent(x -> hr.setTaxonkey(x.getKey())); if (Objects.nonNull(tr.getClassification())) { tr.getClassification() .forEach( rankedName -> { switch (rankedName.getRank()) { case KINGDOM: hr.setKingdom(rankedName.getName()); hr.setKingdomkey(rankedName.getKey()); break; case PHYLUM: hr.setPhylum(rankedName.getName()); hr.setPhylumkey(rankedName.getKey()); break; case CLASS: hr.setClass$(rankedName.getName()); hr.setClasskey(rankedName.getKey()); break; case ORDER: hr.setOrder(rankedName.getName()); hr.setOrderkey(rankedName.getKey()); break; case FAMILY: hr.setFamily(rankedName.getName()); hr.setFamilykey(rankedName.getKey()); break; case GENUS: hr.setGenus(rankedName.getName()); hr.setGenuskey(rankedName.getKey()); break; case SUBGENUS: hr.setSubgenus(rankedName.getName()); hr.setSubgenuskey(rankedName.getKey()); break; case SPECIES: hr.setSpecies(rankedName.getName()); hr.setSpecieskey(rankedName.getKey()); break; default: break; } }); } if (Objects.nonNull(tr.getAcceptedUsage())) { hr.setAcceptedscientificname(tr.getAcceptedUsage().getName()); hr.setAcceptednameusageid(tr.getAcceptedUsage().getKey().toString()); if (Objects.nonNull(tr.getAcceptedUsage().getKey())) { hr.setAcceptedtaxonkey(tr.getAcceptedUsage().getKey()); } Optional.ofNullable(tr.getAcceptedUsage().getRank()) .ifPresent(r -> hr.setTaxonrank(r.name())); } else if (Objects.nonNull(tr.getUsage()) && tr.getUsage().getKey() != 0) { hr.setAcceptedtaxonkey(tr.getUsage().getKey()); hr.setAcceptedscientificname(tr.getUsage().getName()); hr.setAcceptednameusageid(tr.getUsage().getKey().toString()); } if (Objects.nonNull(tr.getUsage())) { hr.setTaxonkey(tr.getUsage().getKey()); hr.setScientificname(tr.getUsage().getName()); Optional.ofNullable(tr.getUsage().getRank()).ifPresent(r -> hr.setTaxonrank(r.name())); } if (Objects.nonNull(tr.getUsageParsedName())) { hr.setGenericname( Objects.nonNull(tr.getUsageParsedName().getGenus()) ? tr.getUsageParsedName().getGenus() : tr.getUsageParsedName().getUninomial()); hr.setSpecificepithet(tr.getUsageParsedName().getSpecificEpithet()); hr.setInfraspecificepithet(tr.getUsageParsedName().getInfraspecificEpithet()); } Optional.ofNullable(tr.getDiagnostics()) .map(Diagnostic::getStatus) .ifPresent(d -> hr.setTaxonomicstatus(d.name())); setCreatedIfGreater(hr, tr.getCreated()); addIssues(tr.getIssues(), hr); }; }  static OccurrenceHdfsRecord toOccurrenceHdfsRecord(SpecificRecordBase... records);  }