Skip to content

Commit

Permalink
Fix separator for titles in wbgetentity action. Closes #777. (#778)
Browse files Browse the repository at this point in the history
  • Loading branch information
wetneb authored May 12, 2023
1 parent fb21b7f commit d27b662
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public Map<String, EntityDocument> wbGetEntities(String ids, String sites,

Map<String, String> parameters = new HashMap<>();
parameters.put(ApiConnection.PARAM_ACTION, "wbgetentities");
List<String> titlesList = titles == null ? Collections.emptyList() : Arrays.asList(titles.split("-"));
List<String> titlesList = titles == null ? Collections.emptyList() : Arrays.asList(titles.split("\\|"));

if (ids != null) {
parameters.put("ids", ids);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ public void setUp() throws Exception {
params.put("ids", "M91629437");
this.con.setWebResourceFromPath(params, getClass(),
"/wbgetentities-missing-mid.json", CompressionType.NONE);

params.clear();
params.put("action", "wbgetentities");
params.put("format", "json");
params.put("titles", "File:Foo-1.png|File:Bar.svg");
params.put("sites", "commonswiki");
this.con.setWebResourceFromPath(params, getClass(),
"/wbgetentities-titles.json", CompressionType.NONE);

this.action = new WbGetEntitiesAction(this.con, Datamodel.SITE_WIKIDATA);

Expand Down Expand Up @@ -121,6 +129,21 @@ public void testWbGetEntitiesPropsFilters()
assertTrue(result1.containsKey("Q42"));
assertEquals(result1, result2);
}

@Test
public void testWbGetEntitiesTitles()
throws MediaWikiApiErrorException, IOException {
WbGetEntitiesActionData properties = new WbGetEntitiesActionData();
properties.titles = "File:Foo-1.png|File:Bar.svg";
properties.sites = "commonswiki";
Map<String, EntityDocument> result1 = action.wbGetEntities(properties);
Map<String, EntityDocument> result2 = action.wbGetEntities(
null, properties.sites, properties.titles, properties.props, null, null);

assertTrue(result1.containsKey("File:Foo-1.png"));
assertTrue(result1.containsKey("File:Bar.svg"));
assertEquals(result1, result2);
}

@Test(expected = IOException.class)
public void testWbGetEntitiesIoError() throws MediaWikiApiErrorException, IOException {
Expand Down
39 changes: 39 additions & 0 deletions wdtk-wikibaseapi/src/test/resources/wbgetentities-titles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"entities": {
"M89": {
"pageid": 125658679,
"ns": 6,
"title": "File:Foo-1.png",
"lastrevid": 734839557,
"modified": "2023-02-22T14:19:55Z",
"type": "mediainfo",
"id": "M89",
"labels": {
"en": {
"language": "en",
"value": "an amazing foo in its natural habitat"
}
},
"descriptions": {},
"statements": {}
},
"M37": {
"pageid": 1256586,
"ns": 6,
"title": "File:Bar.svg",
"lastrevid": 7348395,
"modified": "2023-02-22T14:19:55Z",
"type": "mediainfo",
"id": "M37",
"labels": {
"en": {
"language": "en",
"value": "the coats of arms of Bar"
}
},
"descriptions": {},
"statements": {}
}
},
"success": 1
}

0 comments on commit d27b662

Please sign in to comment.