From 8dec08aad3dc3361c0a71388349d4f7443ee3cb4 Mon Sep 17 00:00:00 2001 From: Owen Stephens Date: Fri, 16 Feb 2018 23:40:44 +0000 Subject: [PATCH 1/6] Changed label of 'blank out cells' to 'set cells to null' where English label is used --- main/webapp/modules/core/langs/translation-en.json | 2 +- main/webapp/modules/core/langs/translation-he.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main/webapp/modules/core/langs/translation-en.json b/main/webapp/modules/core/langs/translation-en.json index c2b43aa1a..b7f9898a4 100644 --- a/main/webapp/modules/core/langs/translation-en.json +++ b/main/webapp/modules/core/langs/translation-en.json @@ -614,7 +614,7 @@ "to-number": "To number", "to-date": "To date", "to-text": "To text", - "blank-out": "Blank out cells", + "blank-out": "Set cells to null", "fill-down": "Fill down", "blank-down": "Blank down", "split-cells": "Split multi-valued cells", diff --git a/main/webapp/modules/core/langs/translation-he.json b/main/webapp/modules/core/langs/translation-he.json index 589dbc8b9..8d19918b2 100644 --- a/main/webapp/modules/core/langs/translation-he.json +++ b/main/webapp/modules/core/langs/translation-he.json @@ -578,7 +578,7 @@ "to-number": "To number", "to-date": "To date", "to-text": "To text", - "blank-out": "Blank out cells", + "blank-out": "Set cells to null", "fill-down": "Fill down", "blank-down": "Blank down", "split-cells": "Split multi-valued cells", From d2687cc58a6b27818b0171b99479793d0e9959ac Mon Sep 17 00:00:00 2001 From: Owen Stephens Date: Sun, 18 Feb 2018 23:19:28 +0000 Subject: [PATCH 2/6] Treat null and empty string as different values when doing transforms --- .../google/refine/expr/ExpressionUtils.java | 6 +- .../tests/expr/ExpressionUtilsTests.java | 96 +++++++++++++++++++ 2 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 main/tests/server/src/com/google/refine/tests/expr/ExpressionUtilsTests.java diff --git a/main/src/com/google/refine/expr/ExpressionUtils.java b/main/src/com/google/refine/expr/ExpressionUtils.java index 398eb78a7..2bd2b9c1d 100644 --- a/main/src/com/google/refine/expr/ExpressionUtils.java +++ b/main/src/com/google/refine/expr/ExpressionUtils.java @@ -125,11 +125,9 @@ public class ExpressionUtils { static public boolean sameValue(Object v1, Object v2) { if (v1 == null) { - return (v2 == null) - || (v2 instanceof String && ((String) v2).length() == 0); + return (v2 == null) ; } else if (v2 == null) { - return (v1 == null) - || (v1 instanceof String && ((String) v1).length() == 0); + return (v1 == null); } else { return v1.equals(v2); } diff --git a/main/tests/server/src/com/google/refine/tests/expr/ExpressionUtilsTests.java b/main/tests/server/src/com/google/refine/tests/expr/ExpressionUtilsTests.java new file mode 100644 index 000000000..c51087d3f --- /dev/null +++ b/main/tests/server/src/com/google/refine/tests/expr/ExpressionUtilsTests.java @@ -0,0 +1,96 @@ +/* + +Copyright 2017, Owen Stephens +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of the copyright holder nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +package com.google.refine.tests.expr.functions; + +import java.util.Properties; + +import org.slf4j.LoggerFactory; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import com.google.refine.browsing.Engine; +import com.google.refine.expr.ExpressionUtils; +import com.google.refine.model.Project; +import com.google.refine.tests.RefineTest; + + +public class ExpressionUtilsTests extends RefineTest { + + Project project; + Properties bindings; + + @Override + @BeforeTest + public void init() { + logger = LoggerFactory.getLogger(this.getClass()); + } + + + @BeforeMethod + public void SetUp() { + project = new Project(); + bindings = ExpressionUtils.createBindings(project); + } + + @AfterMethod + public void TearDown() { + project = null; + bindings = null; + } + + // -----------------tests------------ + + @Test + public void testSameValueTrue() { + Assert.assertTrue(ExpressionUtils.sameValue(null,null)); + Assert.assertTrue(ExpressionUtils.sameValue("","")); + Assert.assertTrue(ExpressionUtils.sameValue("one","one")); + Assert.assertTrue(ExpressionUtils.sameValue(1,1)); + Assert.assertTrue(ExpressionUtils.sameValue(1.0,1.00)); + Assert.assertTrue(ExpressionUtils.sameValue(true,true)); + } + + @Test + public void testSameValueFalse() { + Assert.assertFalse(ExpressionUtils.sameValue("",null)); + Assert.assertFalse(ExpressionUtils.sameValue(null,"")); + Assert.assertFalse(ExpressionUtils.sameValue("one","two")); + Assert.assertFalse(ExpressionUtils.sameValue(1,2)); + Assert.assertFalse(ExpressionUtils.sameValue(1,1.0)); + Assert.assertFalse(ExpressionUtils.sameValue(true,false)); + } +} From 0cff8a5c6c5c1a609adb7a89c0214ffc1b70a092 Mon Sep 17 00:00:00 2001 From: Owen Stephens Date: Sun, 18 Feb 2018 23:26:50 +0000 Subject: [PATCH 3/6] Make explict that 'Blank out cells' option sets cells to null --- main/webapp/modules/core/langs/translation-en.json | 2 +- main/webapp/modules/core/langs/translation-es.json | 2 +- main/webapp/modules/core/langs/translation-fil.json | 2 +- main/webapp/modules/core/langs/translation-fr.json | 2 +- main/webapp/modules/core/langs/translation-he.json | 3 ++- main/webapp/modules/core/langs/translation-it.json | 2 +- main/webapp/modules/core/langs/translation-pt_BR.json | 2 +- 7 files changed, 8 insertions(+), 7 deletions(-) diff --git a/main/webapp/modules/core/langs/translation-en.json b/main/webapp/modules/core/langs/translation-en.json index b7f9898a4..b792014df 100644 --- a/main/webapp/modules/core/langs/translation-en.json +++ b/main/webapp/modules/core/langs/translation-en.json @@ -614,7 +614,7 @@ "to-number": "To number", "to-date": "To date", "to-text": "To text", - "blank-out": "Set cells to null", + "blank-out": "Blank out cells (null)", "fill-down": "Fill down", "blank-down": "Blank down", "split-cells": "Split multi-valued cells", diff --git a/main/webapp/modules/core/langs/translation-es.json b/main/webapp/modules/core/langs/translation-es.json index 86cdf73aa..72060aba2 100644 --- a/main/webapp/modules/core/langs/translation-es.json +++ b/main/webapp/modules/core/langs/translation-es.json @@ -576,7 +576,7 @@ "to-number": "A número", "to-date": "A fecha", "to-text": "A texto", - "blank-out": "Vaciar Celdas", + "blank-out": "Vaciar Celdas (null)", "fill-down": "Llenar hacia abajo", "blank-down": "Vaciar hacia abajo", "split-cells": "Dividir celdas multi-valuadas", diff --git a/main/webapp/modules/core/langs/translation-fil.json b/main/webapp/modules/core/langs/translation-fil.json index 8d1804aaf..1ef2c3e06 100644 --- a/main/webapp/modules/core/langs/translation-fil.json +++ b/main/webapp/modules/core/langs/translation-fil.json @@ -475,7 +475,7 @@ "re-trans": "Muling ibahin ang hanggang sa", "warning-no-length": "Hindi tinukoy ang haba ng patlang.", "discard-judg": "Itapon ang mga hatol sa pagkakasundo", - "blank-out": "Mga blankong cell", + "blank-out": "Mga blankong cell (null)", "best-cand-type-match": "tumutugma sa mga uri ng pinakamahusay na kandidato?", "sort-by-col": "ayusin ayon sa hanay na ito lamang", "enter-col-name": "Magpasok ng bagong pangalan ng haligi", diff --git a/main/webapp/modules/core/langs/translation-fr.json b/main/webapp/modules/core/langs/translation-fr.json index bc5665725..c9fedfda9 100644 --- a/main/webapp/modules/core/langs/translation-fr.json +++ b/main/webapp/modules/core/langs/translation-fr.json @@ -476,7 +476,7 @@ "remove-matching": "Supprimer les lignes correspondantes", "warning-no-length": "Aucune longueur de champ n’a été indiquée.", "discard-judg": "Rejeter les avis de réconciliation", - "blank-out": "Vider les cellules", + "blank-out": "Vider les cellules (null)", "best-cand-type-match": "Meilleure correspondance de type des candidats ?", "sort-by-col": "trier selon cette seule colonne", "enter-col-name": "Indiquer le nom de la nouvelle colonne", diff --git a/main/webapp/modules/core/langs/translation-he.json b/main/webapp/modules/core/langs/translation-he.json index 8d19918b2..a246fa891 100644 --- a/main/webapp/modules/core/langs/translation-he.json +++ b/main/webapp/modules/core/langs/translation-he.json @@ -578,7 +578,8 @@ "to-number": "To number", "to-date": "To date", "to-text": "To text", - "blank-out": "Set cells to null", + "blank-out": "Blank out cells (null)", + "empty-cells": "Set cells to empty string", "fill-down": "Fill down", "blank-down": "Blank down", "split-cells": "Split multi-valued cells", diff --git a/main/webapp/modules/core/langs/translation-it.json b/main/webapp/modules/core/langs/translation-it.json index 0db4b8819..e58de6621 100644 --- a/main/webapp/modules/core/langs/translation-it.json +++ b/main/webapp/modules/core/langs/translation-it.json @@ -474,7 +474,7 @@ "re-trans": "Ritrasforma fino a", "warning-no-length": "Nessuna lunghezza dei campi specificata.", "discard-judg": "Annulla i match dei candidati", - "blank-out": "Cancella tutte le celle", + "blank-out": "Cancella tutte le celle (null)", "best-cand-type-match": "miglior match del tipo del candidato?", "sort-by-col": "ordina per questa colonna", "enter-col-name": "Inserisci il nome della nuova colonna", diff --git a/main/webapp/modules/core/langs/translation-pt_BR.json b/main/webapp/modules/core/langs/translation-pt_BR.json index 63c501534..d80038850 100644 --- a/main/webapp/modules/core/langs/translation-pt_BR.json +++ b/main/webapp/modules/core/langs/translation-pt_BR.json @@ -467,7 +467,7 @@ "uppercase": "Para maiúsculo", "best-type": "Best candidate's types", "discard-judg": "Descartar a análise de reconciliação", - "blank-out": "Limpar células", + "blank-out": "Limpar células (null)", "best-cand-type-match": "best candidate's types match?", "sort-by-col": "ordenar somente esta coluna", "enter-col-name": "Digite um nome para a nova coluna", From a8b5052b009e253731852af429a764c9b0c99bdc Mon Sep 17 00:00:00 2001 From: Owen Stephens Date: Sun, 18 Feb 2018 23:35:00 +0000 Subject: [PATCH 4/6] Add "Blank out cells (empty string)" to common transformations menu --- main/webapp/modules/core/langs/translation-en.json | 1 + .../modules/core/scripts/views/data-table/menu-edit-cells.js | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/main/webapp/modules/core/langs/translation-en.json b/main/webapp/modules/core/langs/translation-en.json index b792014df..8f2301147 100644 --- a/main/webapp/modules/core/langs/translation-en.json +++ b/main/webapp/modules/core/langs/translation-en.json @@ -615,6 +615,7 @@ "to-date": "To date", "to-text": "To text", "blank-out": "Blank out cells (null)", + "blank-out-empty": "Blank out cells (empty string)", "fill-down": "Fill down", "blank-down": "Blank down", "split-cells": "Split multi-valued cells", diff --git a/main/webapp/modules/core/scripts/views/data-table/menu-edit-cells.js b/main/webapp/modules/core/scripts/views/data-table/menu-edit-cells.js index ec0343e67..8298bdc2e 100644 --- a/main/webapp/modules/core/scripts/views/data-table/menu-edit-cells.js +++ b/main/webapp/modules/core/scripts/views/data-table/menu-edit-cells.js @@ -268,6 +268,11 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) { id: "core/to-blank", label: $.i18n._('core-views')["blank-out"], click: function() { doTextTransform("null", "keep-original", false, ""); } + }, + { + id: "core/to-empty", + label: $.i18n._('core-views')["blank-out-empty"], + click: function() { doTextTransform("\"\"", "keep-original", false, ""); } } ] }, From c172e2d66d9302be500253d3f90d19884b9b2532 Mon Sep 17 00:00:00 2001 From: Owen Stephens Date: Mon, 19 Feb 2018 09:09:20 +0000 Subject: [PATCH 5/6] Updated translations --- main/webapp/modules/core/langs/translation-en.json | 4 ++-- main/webapp/modules/core/langs/translation-es.json | 2 +- main/webapp/modules/core/langs/translation-fil.json | 2 +- main/webapp/modules/core/langs/translation-fr.json | 2 +- main/webapp/modules/core/langs/translation-he.json | 3 ++- main/webapp/modules/core/langs/translation-it.json | 2 +- main/webapp/modules/core/langs/translation-pt_BR.json | 2 +- 7 files changed, 9 insertions(+), 8 deletions(-) diff --git a/main/webapp/modules/core/langs/translation-en.json b/main/webapp/modules/core/langs/translation-en.json index 8f2301147..aff50f5bb 100644 --- a/main/webapp/modules/core/langs/translation-en.json +++ b/main/webapp/modules/core/langs/translation-en.json @@ -614,8 +614,8 @@ "to-number": "To number", "to-date": "To date", "to-text": "To text", - "blank-out": "Blank out cells (null)", - "blank-out-empty": "Blank out cells (empty string)", + "blank-out": "To null", + "blank-out-empty": "To empty string", "fill-down": "Fill down", "blank-down": "Blank down", "split-cells": "Split multi-valued cells", diff --git a/main/webapp/modules/core/langs/translation-es.json b/main/webapp/modules/core/langs/translation-es.json index 72060aba2..612dc05bf 100644 --- a/main/webapp/modules/core/langs/translation-es.json +++ b/main/webapp/modules/core/langs/translation-es.json @@ -576,7 +576,7 @@ "to-number": "A número", "to-date": "A fecha", "to-text": "A texto", - "blank-out": "Vaciar Celdas (null)", + "blank-out": "Establecer celdas en nulo", "fill-down": "Llenar hacia abajo", "blank-down": "Vaciar hacia abajo", "split-cells": "Dividir celdas multi-valuadas", diff --git a/main/webapp/modules/core/langs/translation-fil.json b/main/webapp/modules/core/langs/translation-fil.json index 1ef2c3e06..66b56f3e5 100644 --- a/main/webapp/modules/core/langs/translation-fil.json +++ b/main/webapp/modules/core/langs/translation-fil.json @@ -475,7 +475,7 @@ "re-trans": "Muling ibahin ang hanggang sa", "warning-no-length": "Hindi tinukoy ang haba ng patlang.", "discard-judg": "Itapon ang mga hatol sa pagkakasundo", - "blank-out": "Mga blankong cell (null)", + "blank-out": "Itakda ang mga cell sa null", "best-cand-type-match": "tumutugma sa mga uri ng pinakamahusay na kandidato?", "sort-by-col": "ayusin ayon sa hanay na ito lamang", "enter-col-name": "Magpasok ng bagong pangalan ng haligi", diff --git a/main/webapp/modules/core/langs/translation-fr.json b/main/webapp/modules/core/langs/translation-fr.json index c9fedfda9..aa2088e61 100644 --- a/main/webapp/modules/core/langs/translation-fr.json +++ b/main/webapp/modules/core/langs/translation-fr.json @@ -476,7 +476,7 @@ "remove-matching": "Supprimer les lignes correspondantes", "warning-no-length": "Aucune longueur de champ n’a été indiquée.", "discard-judg": "Rejeter les avis de réconciliation", - "blank-out": "Vider les cellules (null)", + "blank-out": "Définir les cellules sur null", "best-cand-type-match": "Meilleure correspondance de type des candidats ?", "sort-by-col": "trier selon cette seule colonne", "enter-col-name": "Indiquer le nom de la nouvelle colonne", diff --git a/main/webapp/modules/core/langs/translation-he.json b/main/webapp/modules/core/langs/translation-he.json index a246fa891..4c6674c87 100644 --- a/main/webapp/modules/core/langs/translation-he.json +++ b/main/webapp/modules/core/langs/translation-he.json @@ -578,7 +578,8 @@ "to-number": "To number", "to-date": "To date", "to-text": "To text", - "blank-out": "Blank out cells (null)", + "blank-out": "To null", + "blank-out-empty": "To empty string", "empty-cells": "Set cells to empty string", "fill-down": "Fill down", "blank-down": "Blank down", diff --git a/main/webapp/modules/core/langs/translation-it.json b/main/webapp/modules/core/langs/translation-it.json index e58de6621..66d3dfc65 100644 --- a/main/webapp/modules/core/langs/translation-it.json +++ b/main/webapp/modules/core/langs/translation-it.json @@ -474,7 +474,7 @@ "re-trans": "Ritrasforma fino a", "warning-no-length": "Nessuna lunghezza dei campi specificata.", "discard-judg": "Annulla i match dei candidati", - "blank-out": "Cancella tutte le celle (null)", + "blank-out": "Imposta le celle su null", "best-cand-type-match": "miglior match del tipo del candidato?", "sort-by-col": "ordina per questa colonna", "enter-col-name": "Inserisci il nome della nuova colonna", diff --git a/main/webapp/modules/core/langs/translation-pt_BR.json b/main/webapp/modules/core/langs/translation-pt_BR.json index d80038850..45b87c1a6 100644 --- a/main/webapp/modules/core/langs/translation-pt_BR.json +++ b/main/webapp/modules/core/langs/translation-pt_BR.json @@ -467,7 +467,7 @@ "uppercase": "Para maiúsculo", "best-type": "Best candidate's types", "discard-judg": "Descartar a análise de reconciliação", - "blank-out": "Limpar células (null)", + "blank-out": "Definir células para nulo", "best-cand-type-match": "best candidate's types match?", "sort-by-col": "ordenar somente esta coluna", "enter-col-name": "Digite um nome para a nova coluna", From 731e1310c66f52b627c0900d5f60c5c6b84df4af Mon Sep 17 00:00:00 2001 From: Owen Stephens Date: Mon, 19 Feb 2018 13:42:45 +0000 Subject: [PATCH 6/6] Stripping stuff we don't need out of the tests --- .../tests/expr/ExpressionUtilsTests.java | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/main/tests/server/src/com/google/refine/tests/expr/ExpressionUtilsTests.java b/main/tests/server/src/com/google/refine/tests/expr/ExpressionUtilsTests.java index c51087d3f..9f371cb12 100644 --- a/main/tests/server/src/com/google/refine/tests/expr/ExpressionUtilsTests.java +++ b/main/tests/server/src/com/google/refine/tests/expr/ExpressionUtilsTests.java @@ -33,25 +33,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.tests.expr.functions; -import java.util.Properties; import org.slf4j.LoggerFactory; import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import com.google.refine.browsing.Engine; import com.google.refine.expr.ExpressionUtils; -import com.google.refine.model.Project; import com.google.refine.tests.RefineTest; public class ExpressionUtilsTests extends RefineTest { - Project project; - Properties bindings; @Override @BeforeTest @@ -60,18 +53,6 @@ public class ExpressionUtilsTests extends RefineTest { } - @BeforeMethod - public void SetUp() { - project = new Project(); - bindings = ExpressionUtils.createBindings(project); - } - - @AfterMethod - public void TearDown() { - project = null; - bindings = null; - } - // -----------------tests------------ @Test