@Test public void testGetAssociatedTaxa() throws Exception { ETLStatistics etlStatistics = new ETLStatistics(); List<AssociatedTaxon> associatedTaxa = null; int listSize = 0; CrsSpecimenTransformer crsSpecimenTransformer = new CrsSpecimenTransformer(etlStatistics); CrsExtractor extractor = new CrsExtractor(specimenFile, etlStatistics); for (XMLRecordInfo extracted : extractor) { CommonReflectionUtil.setField(AbstractTransformer.class, crsSpecimenTransformer, "objectID", "RMNH.MAM.TT.5"); CommonReflectionUtil.setField(AbstractTransformer.class, crsSpecimenTransformer, "input", extracted); Object returned = CommonReflectionUtil.callMethod(null, null, crsSpecimenTransformer, "getAssociatedTaxa"); associatedTaxa = (List<AssociatedTaxon>) returned; listSize = associatedTaxa.size(); } AssociatedTaxon expectedAssociatedTaxon = new AssociatedTaxon( "Achillea millefolium", TaxonRelationType.parse("in relation with") ); assertEquals( "01", 2, listSize); assertTrue("02", associatedTaxa.contains(expectedAssociatedTaxon)); }
private List<AssociatedTaxon> getAssociatedTaxa() { Element record = input.getRecord(); List<Element> elements = DOMUtil.getDescendants(record, "ncrsSynecology"); if (elements == null) { return null; } HashMap<TaxonRelationType, String> relationTypeMap = new HashMap<>(); for (Element element : elements) { String scientificOrInformalName = val(element, "abcd:ScientificOrInformalName"); TaxonRelationType relationType; try { relationType = getTaxonRelationType(element); if (relationType == null) { continue; } else if (relationTypeMap.containsKey(relationType) && scientificOrInformalName != null) { relationTypeMap.put(relationType, relationTypeMap.get(relationType).concat(" | " + scientificOrInformalName)); } else if (scientificOrInformalName != null) { relationTypeMap.put(relationType, scientificOrInformalName); } } catch (IllegalArgumentException e) { if (!suppressErrors) { warn(e.getMessage()); } continue; } } if (relationTypeMap.size() == 0) { return null; } ArrayList<AssociatedTaxon> associatedTaxa = new ArrayList<>(); for (Entry<TaxonRelationType, String> entry : relationTypeMap.entrySet()) { associatedTaxa.add(new AssociatedTaxon(entry.getValue(), entry.getKey())); } return associatedTaxa; }
CrsSpecimenTransformer extends AbstractXMLTransformer<Specimen> { private List<AssociatedTaxon> getAssociatedTaxa() { Element record = input.getRecord(); List<Element> elements = DOMUtil.getDescendants(record, "ncrsSynecology"); if (elements == null) { return null; } HashMap<TaxonRelationType, String> relationTypeMap = new HashMap<>(); for (Element element : elements) { String scientificOrInformalName = val(element, "abcd:ScientificOrInformalName"); TaxonRelationType relationType; try { relationType = getTaxonRelationType(element); if (relationType == null) { continue; } else if (relationTypeMap.containsKey(relationType) && scientificOrInformalName != null) { relationTypeMap.put(relationType, relationTypeMap.get(relationType).concat(" | " + scientificOrInformalName)); } else if (scientificOrInformalName != null) { relationTypeMap.put(relationType, scientificOrInformalName); } } catch (IllegalArgumentException e) { if (!suppressErrors) { warn(e.getMessage()); } continue; } } if (relationTypeMap.size() == 0) { return null; } ArrayList<AssociatedTaxon> associatedTaxa = new ArrayList<>(); for (Entry<TaxonRelationType, String> entry : relationTypeMap.entrySet()) { associatedTaxa.add(new AssociatedTaxon(entry.getValue(), entry.getKey())); } return associatedTaxa; } }
CrsSpecimenTransformer extends AbstractXMLTransformer<Specimen> { private List<AssociatedTaxon> getAssociatedTaxa() { Element record = input.getRecord(); List<Element> elements = DOMUtil.getDescendants(record, "ncrsSynecology"); if (elements == null) { return null; } HashMap<TaxonRelationType, String> relationTypeMap = new HashMap<>(); for (Element element : elements) { String scientificOrInformalName = val(element, "abcd:ScientificOrInformalName"); TaxonRelationType relationType; try { relationType = getTaxonRelationType(element); if (relationType == null) { continue; } else if (relationTypeMap.containsKey(relationType) && scientificOrInformalName != null) { relationTypeMap.put(relationType, relationTypeMap.get(relationType).concat(" | " + scientificOrInformalName)); } else if (scientificOrInformalName != null) { relationTypeMap.put(relationType, scientificOrInformalName); } } catch (IllegalArgumentException e) { if (!suppressErrors) { warn(e.getMessage()); } continue; } } if (relationTypeMap.size() == 0) { return null; } ArrayList<AssociatedTaxon> associatedTaxa = new ArrayList<>(); for (Entry<TaxonRelationType, String> entry : relationTypeMap.entrySet()) { associatedTaxa.add(new AssociatedTaxon(entry.getValue(), entry.getKey())); } return associatedTaxa; } CrsSpecimenTransformer(ETLStatistics stats); }
CrsSpecimenTransformer extends AbstractXMLTransformer<Specimen> { private List<AssociatedTaxon> getAssociatedTaxa() { Element record = input.getRecord(); List<Element> elements = DOMUtil.getDescendants(record, "ncrsSynecology"); if (elements == null) { return null; } HashMap<TaxonRelationType, String> relationTypeMap = new HashMap<>(); for (Element element : elements) { String scientificOrInformalName = val(element, "abcd:ScientificOrInformalName"); TaxonRelationType relationType; try { relationType = getTaxonRelationType(element); if (relationType == null) { continue; } else if (relationTypeMap.containsKey(relationType) && scientificOrInformalName != null) { relationTypeMap.put(relationType, relationTypeMap.get(relationType).concat(" | " + scientificOrInformalName)); } else if (scientificOrInformalName != null) { relationTypeMap.put(relationType, scientificOrInformalName); } } catch (IllegalArgumentException e) { if (!suppressErrors) { warn(e.getMessage()); } continue; } } if (relationTypeMap.size() == 0) { return null; } ArrayList<AssociatedTaxon> associatedTaxa = new ArrayList<>(); for (Entry<TaxonRelationType, String> entry : relationTypeMap.entrySet()) { associatedTaxa.add(new AssociatedTaxon(entry.getValue(), entry.getKey())); } return associatedTaxa; } CrsSpecimenTransformer(ETLStatistics stats);  }
CrsSpecimenTransformer extends AbstractXMLTransformer<Specimen> { private List<AssociatedTaxon> getAssociatedTaxa() { Element record = input.getRecord(); List<Element> elements = DOMUtil.getDescendants(record, "ncrsSynecology"); if (elements == null) { return null; } HashMap<TaxonRelationType, String> relationTypeMap = new HashMap<>(); for (Element element : elements) { String scientificOrInformalName = val(element, "abcd:ScientificOrInformalName"); TaxonRelationType relationType; try { relationType = getTaxonRelationType(element); if (relationType == null) { continue; } else if (relationTypeMap.containsKey(relationType) && scientificOrInformalName != null) { relationTypeMap.put(relationType, relationTypeMap.get(relationType).concat(" | " + scientificOrInformalName)); } else if (scientificOrInformalName != null) { relationTypeMap.put(relationType, scientificOrInformalName); } } catch (IllegalArgumentException e) { if (!suppressErrors) { warn(e.getMessage()); } continue; } } if (relationTypeMap.size() == 0) { return null; } ArrayList<AssociatedTaxon> associatedTaxa = new ArrayList<>(); for (Entry<TaxonRelationType, String> entry : relationTypeMap.entrySet()) { associatedTaxa.add(new AssociatedTaxon(entry.getValue(), entry.getKey())); } return associatedTaxa; } CrsSpecimenTransformer(ETLStatistics stats);   }