@SuppressWarnings({"RedundantArrayCreation", "unchecked"}) @Test public void testTransform() { CSVRecordInfo<CoLReferenceCsvField> record = mock(CSVRecordInfo.class); when(record.get(CoLReferenceCsvField.taxonID)).thenReturn("6931870"); when(record.get(CoLReferenceCsvField.creator)).thenReturn("Pfeiffer, L."); when(record.get(CoLReferenceCsvField.date)).thenReturn("1846"); when(record.get(CoLReferenceCsvField.title)).thenReturn("Diagnosen einiger neuer Heliceen."); when(record.get(CoLReferenceCsvField.description)).thenReturn("Malakozoologische Blätter"); when(record.get(CoLReferenceCsvField.identifier)).thenReturn(""); when(record.get(CoLReferenceCsvField.type)).thenReturn("taxon"); List<CSVRecordInfo<CoLReferenceCsvField>> list = new ArrayList<>(); list.add(record); CoLReferenceBatchTransformer batchTransformer = new CoLReferenceBatchTransformer(); 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 authorName = "Pfeiffer, L."; String citationDetail = "Malakozoologische Blätter"; String titleCitation = "Diagnosen einiger neuer Heliceen."; String publicationDate = "1846-01-01T00:00Z"; 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",authorName, actual.getReferences().iterator().next().getAuthor().getFullName()); assertEquals("10",citationDetail, actual.getReferences().iterator().next().getCitationDetail()); assertEquals("11",titleCitation, actual.getReferences().iterator().next().getTitleCitation()); assertEquals("12",publicationDate, actual.getReferences().iterator().next().getPublicationDate().toString()); }
Collection<Taxon> transform(ArrayList<CSVRecordInfo<CoLReferenceCsvField>> records) { HashMap<String, Taxon> lookupTable = createLookupTable(records); for (CSVRecordInfo<CoLReferenceCsvField> record : records) { String id = record.get(taxonID); Taxon taxon = lookupTable.get(id); Reference reference = createReference(record); if (taxon == null) { if (dry == false && testGenera == null) { ++numOrphans; logger.error("{} | Orphan: {} ", id, reference); } } else if (taxon.getReferences() == null) { ++numCreated; ++numUpdated; taxon.addReference(reference); } else if (!taxon.getReferences().contains(reference)) { ++numCreated; taxon.addReference(reference); } else { ++numDuplicates; logger.error("{} | Duplicate reference: {}", id, reference); } } return lookupTable.values(); }
CoLReferenceBatchTransformer { Collection<Taxon> transform(ArrayList<CSVRecordInfo<CoLReferenceCsvField>> records) { HashMap<String, Taxon> lookupTable = createLookupTable(records); for (CSVRecordInfo<CoLReferenceCsvField> record : records) { String id = record.get(taxonID); Taxon taxon = lookupTable.get(id); Reference reference = createReference(record); if (taxon == null) { if (dry == false && testGenera == null) { ++numOrphans; logger.error("{} | Orphan: {} ", id, reference); } } else if (taxon.getReferences() == null) { ++numCreated; ++numUpdated; taxon.addReference(reference); } else if (!taxon.getReferences().contains(reference)) { ++numCreated; taxon.addReference(reference); } else { ++numDuplicates; logger.error("{} | Duplicate reference: {}", id, reference); } } return lookupTable.values(); } }
CoLReferenceBatchTransformer { Collection<Taxon> transform(ArrayList<CSVRecordInfo<CoLReferenceCsvField>> records) { HashMap<String, Taxon> lookupTable = createLookupTable(records); for (CSVRecordInfo<CoLReferenceCsvField> record : records) { String id = record.get(taxonID); Taxon taxon = lookupTable.get(id); Reference reference = createReference(record); if (taxon == null) { if (dry == false && testGenera == null) { ++numOrphans; logger.error("{} | Orphan: {} ", id, reference); } } else if (taxon.getReferences() == null) { ++numCreated; ++numUpdated; taxon.addReference(reference); } else if (!taxon.getReferences().contains(reference)) { ++numCreated; taxon.addReference(reference); } else { ++numDuplicates; logger.error("{} | Duplicate reference: {}", id, reference); } } return lookupTable.values(); } CoLReferenceBatchTransformer(); }
CoLReferenceBatchTransformer { Collection<Taxon> transform(ArrayList<CSVRecordInfo<CoLReferenceCsvField>> records) { HashMap<String, Taxon> lookupTable = createLookupTable(records); for (CSVRecordInfo<CoLReferenceCsvField> record : records) { String id = record.get(taxonID); Taxon taxon = lookupTable.get(id); Reference reference = createReference(record); if (taxon == null) { if (dry == false && testGenera == null) { ++numOrphans; logger.error("{} | Orphan: {} ", id, reference); } } else if (taxon.getReferences() == null) { ++numCreated; ++numUpdated; taxon.addReference(reference); } else if (!taxon.getReferences().contains(reference)) { ++numCreated; taxon.addReference(reference); } else { ++numDuplicates; logger.error("{} | Duplicate reference: {}", id, reference); } } return lookupTable.values(); } CoLReferenceBatchTransformer();  }
CoLReferenceBatchTransformer { Collection<Taxon> transform(ArrayList<CSVRecordInfo<CoLReferenceCsvField>> records) { HashMap<String, Taxon> lookupTable = createLookupTable(records); for (CSVRecordInfo<CoLReferenceCsvField> record : records) { String id = record.get(taxonID); Taxon taxon = lookupTable.get(id); Reference reference = createReference(record); if (taxon == null) { if (dry == false && testGenera == null) { ++numOrphans; logger.error("{} | Orphan: {} ", id, reference); } } else if (taxon.getReferences() == null) { ++numCreated; ++numUpdated; taxon.addReference(reference); } else if (!taxon.getReferences().contains(reference)) { ++numCreated; taxon.addReference(reference); } else { ++numDuplicates; logger.error("{} | Duplicate reference: {}", id, reference); } } return lookupTable.values(); } CoLReferenceBatchTransformer();   }