From 5b8be7f1a3cfc795db105f0b4836fe5d5a0606d3 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Tue, 4 Sep 2018 10:26:03 +0100 Subject: [PATCH] Fix ListFacetConfig serialization --- .../refine/browsing/facets/ListFacet.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/main/src/com/google/refine/browsing/facets/ListFacet.java b/main/src/com/google/refine/browsing/facets/ListFacet.java index 40ac933ab..fcf667073 100644 --- a/main/src/com/google/refine/browsing/facets/ListFacet.java +++ b/main/src/com/google/refine/browsing/facets/ListFacet.java @@ -73,7 +73,7 @@ public class ListFacet implements Facet { public boolean omitBlank; public boolean omitError; - public List selection = new LinkedList(); + public List selection = new LinkedList<>(); public boolean selectBlank; public boolean selectError; @@ -81,15 +81,24 @@ public class ListFacet implements Facet { public void write(JSONWriter writer, Properties options) throws JSONException { writer.object(); + writer.key("type"); writer.value("list"); writer.key("name"); writer.value(name); writer.key("expression"); writer.value(expression); writer.key("columnName"); writer.value(columnName); writer.key("invert"); writer.value(invert); writer.key("selection"); writer.array(); - for (NominalFacetChoice choice : selection) { + for (DecoratedValue choice : selection) { + writer.object(); + writer.key("v"); choice.write(writer, options); + writer.endObject(); } writer.endArray(); + writer.key("omitBlank"); writer.value(omitBlank); + writer.key("selectBlank"); writer.value(selectBlank); + writer.key("omitError"); writer.value(omitError); + writer.key("selectError"); writer.value(selectError); + writer.endObject(); } public void initializeFromJSON(JSONObject o) { @@ -108,10 +117,7 @@ public class ListFacet implements Facet { DecoratedValue decoratedValue = new DecoratedValue( ocv.get("v"), ocv.getString("l")); - NominalFacetChoice nominalFacetChoice = new NominalFacetChoice(decoratedValue); - nominalFacetChoice.selected = true; - - selection.add(nominalFacetChoice); + selection.add(decoratedValue); } omitBlank = JSONUtilities.getBoolean(o, "omitBlank", false); @@ -287,8 +293,8 @@ public class ListFacet implements Facet { _choices.clear(); _choices.addAll(grouper.choices.values()); - for (NominalFacetChoice choice : _config.selection) { - String valueString = choice.decoratedValue.value.toString(); + for (DecoratedValue decoratedValue : _config.selection) { + String valueString = decoratedValue.value.toString(); if (grouper.choices.containsKey(valueString)) { grouper.choices.get(valueString).selected = true; @@ -303,6 +309,7 @@ public class ListFacet implements Facet { * won't be able to detect the "bicycle" choice, so we need to inject * that choice into the choice list ourselves. */ + NominalFacetChoice choice = new NominalFacetChoice(decoratedValue); choice.count = 0; _choices.add(choice); } @@ -315,7 +322,7 @@ public class ListFacet implements Facet { protected Object[] createMatches() { Object[] a = new Object[_config.selection.size()]; for (int i = 0; i < a.length; i++) { - a[i] = _config.selection.get(i).decoratedValue.value; + a[i] = _config.selection.get(i).value; } return a; }