Skip to content

Commit

Permalink
Fixed descriptors reinterpretation
Browse files Browse the repository at this point in the history
  • Loading branch information
marcos-lg committed Oct 22, 2024
1 parent ea216fd commit e942929
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public void descriptorsTest() {
descriptors = descriptorsService.listDescriptors(DescriptorSearchRequest.builder().build());
assertEquals(4, descriptors.getResults().size());
assertTrue(descriptors.getResults().stream().allMatch(r -> r.getVerbatim().size() == 4));
descriptors =
descriptorsService.listDescriptors(
DescriptorSearchRequest.builder().usageName(Collections.singletonList("Aves")).build());
assertEquals(2, descriptors.getResults().size());

// check the order of the verbatim fields is the same as in the file
descriptors
Expand Down Expand Up @@ -238,7 +242,7 @@ public void reinterpretationTest() {
collection.setName("n1");
collectionService.create(collection);

Resource descriptorsFile = new ClassPathResource("collections/descriptors.csv");
Resource descriptorsFile = new ClassPathResource("collections/descriptors2.csv");
long descriptorGroupKey =
descriptorsService.createDescriptorGroup(
StreamUtils.copyToByteArray(descriptorsFile.getInputStream()),
Expand Down Expand Up @@ -276,5 +280,10 @@ public void reinterpretationTest() {
descriptorsCount,
descriptorsService.countDescriptors(
DescriptorSearchRequest.builder().descriptorGroupKey(descriptorGroupKey).build()));

PagingResponse<Descriptor> descriptors =
descriptorsService.listDescriptors(
DescriptorSearchRequest.builder().usageName(Collections.singletonList("Aves")).build());
assertEquals(2, descriptors.getResults().size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class InterpreterIT {
@Test
public void typeStatusInterpreterTest() {
Map<String, String> valuesMap = new HashMap<>();
valuesMap.put("dwc:typestatus", "allotype|hyotype|foo|possibly foo");
valuesMap.put("dwc:typeStatus", "allotype|hyotype|foo|possibly foo");

InterpretedResult<List<String>> result =
Interpreter.interpretTypeStatus(valuesMap, conceptClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private void importDescriptorsFile(
String[] headers = csvReader.readNextSilently();
for (int i = 0; i < headers.length; i++) {
headersByIndex.put(i, headers[i]);
headersByName.put(headers[i].toLowerCase(), i);
headersByName.put(headers[i], i);
}

String[] values;
Expand All @@ -153,8 +153,7 @@ private void importDescriptorsFile(

Map<String, String> valuesMap = valuesAndHeadersToMap(values, headersByName);

DescriptorDto descriptorDto = new DescriptorDto();
interpretDescriptor(valuesMap, descriptorDto);
DescriptorDto descriptorDto = interpretDescriptor(valuesMap);
descriptorDto.setDescriptorGroupKey(descriptorGroupKey);
descriptorsMapper.createDescriptor(descriptorDto);

Expand All @@ -174,7 +173,7 @@ private static Map<String, String> valuesAndHeadersToMap(
}

return headersByName.entrySet().stream()
.collect(Collectors.toMap(e -> e.getKey().toLowerCase(), e -> values[e.getValue()]));
.collect(Collectors.toMap(Map.Entry::getKey, e -> values[e.getValue()]));
}

private <T> void setResult(
Expand Down Expand Up @@ -390,8 +389,10 @@ public void reinterpretDescriptorGroup(long descriptorGroupKey) {
while (!descriptorDtos.isEmpty()) {
descriptorDtos.forEach(
dto -> {
interpretDescriptor(verbatimDtosToMap(dto.getVerbatim()), dto);
descriptorsMapper.updateDescriptor(dto);
DescriptorDto reinterpretedDto =
interpretDescriptor(verbatimDtosToMap(dto.getVerbatim()));
reinterpretedDto.setKey(dto.getKey());
descriptorsMapper.updateDescriptor(reinterpretedDto);
});
offset += limit;
descriptorDtos =
Expand Down Expand Up @@ -435,7 +436,8 @@ public void reinterpretAllDescriptorGroups() {
reinterpretCollectionDescriptorGroups(null);
}

private void interpretDescriptor(Map<String, String> valuesMap, DescriptorDto descriptorDto) {
private DescriptorDto interpretDescriptor(Map<String, String> valuesMap) {
DescriptorDto descriptorDto = new DescriptorDto();
// taxonomy
InterpretedResult<Interpreter.TaxonData> taxonomyResult =
Interpreter.interpretTaxonomy(valuesMap, nubResourceClient);
Expand Down Expand Up @@ -515,6 +517,8 @@ private void interpretDescriptor(Map<String, String> valuesMap, DescriptorDto de
Interpreter.interpretString(valuesMap, "ltc:objectClassificationName");
setResult(
descriptorDto, objectClassificationResult, DescriptorDto::setObjectClassificationName);

return descriptorDto;
}

private static Descriptor convertRecordDto(DescriptorDto dto) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,13 @@ private static String extractValue(Map<String, String> valuesMap, DwcTerm term)
}

private static String extractValue(Map<String, String> valuesMap, String fieldName) {
return Optional.ofNullable(valuesMap.get(fieldName.toLowerCase()))
return Optional.ofNullable(valuesMap.get(fieldName))
.filter(v -> !v.isEmpty())
.orElse(null);
}

private static Optional<String> extractOptValue(Map<String, String> valuesMap, DwcTerm term) {
return Optional.ofNullable(valuesMap.get(term.prefixedName().toLowerCase()))
return Optional.ofNullable(valuesMap.get(term.prefixedName()))
.filter(v -> !v.isEmpty());
}

Expand Down

0 comments on commit e942929

Please sign in to comment.