From 1866f9691d633b0d62022b38f4c7fd4d009f6cd5 Mon Sep 17 00:00:00 2001 From: Jacky Date: Fri, 2 Mar 2018 17:09:33 -0500 Subject: [PATCH 1/3] pass the limit as int from javascript --- .../core/scripts/reconciliation/standard-service-panel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/webapp/modules/core/scripts/reconciliation/standard-service-panel.js b/main/webapp/modules/core/scripts/reconciliation/standard-service-panel.js index 72236edf2..ae5ca3d7a 100644 --- a/main/webapp/modules/core/scripts/reconciliation/standard-service-panel.js +++ b/main/webapp/modules/core/scripts/reconciliation/standard-service-panel.js @@ -316,7 +316,7 @@ ReconStandardServicePanel.prototype.start = function() { type: (type) ? { id: type.id, name: type.name } : null, autoMatch: this._elmts.automatchCheck[0].checked, columnDetails: columnDetails, - limit: this._elmts.maxCandidates[0].value + limit: parseInt(this._elmts.maxCandidates[0].value) || 0 }) }, { cellsChanged: true, columnStatsChanged: true } From 8c8b091adce2ec60cb3c61f4c78e426015eca1a3 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Sun, 4 Mar 2018 00:47:06 +0000 Subject: [PATCH 2/3] Accept empty string for the limit in a reconciliation config --- .../model/recon/StandardReconConfig.java | 9 +++-- .../google/refine/tests/model/ReconTests.java | 33 ++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/main/src/com/google/refine/model/recon/StandardReconConfig.java b/main/src/com/google/refine/model/recon/StandardReconConfig.java index f1cb97d3b..07506002f 100644 --- a/main/src/com/google/refine/model/recon/StandardReconConfig.java +++ b/main/src/com/google/refine/model/recon/StandardReconConfig.java @@ -111,8 +111,13 @@ public class StandardReconConfig extends ReconConfig { } JSONObject t = obj.has("type") && !obj.isNull("type") ? obj.getJSONObject("type") : null; - - int limit = obj.has("limit") && !obj.isNull("limit") ? obj.getInt("limit") : 0; + + int limit; + try { + limit = obj.has("limit") && !obj.isNull("limit") ? obj.getInt("limit") : 0; + } catch(JSONException e) { + limit = 0; + } return new StandardReconConfig( obj.getString("service"), diff --git a/main/tests/server/src/com/google/refine/tests/model/ReconTests.java b/main/tests/server/src/com/google/refine/tests/model/ReconTests.java index 5d6466c99..f9a92607c 100644 --- a/main/tests/server/src/com/google/refine/tests/model/ReconTests.java +++ b/main/tests/server/src/com/google/refine/tests/model/ReconTests.java @@ -53,7 +53,7 @@ public class ReconTests extends RefineTest { * @throws Exception */ @Test - public void limitJSONKeyTest() throws Exception { + public void limitJSONKeyAsIntTest() throws Exception { JSONObject obj = new JSONObject( " {\n" + " \"mode\": \"standard-service\",\n" + @@ -74,4 +74,35 @@ public class ReconTests extends RefineTest { // Assert the object is created Assert.assertTrue(config != null); } + + /** + * Regression for issue #1526: + * the UI used to send an empty limit as an empty string, which + * failed to be parsed by the backend. + * @throws Exception + */ + @Test + public void limitJSONKeyAsEmptyStringTest() throws Exception { + JSONObject obj = new JSONObject( + " {\n" + + " \"mode\": \"standard-service\",\n" + + " \"service\": \"https://tools.wmflabs.org/openrefine-wikidata/en/api\",\n" + + " \"identifierSpace\": \"http://www.wikidata.org/entity/\",\n" + + " \"schemaSpace\": \"http://www.wikidata.org/prop/direct/\",\n" + + " \"type\": {\n" + + " \"id\": \"Q13442814\",\n" + + " \"name\": \"scientific article\"\n" + + " },\n" + + " \"autoMatch\": true,\n" + + " \"columnDetails\": [],\n" + + " \"limit\": \"\"\n" + + " }"); + + ReconConfig config = StandardReconConfig.reconstruct(obj); + + // Assert the object is created + Assert.assertTrue(config != null); + } + + } From 75900138dd700dff8d7d3160c633d7f8c6262b3b Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Sun, 4 Mar 2018 22:41:44 +0000 Subject: [PATCH 3/3] Revert "Accept empty string for the limit in a reconciliation config" This reverts commit 8c8b091adce2ec60cb3c61f4c78e426015eca1a3. --- .../model/recon/StandardReconConfig.java | 9 ++--- .../google/refine/tests/model/ReconTests.java | 33 +------------------ 2 files changed, 3 insertions(+), 39 deletions(-) diff --git a/main/src/com/google/refine/model/recon/StandardReconConfig.java b/main/src/com/google/refine/model/recon/StandardReconConfig.java index 07506002f..f1cb97d3b 100644 --- a/main/src/com/google/refine/model/recon/StandardReconConfig.java +++ b/main/src/com/google/refine/model/recon/StandardReconConfig.java @@ -111,13 +111,8 @@ public class StandardReconConfig extends ReconConfig { } JSONObject t = obj.has("type") && !obj.isNull("type") ? obj.getJSONObject("type") : null; - - int limit; - try { - limit = obj.has("limit") && !obj.isNull("limit") ? obj.getInt("limit") : 0; - } catch(JSONException e) { - limit = 0; - } + + int limit = obj.has("limit") && !obj.isNull("limit") ? obj.getInt("limit") : 0; return new StandardReconConfig( obj.getString("service"), diff --git a/main/tests/server/src/com/google/refine/tests/model/ReconTests.java b/main/tests/server/src/com/google/refine/tests/model/ReconTests.java index f9a92607c..5d6466c99 100644 --- a/main/tests/server/src/com/google/refine/tests/model/ReconTests.java +++ b/main/tests/server/src/com/google/refine/tests/model/ReconTests.java @@ -53,7 +53,7 @@ public class ReconTests extends RefineTest { * @throws Exception */ @Test - public void limitJSONKeyAsIntTest() throws Exception { + public void limitJSONKeyTest() throws Exception { JSONObject obj = new JSONObject( " {\n" + " \"mode\": \"standard-service\",\n" + @@ -74,35 +74,4 @@ public class ReconTests extends RefineTest { // Assert the object is created Assert.assertTrue(config != null); } - - /** - * Regression for issue #1526: - * the UI used to send an empty limit as an empty string, which - * failed to be parsed by the backend. - * @throws Exception - */ - @Test - public void limitJSONKeyAsEmptyStringTest() throws Exception { - JSONObject obj = new JSONObject( - " {\n" + - " \"mode\": \"standard-service\",\n" + - " \"service\": \"https://tools.wmflabs.org/openrefine-wikidata/en/api\",\n" + - " \"identifierSpace\": \"http://www.wikidata.org/entity/\",\n" + - " \"schemaSpace\": \"http://www.wikidata.org/prop/direct/\",\n" + - " \"type\": {\n" + - " \"id\": \"Q13442814\",\n" + - " \"name\": \"scientific article\"\n" + - " },\n" + - " \"autoMatch\": true,\n" + - " \"columnDetails\": [],\n" + - " \"limit\": \"\"\n" + - " }"); - - ReconConfig config = StandardReconConfig.reconstruct(obj); - - // Assert the object is created - Assert.assertTrue(config != null); - } - - }