Skip to content

Commit

Permalink
Fix fetching mids of multiple non-existent files. Closes #745. (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
wetneb authored Nov 23, 2022
1 parent 9372cc9 commit e6c7841
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public Map<String, MediaInfoIdValue> getMediaInfoIds(List<String> fileNames)
Map.Entry<String, JsonNode> page = iterator.next();
String pageId = page.getKey();
String title = page.getValue().get("title").textValue();
if (!"-1".equals(pageId)) { // "-1" means not found
if (!pageId.startsWith("-")) { // negative keys such as "-1", "-2", ... mean not found
midMap.put(title, Datamodel.makeMediaInfoIdValue("M" + pageId, siteIri));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,21 @@ public void testGetMediaInfoIdNotFound() throws IOException, MediaWikiApiErrorEx
assertNull(result);
}

@Test
public void testGetMediaInfoIdNotFoundTwice() throws IOException, MediaWikiApiErrorException {
Map<String, String> parameters = new HashMap<>();
parameters.put("action", "query");
parameters.put("format", "json");
parameters.put("titles", "File:Not Found|File:Not Found Either");
con.setWebResourceFromPath(parameters, getClass(),
"/query-Not Found twice.json", CompressionType.NONE);

Map<String, MediaInfoIdValue> result = wdf.getMediaInfoIdsByFileName("Not Found", "Not Found Either");
assertEquals(result.size(), 2);
assertNull(result.get("Not Found"));
assertNull(result.get("Not Found Either"));
}

@Test
public void testWbGetVirtualMediaInfoEntityFromTitle() throws IOException, MediaWikiApiErrorException {
Map<String, String> parameters = new HashMap<>();
Expand Down
17 changes: 17 additions & 0 deletions wdtk-wikibaseapi/src/test/resources/query-Not Found twice.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"batchcomplete": "",
"query": {
"pages": {
"-1": {
"ns": 6,
"title": "File:Not Found",
"missing": ""
},
"-2": {
"ns": 6,
"title": "File:Not Found Either",
"missing": ""
}
}
}
}

0 comments on commit e6c7841

Please sign in to comment.