Skip to content

Commit

Permalink
Merge pull request DSpace#9203 from philipprumpf/issue-9202
Browse files Browse the repository at this point in the history
CrossRefImport: ignore empty responses rather than generating empty phantom ImportRecords
  • Loading branch information
alanorth authored Nov 23, 2023
2 parents 50b47b7 + a68755e commit 06cf8e1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ public List<ImportRecord> call() throws Exception {
Iterator<JsonNode> nodes = jsonNode.at("/message/items").iterator();
while (nodes.hasNext()) {
JsonNode node = nodes.next();
results.add(transformSourceRecords(node.toString()));
if (!node.isMissingNode()) {
results.add(transformSourceRecords(node.toString()));
}
}
return results;
}
Expand Down Expand Up @@ -196,7 +198,9 @@ public List<ImportRecord> call() throws Exception {
String responseString = liveImportClient.executeHttpGetRequest(1000, uriBuilder.toString(), params);
JsonNode jsonNode = convertStringJsonToJsonNode(responseString);
JsonNode messageNode = jsonNode.at("/message");
results.add(transformSourceRecords(messageNode.toString()));
if (!messageNode.isMissingNode()) {
results.add(transformSourceRecords(messageNode.toString()));
}
return results;
}
}
Expand Down Expand Up @@ -250,7 +254,9 @@ public List<ImportRecord> call() throws Exception {
Iterator<JsonNode> nodes = jsonNode.at("/message/items").iterator();
while (nodes.hasNext()) {
JsonNode node = nodes.next();
results.add(transformSourceRecords(node.toString()));
if (!node.isMissingNode()) {
results.add(transformSourceRecords(node.toString()));
}
}
return results;
}
Expand Down Expand Up @@ -333,4 +339,4 @@ public void setUrl(String url) {
this.url = url;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ public class CrossRefImportMetadataSourceServiceIT extends AbstractLiveImportInt
@Autowired
private CrossRefImportMetadataSourceServiceImpl crossRefServiceImpl;

@Test
public void crossRefImportMetadataGetNoRecordsTest() throws Exception {
context.turnOffAuthorisationSystem();
CloseableHttpClient originalHttpClient = liveImportClientImpl.getHttpClient();
CloseableHttpClient httpClient = Mockito.mock(CloseableHttpClient.class);
try {
liveImportClientImpl.setHttpClient(httpClient);
CloseableHttpResponse response = mockResponse("" , 404, "Not Found");
when(httpClient.execute(ArgumentMatchers.any())).thenReturn(response);

context.restoreAuthSystemState();
Collection<ImportRecord> recordsImported = crossRefServiceImpl.getRecords("test query", 0, 2);
assertEquals(0, recordsImported.size());
} finally {
liveImportClientImpl.setHttpClient(originalHttpClient);
}
}

@Test
public void crossRefImportMetadataGetRecordsTest() throws Exception {
context.turnOffAuthorisationSystem();
Expand Down

0 comments on commit 06cf8e1

Please sign in to comment.