@Test public void testCreateLookupTable() { 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); Object returned = ReflectionUtil.callStatic(CoLVernacularNameBatchTransformer.class, "createLookupTable", new Class[] {ArrayList.class}, new Object[] {list}); 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<CoLVernacularNameCsvField>> records) { HashSet<String> ids = new HashSet<>(records.size()); for (CSVRecordInfo<CoLVernacularNameCsvField> record : records) { ids.add(getElasticsearchId(COL, record.get(taxonID))); } DocumentType<Taxon> dt = TAXON; SearchRequest searchRequest = 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(searchRequest); SearchHits hits = response.getHits(); SearchHit[] searchHits = hits.getHits(); HashMap<String, Taxon> taxa = new HashMap<>(searchHits.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; }
CoLVernacularNameBatchTransformer { private static HashMap<String, Taxon> createLookupTable( ArrayList<CSVRecordInfo<CoLVernacularNameCsvField>> records) { HashSet<String> ids = new HashSet<>(records.size()); for (CSVRecordInfo<CoLVernacularNameCsvField> record : records) { ids.add(getElasticsearchId(COL, record.get(taxonID))); } DocumentType<Taxon> dt = TAXON; SearchRequest searchRequest = 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(searchRequest); SearchHits hits = response.getHits(); SearchHit[] searchHits = hits.getHits(); HashMap<String, Taxon> taxa = new HashMap<>(searchHits.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; } }
CoLVernacularNameBatchTransformer { private static HashMap<String, Taxon> createLookupTable( ArrayList<CSVRecordInfo<CoLVernacularNameCsvField>> records) { HashSet<String> ids = new HashSet<>(records.size()); for (CSVRecordInfo<CoLVernacularNameCsvField> record : records) { ids.add(getElasticsearchId(COL, record.get(taxonID))); } DocumentType<Taxon> dt = TAXON; SearchRequest searchRequest = 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(searchRequest); SearchHits hits = response.getHits(); SearchHit[] searchHits = hits.getHits(); HashMap<String, Taxon> taxa = new HashMap<>(searchHits.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; } CoLVernacularNameBatchTransformer(); }
CoLVernacularNameBatchTransformer { private static HashMap<String, Taxon> createLookupTable( ArrayList<CSVRecordInfo<CoLVernacularNameCsvField>> records) { HashSet<String> ids = new HashSet<>(records.size()); for (CSVRecordInfo<CoLVernacularNameCsvField> record : records) { ids.add(getElasticsearchId(COL, record.get(taxonID))); } DocumentType<Taxon> dt = TAXON; SearchRequest searchRequest = 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(searchRequest); SearchHits hits = response.getHits(); SearchHit[] searchHits = hits.getHits(); HashMap<String, Taxon> taxa = new HashMap<>(searchHits.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; } CoLVernacularNameBatchTransformer();  }
CoLVernacularNameBatchTransformer { private static HashMap<String, Taxon> createLookupTable( ArrayList<CSVRecordInfo<CoLVernacularNameCsvField>> records) { HashSet<String> ids = new HashSet<>(records.size()); for (CSVRecordInfo<CoLVernacularNameCsvField> record : records) { ids.add(getElasticsearchId(COL, record.get(taxonID))); } DocumentType<Taxon> dt = TAXON; SearchRequest searchRequest = 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(searchRequest); SearchHits hits = response.getHits(); SearchHit[] searchHits = hits.getHits(); HashMap<String, Taxon> taxa = new HashMap<>(searchHits.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; } CoLVernacularNameBatchTransformer();   }