@Test public void testCreateLookupTable() throws Exception { CSVRecordInfo<CoLTaxonCsvField> record = mock(CSVRecordInfo.class); when(record.get(CoLTaxonCsvField.taxonID)).thenReturn("6931870"); when(record.get(CoLTaxonCsvField.identifier)).thenReturn( "urn:lsid:catalogueoflife.org:taxon:6703cbb5-e478-11e5-86e7-bc764e092680:col20150315"); when(record.get(CoLTaxonCsvField.datasetID)).thenReturn("67"); when(record.get(CoLTaxonCsvField.datasetName)) .thenReturn("ITIS Bees in Species 2000 & ITIS Catalogue of Life: 23rd March 2016"); when(record.get(CoLTaxonCsvField.acceptedNameUsageID)).thenReturn("6931870"); when(record.get(CoLTaxonCsvField.parentNameUsageID)).thenReturn("27000241"); when(record.get(CoLTaxonCsvField.taxonomicStatus)).thenReturn("accepted name"); when(record.get(CoLTaxonCsvField.taxonRank)).thenReturn("species"); when(record.get(CoLTaxonCsvField.verbatimTaxonRank)).thenReturn("test_verbatimTaxonRank"); when(record.get(CoLTaxonCsvField.scientificName)).thenReturn("Bombus affinis Cresson, 1863"); when(record.get(CoLTaxonCsvField.kingdom)).thenReturn("Animalia"); when(record.get(CoLTaxonCsvField.phylum)).thenReturn("Arthropoda"); when(record.get(CoLTaxonCsvField.classRank)).thenReturn("Insecta"); when(record.get(CoLTaxonCsvField.superfamily)).thenReturn("Apoidea"); when(record.get(CoLTaxonCsvField.genericName)).thenReturn("Bombus"); when(record.get(CoLTaxonCsvField.subgenus)).thenReturn("test_subgenus"); when(record.get(CoLTaxonCsvField.specificEpithet)).thenReturn("affinis"); when(record.get(CoLTaxonCsvField.infraspecificEpithet)).thenReturn(""); when(record.get(CoLTaxonCsvField.scientificNameAuthorship)).thenReturn("Cresson, 1863"); when(record.get(CoLTaxonCsvField.source)).thenReturn("test_source"); when(record.get(CoLTaxonCsvField.namePublishedIn)).thenReturn(""); when(record.get(CoLTaxonCsvField.nameAccordingTo)).thenReturn(""); when(record.get(CoLTaxonCsvField.modified)).thenReturn("30-Sep-2008"); when(record.get(CoLTaxonCsvField.description)).thenReturn("test_desc"); when(record.get(CoLTaxonCsvField.taxonConceptID)).thenReturn(""); when(record.get(CoLTaxonCsvField.scientificNameID)).thenReturn("ITS-714782"); when(record.get(CoLTaxonCsvField.references)).thenReturn( "http: when(record.get(CoLTaxonCsvField.isExtinct)).thenReturn("false"); List<CSVRecordInfo<CoLTaxonCsvField>> arrayList = new ArrayList<>(); arrayList.add(record); Object returned = ReflectionUtil.callStatic(CoLSynonymBatchTransformer.class, "createLookupTable", new Class[] {ArrayList.class}, new Object[] {arrayList}); HashMap<String, Taxon> actualResults = (HashMap<String, Taxon>) returned; String expectedKey = "6931870"; Taxon actual = actualResults.get(expectedKey); String expectedId = "6931870@COL"; String expectedScientificNameGroup = "bombus affinis"; String expectedFullScientificName = "Bombus affinis Cresson, 1863"; String expectedSourceSystemName = "Species 2000 - Catalogue Of Life"; String expectedSpcificEpithet = "affinis"; assertEquals("01",expectedKey, actualResults.keySet().iterator().next()); assertEquals("02",expectedId, actual.getId()); assertNotNull("03",actual.getRecordURI()); assertEquals("04",expectedFullScientificName, actual.getAcceptedName().getFullScientificName()); assertEquals("05",expectedScientificNameGroup, actual.getAcceptedName().getScientificNameGroup()); assertEquals("06",expectedSpcificEpithet, actual.getDefaultClassification().getSpecificEpithet()); assertEquals("07",expectedSourceSystemName, actual.getSourceSystem().getName()); }
private static HashMap<String, Taxon> createLookupTable( ArrayList<CSVRecordInfo<CoLTaxonCsvField>> records) { HashSet<String> ids = new HashSet<>(records.size()); for (CSVRecordInfo<CoLTaxonCsvField> record : records) { ids.add(getElasticsearchId(COL, record.get(acceptedNameUsageID))); } DocumentType<Taxon> dt = TAXON; SearchRequest request = ESUtil.newSearchRequest(dt); IdsQueryBuilder query = QueryBuilders.idsQuery(); query.addIds(ids.toArray(new String[ids.size()])); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.trackTotalHits(false); searchSourceBuilder.query(query); searchSourceBuilder.size(ids.size()); SearchResponse response = ESUtil.executeSearchRequest(request); SearchHits searchHits = response.getHits(); SearchHit[] hits = searchHits.getHits(); HashMap<String, Taxon> taxa = new HashMap<>(hits.length + 4, 1F); ObjectMapper om = dt.getObjectMapper(); for (SearchHit hit : hits) { Taxon taxon = om.convertValue(hit.getSourceAsMap(), dt.getJavaType()); taxon.setId(hit.getId()); taxa.put(taxon.getSourceSystemId(), taxon); } return taxa; }
CoLSynonymBatchTransformer { private static HashMap<String, Taxon> createLookupTable( ArrayList<CSVRecordInfo<CoLTaxonCsvField>> records) { HashSet<String> ids = new HashSet<>(records.size()); for (CSVRecordInfo<CoLTaxonCsvField> record : records) { ids.add(getElasticsearchId(COL, record.get(acceptedNameUsageID))); } DocumentType<Taxon> dt = TAXON; SearchRequest request = ESUtil.newSearchRequest(dt); IdsQueryBuilder query = QueryBuilders.idsQuery(); query.addIds(ids.toArray(new String[ids.size()])); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.trackTotalHits(false); searchSourceBuilder.query(query); searchSourceBuilder.size(ids.size()); SearchResponse response = ESUtil.executeSearchRequest(request); SearchHits searchHits = response.getHits(); SearchHit[] hits = searchHits.getHits(); HashMap<String, Taxon> taxa = new HashMap<>(hits.length + 4, 1F); ObjectMapper om = dt.getObjectMapper(); for (SearchHit hit : hits) { Taxon taxon = om.convertValue(hit.getSourceAsMap(), dt.getJavaType()); taxon.setId(hit.getId()); taxa.put(taxon.getSourceSystemId(), taxon); } return taxa; } }
CoLSynonymBatchTransformer { private static HashMap<String, Taxon> createLookupTable( ArrayList<CSVRecordInfo<CoLTaxonCsvField>> records) { HashSet<String> ids = new HashSet<>(records.size()); for (CSVRecordInfo<CoLTaxonCsvField> record : records) { ids.add(getElasticsearchId(COL, record.get(acceptedNameUsageID))); } DocumentType<Taxon> dt = TAXON; SearchRequest request = ESUtil.newSearchRequest(dt); IdsQueryBuilder query = QueryBuilders.idsQuery(); query.addIds(ids.toArray(new String[ids.size()])); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.trackTotalHits(false); searchSourceBuilder.query(query); searchSourceBuilder.size(ids.size()); SearchResponse response = ESUtil.executeSearchRequest(request); SearchHits searchHits = response.getHits(); SearchHit[] hits = searchHits.getHits(); HashMap<String, Taxon> taxa = new HashMap<>(hits.length + 4, 1F); ObjectMapper om = dt.getObjectMapper(); for (SearchHit hit : hits) { Taxon taxon = om.convertValue(hit.getSourceAsMap(), dt.getJavaType()); taxon.setId(hit.getId()); taxa.put(taxon.getSourceSystemId(), taxon); } return taxa; } CoLSynonymBatchTransformer(); }
CoLSynonymBatchTransformer { private static HashMap<String, Taxon> createLookupTable( ArrayList<CSVRecordInfo<CoLTaxonCsvField>> records) { HashSet<String> ids = new HashSet<>(records.size()); for (CSVRecordInfo<CoLTaxonCsvField> record : records) { ids.add(getElasticsearchId(COL, record.get(acceptedNameUsageID))); } DocumentType<Taxon> dt = TAXON; SearchRequest request = ESUtil.newSearchRequest(dt); IdsQueryBuilder query = QueryBuilders.idsQuery(); query.addIds(ids.toArray(new String[ids.size()])); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.trackTotalHits(false); searchSourceBuilder.query(query); searchSourceBuilder.size(ids.size()); SearchResponse response = ESUtil.executeSearchRequest(request); SearchHits searchHits = response.getHits(); SearchHit[] hits = searchHits.getHits(); HashMap<String, Taxon> taxa = new HashMap<>(hits.length + 4, 1F); ObjectMapper om = dt.getObjectMapper(); for (SearchHit hit : hits) { Taxon taxon = om.convertValue(hit.getSourceAsMap(), dt.getJavaType()); taxon.setId(hit.getId()); taxa.put(taxon.getSourceSystemId(), taxon); } return taxa; } CoLSynonymBatchTransformer();  }
CoLSynonymBatchTransformer { private static HashMap<String, Taxon> createLookupTable( ArrayList<CSVRecordInfo<CoLTaxonCsvField>> records) { HashSet<String> ids = new HashSet<>(records.size()); for (CSVRecordInfo<CoLTaxonCsvField> record : records) { ids.add(getElasticsearchId(COL, record.get(acceptedNameUsageID))); } DocumentType<Taxon> dt = TAXON; SearchRequest request = ESUtil.newSearchRequest(dt); IdsQueryBuilder query = QueryBuilders.idsQuery(); query.addIds(ids.toArray(new String[ids.size()])); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.trackTotalHits(false); searchSourceBuilder.query(query); searchSourceBuilder.size(ids.size()); SearchResponse response = ESUtil.executeSearchRequest(request); SearchHits searchHits = response.getHits(); SearchHit[] hits = searchHits.getHits(); HashMap<String, Taxon> taxa = new HashMap<>(hits.length + 4, 1F); ObjectMapper om = dt.getObjectMapper(); for (SearchHit hit : hits) { Taxon taxon = om.convertValue(hit.getSourceAsMap(), dt.getJavaType()); taxon.setId(hit.getId()); taxa.put(taxon.getSourceSystemId(), taxon); } return taxa; } CoLSynonymBatchTransformer();   }