@Test public void testGetIdentification() throws Exception { ETLStatistics etlStatistics = new ETLStatistics(); SpecimenIdentification identification = null; CrsSpecimenTransformer crsSpecimenTransformer = new CrsSpecimenTransformer(etlStatistics); CrsExtractor extractor = new CrsExtractor(specimenFile, etlStatistics); outerloop: for (XMLRecordInfo extracted : extractor) { Element rootElement = extracted.getRecord(); List<Element> elems = DOMUtil.getDescendants(rootElement, "ncrsDetermination"); Object obj = CommonReflectionUtil.callMethod(elems, List.class, crsSpecimenTransformer, "hasTestGenus"); boolean check = (boolean) obj; if (check) { for (Element element : elems) { String fullScientificNameStr = DOMUtil.getDescendantValue(element, "abcd:FullScientificNameString"); Object identificationObj = ReflectionUtil.call(crsSpecimenTransformer, "getIdentification", new Class[] {Element.class, String.class}, new Object[] {element, "Arts"}); identification = (SpecimenIdentification) identificationObj; if (identification != null && fullScientificNameStr.equals("Cleyera japonica")) break outerloop; } } } SpecimenIdentification expectedSid = new SpecimenIdentification(); expectedSid.setRockType("Test_Rock"); expectedSid.setAssociatedFossilAssemblage("Test_Assemblage"); expectedSid.setRockMineralUsage("Test_Minerals"); expectedSid.addIdentifier(new Agent("Co de Boswachter")); assertTrue("01", identification.isPreferred()); assertEquals("02",expectedSid.getRockType(), identification.getRockType()); assertEquals("03",expectedSid.getAssociatedFossilAssemblage(), identification.getAssociatedFossilAssemblage()); assertEquals("04",expectedSid.getRockMineralUsage(), identification.getRockMineralUsage()); assertEquals("05",expectedSid.getIdentifiers().get(0).getAgentText(), identification.getIdentifiers().get(0).getAgentText()); }
private SpecimenIdentification getIdentification(Element elem, String collectionType) { ScientificName sn = getScientificName(elem, collectionType); if (sn.getFullScientificName() == null) { if (!suppressErrors) { warn("No scientific name in identification"); } return null; } SpecimenIdentification si = new SpecimenIdentification(); String s = val(elem, "abcd:PreferredFlag"); si.setPreferred(s == null || s.equals("1")); si.setTypeStatus(getTypeStatus(elem)); si.setDateIdentified(date(elem, "abcd:IdentificationDate")); String identifier = val(elem, "abcd:Identifier"); if (identifier != null) si.addIdentifier(new Agent(identifier)); si.setAssociatedFossilAssemblage(val(elem, "abcd:AssociatedFossilAssemblage")); si.setAssociatedMineralName(val(elem, "abcd:AssociatedMineralName")); si.setRockMineralUsage(val(elem, "abcd:RockMineralUsage")); si.setRockType(val(elem, "abcd:RockType")); si.setScientificName(sn); List<Monomial> sc = getSystemClassification(elem, si.getScientificName()); DefaultClassification dc = DefaultClassification.fromSystemClassification(sc); si.setDefaultClassification(dc); String infrasSubspecificRank = val(elem, "abcd:InfrasubspecificRank"); String fullScientificNameStr = val(elem, "abcd:FullScientificNameString"); String taxonCoverageStr = val(elem, "abcd:taxonCoverage"); if (infrasSubspecificRank != null) { si.setTaxonRank(infrasSubspecificRank); } else if (si.getScientificName().getInfraspecificEpithet() != null && si.getScientificName().getGenusOrMonomial() != null) si.setTaxonRank("subspecies"); else if (si.getScientificName().getSpecificEpithet() != null && si.getScientificName().getGenusOrMonomial() != null) si.setTaxonRank("species"); else if (si.getScientificName().getSubgenus() != null && si.getScientificName().getGenusOrMonomial() != null) si.setTaxonRank("subgenus"); else if (si.getScientificName().getGenusOrMonomial() != null) si.setTaxonRank("genus"); else if (fullScientificNameStr != null && fullScientificNameStr.length() > 0) si.setTaxonRank("genus"); else if (taxonCoverageStr != null && taxonCoverageStr.length() > 0) { List<Element> higherNames = DOMUtil.getDescendants(elem, "ncrsHighername"); TaxonomicRank taxonomicRank = getBestTaxonRank(higherNames); if (taxonomicRank != null) si.setTaxonRank(taxonomicRank.getEnglishName()); } String informalNameStr = val(elem, "abcd:InformalNameString"); if (informalNameStr != null) { si.setVernacularNames(Collections.singletonList(new VernacularName(informalNameStr))); } return si; }
CrsSpecimenTransformer extends AbstractXMLTransformer<Specimen> { private SpecimenIdentification getIdentification(Element elem, String collectionType) { ScientificName sn = getScientificName(elem, collectionType); if (sn.getFullScientificName() == null) { if (!suppressErrors) { warn("No scientific name in identification"); } return null; } SpecimenIdentification si = new SpecimenIdentification(); String s = val(elem, "abcd:PreferredFlag"); si.setPreferred(s == null || s.equals("1")); si.setTypeStatus(getTypeStatus(elem)); si.setDateIdentified(date(elem, "abcd:IdentificationDate")); String identifier = val(elem, "abcd:Identifier"); if (identifier != null) si.addIdentifier(new Agent(identifier)); si.setAssociatedFossilAssemblage(val(elem, "abcd:AssociatedFossilAssemblage")); si.setAssociatedMineralName(val(elem, "abcd:AssociatedMineralName")); si.setRockMineralUsage(val(elem, "abcd:RockMineralUsage")); si.setRockType(val(elem, "abcd:RockType")); si.setScientificName(sn); List<Monomial> sc = getSystemClassification(elem, si.getScientificName()); DefaultClassification dc = DefaultClassification.fromSystemClassification(sc); si.setDefaultClassification(dc); String infrasSubspecificRank = val(elem, "abcd:InfrasubspecificRank"); String fullScientificNameStr = val(elem, "abcd:FullScientificNameString"); String taxonCoverageStr = val(elem, "abcd:taxonCoverage"); if (infrasSubspecificRank != null) { si.setTaxonRank(infrasSubspecificRank); } else if (si.getScientificName().getInfraspecificEpithet() != null && si.getScientificName().getGenusOrMonomial() != null) si.setTaxonRank("subspecies"); else if (si.getScientificName().getSpecificEpithet() != null && si.getScientificName().getGenusOrMonomial() != null) si.setTaxonRank("species"); else if (si.getScientificName().getSubgenus() != null && si.getScientificName().getGenusOrMonomial() != null) si.setTaxonRank("subgenus"); else if (si.getScientificName().getGenusOrMonomial() != null) si.setTaxonRank("genus"); else if (fullScientificNameStr != null && fullScientificNameStr.length() > 0) si.setTaxonRank("genus"); else if (taxonCoverageStr != null && taxonCoverageStr.length() > 0) { List<Element> higherNames = DOMUtil.getDescendants(elem, "ncrsHighername"); TaxonomicRank taxonomicRank = getBestTaxonRank(higherNames); if (taxonomicRank != null) si.setTaxonRank(taxonomicRank.getEnglishName()); } String informalNameStr = val(elem, "abcd:InformalNameString"); if (informalNameStr != null) { si.setVernacularNames(Collections.singletonList(new VernacularName(informalNameStr))); } return si; } }
CrsSpecimenTransformer extends AbstractXMLTransformer<Specimen> { private SpecimenIdentification getIdentification(Element elem, String collectionType) { ScientificName sn = getScientificName(elem, collectionType); if (sn.getFullScientificName() == null) { if (!suppressErrors) { warn("No scientific name in identification"); } return null; } SpecimenIdentification si = new SpecimenIdentification(); String s = val(elem, "abcd:PreferredFlag"); si.setPreferred(s == null || s.equals("1")); si.setTypeStatus(getTypeStatus(elem)); si.setDateIdentified(date(elem, "abcd:IdentificationDate")); String identifier = val(elem, "abcd:Identifier"); if (identifier != null) si.addIdentifier(new Agent(identifier)); si.setAssociatedFossilAssemblage(val(elem, "abcd:AssociatedFossilAssemblage")); si.setAssociatedMineralName(val(elem, "abcd:AssociatedMineralName")); si.setRockMineralUsage(val(elem, "abcd:RockMineralUsage")); si.setRockType(val(elem, "abcd:RockType")); si.setScientificName(sn); List<Monomial> sc = getSystemClassification(elem, si.getScientificName()); DefaultClassification dc = DefaultClassification.fromSystemClassification(sc); si.setDefaultClassification(dc); String infrasSubspecificRank = val(elem, "abcd:InfrasubspecificRank"); String fullScientificNameStr = val(elem, "abcd:FullScientificNameString"); String taxonCoverageStr = val(elem, "abcd:taxonCoverage"); if (infrasSubspecificRank != null) { si.setTaxonRank(infrasSubspecificRank); } else if (si.getScientificName().getInfraspecificEpithet() != null && si.getScientificName().getGenusOrMonomial() != null) si.setTaxonRank("subspecies"); else if (si.getScientificName().getSpecificEpithet() != null && si.getScientificName().getGenusOrMonomial() != null) si.setTaxonRank("species"); else if (si.getScientificName().getSubgenus() != null && si.getScientificName().getGenusOrMonomial() != null) si.setTaxonRank("subgenus"); else if (si.getScientificName().getGenusOrMonomial() != null) si.setTaxonRank("genus"); else if (fullScientificNameStr != null && fullScientificNameStr.length() > 0) si.setTaxonRank("genus"); else if (taxonCoverageStr != null && taxonCoverageStr.length() > 0) { List<Element> higherNames = DOMUtil.getDescendants(elem, "ncrsHighername"); TaxonomicRank taxonomicRank = getBestTaxonRank(higherNames); if (taxonomicRank != null) si.setTaxonRank(taxonomicRank.getEnglishName()); } String informalNameStr = val(elem, "abcd:InformalNameString"); if (informalNameStr != null) { si.setVernacularNames(Collections.singletonList(new VernacularName(informalNameStr))); } return si; } CrsSpecimenTransformer(ETLStatistics stats); }
CrsSpecimenTransformer extends AbstractXMLTransformer<Specimen> { private SpecimenIdentification getIdentification(Element elem, String collectionType) { ScientificName sn = getScientificName(elem, collectionType); if (sn.getFullScientificName() == null) { if (!suppressErrors) { warn("No scientific name in identification"); } return null; } SpecimenIdentification si = new SpecimenIdentification(); String s = val(elem, "abcd:PreferredFlag"); si.setPreferred(s == null || s.equals("1")); si.setTypeStatus(getTypeStatus(elem)); si.setDateIdentified(date(elem, "abcd:IdentificationDate")); String identifier = val(elem, "abcd:Identifier"); if (identifier != null) si.addIdentifier(new Agent(identifier)); si.setAssociatedFossilAssemblage(val(elem, "abcd:AssociatedFossilAssemblage")); si.setAssociatedMineralName(val(elem, "abcd:AssociatedMineralName")); si.setRockMineralUsage(val(elem, "abcd:RockMineralUsage")); si.setRockType(val(elem, "abcd:RockType")); si.setScientificName(sn); List<Monomial> sc = getSystemClassification(elem, si.getScientificName()); DefaultClassification dc = DefaultClassification.fromSystemClassification(sc); si.setDefaultClassification(dc); String infrasSubspecificRank = val(elem, "abcd:InfrasubspecificRank"); String fullScientificNameStr = val(elem, "abcd:FullScientificNameString"); String taxonCoverageStr = val(elem, "abcd:taxonCoverage"); if (infrasSubspecificRank != null) { si.setTaxonRank(infrasSubspecificRank); } else if (si.getScientificName().getInfraspecificEpithet() != null && si.getScientificName().getGenusOrMonomial() != null) si.setTaxonRank("subspecies"); else if (si.getScientificName().getSpecificEpithet() != null && si.getScientificName().getGenusOrMonomial() != null) si.setTaxonRank("species"); else if (si.getScientificName().getSubgenus() != null && si.getScientificName().getGenusOrMonomial() != null) si.setTaxonRank("subgenus"); else if (si.getScientificName().getGenusOrMonomial() != null) si.setTaxonRank("genus"); else if (fullScientificNameStr != null && fullScientificNameStr.length() > 0) si.setTaxonRank("genus"); else if (taxonCoverageStr != null && taxonCoverageStr.length() > 0) { List<Element> higherNames = DOMUtil.getDescendants(elem, "ncrsHighername"); TaxonomicRank taxonomicRank = getBestTaxonRank(higherNames); if (taxonomicRank != null) si.setTaxonRank(taxonomicRank.getEnglishName()); } String informalNameStr = val(elem, "abcd:InformalNameString"); if (informalNameStr != null) { si.setVernacularNames(Collections.singletonList(new VernacularName(informalNameStr))); } return si; } CrsSpecimenTransformer(ETLStatistics stats);  }
CrsSpecimenTransformer extends AbstractXMLTransformer<Specimen> { private SpecimenIdentification getIdentification(Element elem, String collectionType) { ScientificName sn = getScientificName(elem, collectionType); if (sn.getFullScientificName() == null) { if (!suppressErrors) { warn("No scientific name in identification"); } return null; } SpecimenIdentification si = new SpecimenIdentification(); String s = val(elem, "abcd:PreferredFlag"); si.setPreferred(s == null || s.equals("1")); si.setTypeStatus(getTypeStatus(elem)); si.setDateIdentified(date(elem, "abcd:IdentificationDate")); String identifier = val(elem, "abcd:Identifier"); if (identifier != null) si.addIdentifier(new Agent(identifier)); si.setAssociatedFossilAssemblage(val(elem, "abcd:AssociatedFossilAssemblage")); si.setAssociatedMineralName(val(elem, "abcd:AssociatedMineralName")); si.setRockMineralUsage(val(elem, "abcd:RockMineralUsage")); si.setRockType(val(elem, "abcd:RockType")); si.setScientificName(sn); List<Monomial> sc = getSystemClassification(elem, si.getScientificName()); DefaultClassification dc = DefaultClassification.fromSystemClassification(sc); si.setDefaultClassification(dc); String infrasSubspecificRank = val(elem, "abcd:InfrasubspecificRank"); String fullScientificNameStr = val(elem, "abcd:FullScientificNameString"); String taxonCoverageStr = val(elem, "abcd:taxonCoverage"); if (infrasSubspecificRank != null) { si.setTaxonRank(infrasSubspecificRank); } else if (si.getScientificName().getInfraspecificEpithet() != null && si.getScientificName().getGenusOrMonomial() != null) si.setTaxonRank("subspecies"); else if (si.getScientificName().getSpecificEpithet() != null && si.getScientificName().getGenusOrMonomial() != null) si.setTaxonRank("species"); else if (si.getScientificName().getSubgenus() != null && si.getScientificName().getGenusOrMonomial() != null) si.setTaxonRank("subgenus"); else if (si.getScientificName().getGenusOrMonomial() != null) si.setTaxonRank("genus"); else if (fullScientificNameStr != null && fullScientificNameStr.length() > 0) si.setTaxonRank("genus"); else if (taxonCoverageStr != null && taxonCoverageStr.length() > 0) { List<Element> higherNames = DOMUtil.getDescendants(elem, "ncrsHighername"); TaxonomicRank taxonomicRank = getBestTaxonRank(higherNames); if (taxonomicRank != null) si.setTaxonRank(taxonomicRank.getEnglishName()); } String informalNameStr = val(elem, "abcd:InformalNameString"); if (informalNameStr != null) { si.setVernacularNames(Collections.singletonList(new VernacularName(informalNameStr))); } return si; } CrsSpecimenTransformer(ETLStatistics stats);   }