@Test public void testTransform() { CSVRecordInfo<CoLVernacularNameCsvField> csvRecordInfo = mock(CSVRecordInfo.class); when(csvRecordInfo.get(CoLVernacularNameCsvField.taxonID)).thenReturn("6931870"); when(csvRecordInfo.get(CoLVernacularNameCsvField.vernacularName)).thenReturn("pinhead spot"); when(csvRecordInfo.get(CoLVernacularNameCsvField.language)).thenReturn("English US"); when(csvRecordInfo.get(CoLVernacularNameCsvField.countryCode)).thenReturn("USA"); when(csvRecordInfo.get(CoLVernacularNameCsvField.locality)).thenReturn(""); when(csvRecordInfo.get(CoLVernacularNameCsvField.transliteration)).thenReturn(""); List<CSVRecordInfo<CoLVernacularNameCsvField>> list = new ArrayList<>(); list.add(csvRecordInfo); CoLVernacularNameBatchTransformer batchTransformer = new CoLVernacularNameBatchTransformer(); Object returned = ReflectionUtil.call(batchTransformer, "transform", new Class[] {ArrayList.class}, new Object[] {list}); Collection<Taxon> updates = (Collection<Taxon>) returned; Taxon actual = updates.iterator().next(); String expectedId = "6931870@COL"; String expectedAuthorshipVerbatim = "Cresson, 1863"; String expectedScientificNameGroup = "bombus affinis"; String expectedFullScientificName = "Bombus affinis Cresson, 1863"; String expectedSourceSystemName = "Species 2000 - Catalogue Of Life"; String expectedSpcificEpithet = "affinis"; String expectedVernecularName = "pinhead spot"; String expectedLanguage = "English US"; assertNotNull("01",actual); assertEquals("02",expectedId, actual.getId()); assertNotNull("03",actual.getRecordURI()); assertEquals("04",expectedAuthorshipVerbatim, actual.getValidName().getAuthorshipVerbatim()); assertEquals("05",expectedScientificNameGroup, actual.getValidName().getScientificNameGroup()); assertEquals("06",expectedFullScientificName, actual.getValidName().getFullScientificName()); assertEquals("07",expectedSourceSystemName, actual.getSourceSystem().getName()); assertEquals("08",expectedSpcificEpithet, actual.getDefaultClassification().getSpecificEpithet()); assertEquals("09",expectedVernecularName, actual.getVernacularNames().iterator().next().getName()); assertEquals("10",expectedLanguage, actual.getVernacularNames().iterator().next().getLanguage()); }
Collection<Taxon> transform(ArrayList<CSVRecordInfo<CoLVernacularNameCsvField>> records) { HashMap<String, Taxon> lookupTable = createLookupTable(records); for (CSVRecordInfo<CoLVernacularNameCsvField> record : records) { String id = record.get(taxonID); Taxon taxon = lookupTable.get(id); VernacularName vernacular = createVernacularName(record); if (taxon == null) { if (dry == false && testGenera == null) { ++numOrphans; logger.error("{} | Orphan: {} ", id, vernacular); } } else if (taxon.getVernacularNames() == null) { ++numCreated; ++numUpdated; taxon.addVernacularName(vernacular); } else if (!taxon.getVernacularNames().contains(vernacular)) { ++numCreated; taxon.addVernacularName(vernacular); } else { ++numDuplicates; logger.error("{} | Duplicate vernacular name: {}", id, vernacular); } } return lookupTable.values(); }
CoLVernacularNameBatchTransformer { Collection<Taxon> transform(ArrayList<CSVRecordInfo<CoLVernacularNameCsvField>> records) { HashMap<String, Taxon> lookupTable = createLookupTable(records); for (CSVRecordInfo<CoLVernacularNameCsvField> record : records) { String id = record.get(taxonID); Taxon taxon = lookupTable.get(id); VernacularName vernacular = createVernacularName(record); if (taxon == null) { if (dry == false && testGenera == null) { ++numOrphans; logger.error("{} | Orphan: {} ", id, vernacular); } } else if (taxon.getVernacularNames() == null) { ++numCreated; ++numUpdated; taxon.addVernacularName(vernacular); } else if (!taxon.getVernacularNames().contains(vernacular)) { ++numCreated; taxon.addVernacularName(vernacular); } else { ++numDuplicates; logger.error("{} | Duplicate vernacular name: {}", id, vernacular); } } return lookupTable.values(); } }
CoLVernacularNameBatchTransformer { Collection<Taxon> transform(ArrayList<CSVRecordInfo<CoLVernacularNameCsvField>> records) { HashMap<String, Taxon> lookupTable = createLookupTable(records); for (CSVRecordInfo<CoLVernacularNameCsvField> record : records) { String id = record.get(taxonID); Taxon taxon = lookupTable.get(id); VernacularName vernacular = createVernacularName(record); if (taxon == null) { if (dry == false && testGenera == null) { ++numOrphans; logger.error("{} | Orphan: {} ", id, vernacular); } } else if (taxon.getVernacularNames() == null) { ++numCreated; ++numUpdated; taxon.addVernacularName(vernacular); } else if (!taxon.getVernacularNames().contains(vernacular)) { ++numCreated; taxon.addVernacularName(vernacular); } else { ++numDuplicates; logger.error("{} | Duplicate vernacular name: {}", id, vernacular); } } return lookupTable.values(); } CoLVernacularNameBatchTransformer(); }
CoLVernacularNameBatchTransformer { Collection<Taxon> transform(ArrayList<CSVRecordInfo<CoLVernacularNameCsvField>> records) { HashMap<String, Taxon> lookupTable = createLookupTable(records); for (CSVRecordInfo<CoLVernacularNameCsvField> record : records) { String id = record.get(taxonID); Taxon taxon = lookupTable.get(id); VernacularName vernacular = createVernacularName(record); if (taxon == null) { if (dry == false && testGenera == null) { ++numOrphans; logger.error("{} | Orphan: {} ", id, vernacular); } } else if (taxon.getVernacularNames() == null) { ++numCreated; ++numUpdated; taxon.addVernacularName(vernacular); } else if (!taxon.getVernacularNames().contains(vernacular)) { ++numCreated; taxon.addVernacularName(vernacular); } else { ++numDuplicates; logger.error("{} | Duplicate vernacular name: {}", id, vernacular); } } return lookupTable.values(); } CoLVernacularNameBatchTransformer();  }
CoLVernacularNameBatchTransformer { Collection<Taxon> transform(ArrayList<CSVRecordInfo<CoLVernacularNameCsvField>> records) { HashMap<String, Taxon> lookupTable = createLookupTable(records); for (CSVRecordInfo<CoLVernacularNameCsvField> record : records) { String id = record.get(taxonID); Taxon taxon = lookupTable.get(id); VernacularName vernacular = createVernacularName(record); if (taxon == null) { if (dry == false && testGenera == null) { ++numOrphans; logger.error("{} | Orphan: {} ", id, vernacular); } } else if (taxon.getVernacularNames() == null) { ++numCreated; ++numUpdated; taxon.addVernacularName(vernacular); } else if (!taxon.getVernacularNames().contains(vernacular)) { ++numCreated; taxon.addVernacularName(vernacular); } else { ++numDuplicates; logger.error("{} | Duplicate vernacular name: {}", id, vernacular); } } return lookupTable.values(); } CoLVernacularNameBatchTransformer();   }