@SuppressWarnings({"unchecked", "RedundantArrayCreation"}) @Test public void testCreateLookupTable() { 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); Object returned = ReflectionUtil.callStatic(CoLReferenceBatchTransformer.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<CoLReferenceCsvField>> records) { HashSet<String> ids = new HashSet<>(records.size()); for (CSVRecordInfo<CoLReferenceCsvField> 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 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; }
CoLReferenceBatchTransformer { private static HashMap<String, Taxon> createLookupTable( ArrayList<CSVRecordInfo<CoLReferenceCsvField>> records) { HashSet<String> ids = new HashSet<>(records.size()); for (CSVRecordInfo<CoLReferenceCsvField> 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 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; } }
CoLReferenceBatchTransformer { private static HashMap<String, Taxon> createLookupTable( ArrayList<CSVRecordInfo<CoLReferenceCsvField>> records) { HashSet<String> ids = new HashSet<>(records.size()); for (CSVRecordInfo<CoLReferenceCsvField> 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 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; } CoLReferenceBatchTransformer(); }
CoLReferenceBatchTransformer { private static HashMap<String, Taxon> createLookupTable( ArrayList<CSVRecordInfo<CoLReferenceCsvField>> records) { HashSet<String> ids = new HashSet<>(records.size()); for (CSVRecordInfo<CoLReferenceCsvField> 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 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; } CoLReferenceBatchTransformer();  }
CoLReferenceBatchTransformer { private static HashMap<String, Taxon> createLookupTable( ArrayList<CSVRecordInfo<CoLReferenceCsvField>> records) { HashSet<String> ids = new HashSet<>(records.size()); for (CSVRecordInfo<CoLReferenceCsvField> 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 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; } CoLReferenceBatchTransformer();   }