Jackson deserialization for TimeRangeFacetConfig
This commit is contained in:
parent
e11145ce0d
commit
c4caf1eba7
@ -73,9 +73,9 @@ public class TimeRangeFacet implements Facet {
|
||||
protected String _columnName; // column to base expression on, if any
|
||||
|
||||
@JsonProperty(FROM)
|
||||
protected double _from; // the numeric selection
|
||||
protected double _from = 0; // the numeric selection
|
||||
@JsonProperty(TO)
|
||||
protected double _to;
|
||||
protected double _to = 0;
|
||||
|
||||
@JsonProperty("selectTime")
|
||||
protected boolean _selectTime; // whether the time selection applies, default true
|
||||
@ -86,31 +86,12 @@ public class TimeRangeFacet implements Facet {
|
||||
@JsonProperty("selectError")
|
||||
protected boolean _selectError;
|
||||
|
||||
@JsonIgnore
|
||||
protected boolean _selected; // false if we're certain that all rows will match
|
||||
// false if we're certain that all rows will match
|
||||
// and there isn't any filtering to do
|
||||
|
||||
@Override
|
||||
public void initializeFromJSON(JSONObject o) throws JSONException {
|
||||
_name = o.getString("name");
|
||||
_expression = o.getString("expression");
|
||||
_columnName = o.getString("columnName");
|
||||
|
||||
if (o.has(FROM) || o.has(TO)) {
|
||||
_from = o.has(FROM) ? o.getDouble(FROM) : 0;
|
||||
_to = o.has(TO) ? o.getDouble(TO) : 0;
|
||||
_selected = true;
|
||||
}
|
||||
|
||||
_selectTime = JSONUtilities.getBoolean(o, "selectTime", true);
|
||||
_selectNonTime = JSONUtilities.getBoolean(o, "selectNonTime", true);
|
||||
_selectBlank = JSONUtilities.getBoolean(o, "selectBlank", true);
|
||||
_selectError = JSONUtilities.getBoolean(o, "selectError", true);
|
||||
|
||||
if (!_selectTime || !_selectNonTime || !_selectBlank || !_selectError) {
|
||||
_selected = true;
|
||||
}
|
||||
}
|
||||
@JsonIgnore
|
||||
protected boolean isSelected() {
|
||||
return _from != 0 || _to != 0 || !_selectTime || !_selectNonTime || !_selectBlank || !_selectError;
|
||||
};
|
||||
|
||||
@Override
|
||||
public TimeRangeFacet apply(Project project) {
|
||||
@ -268,7 +249,7 @@ public class TimeRangeFacet implements Facet {
|
||||
|
||||
@Override
|
||||
public RowFilter getRowFilter(Project project) {
|
||||
if (_eval != null && _errorMessage == null && _config._selected) {
|
||||
if (_eval != null && _errorMessage == null && _config.isSelected()) {
|
||||
return new ExpressionTimeComparisonRowFilter(
|
||||
getRowEvaluable(project), _config._selectTime, _config._selectNonTime, _config._selectBlank, _config._selectError) {
|
||||
|
||||
@ -338,7 +319,7 @@ public class TimeRangeFacet implements Facet {
|
||||
_baseBlankCount = index.getBlankRowCount();
|
||||
_baseErrorCount = index.getErrorRowCount();
|
||||
|
||||
if (_config._selected) {
|
||||
if (_config.isSelected()) {
|
||||
_config._from = Math.max(_config._from, _min);
|
||||
_config._to = Math.min(_config._to, _max);
|
||||
} else {
|
||||
|
@ -1,10 +1,13 @@
|
||||
package com.google.refine.tests.browsing.facets;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
|
||||
import com.google.refine.browsing.Engine;
|
||||
import com.google.refine.browsing.facets.TimeRangeFacet;
|
||||
import com.google.refine.browsing.facets.TimeRangeFacet.TimeRangeFacetConfig;
|
||||
@ -12,6 +15,7 @@ import com.google.refine.model.Cell;
|
||||
import com.google.refine.model.Project;
|
||||
import com.google.refine.tests.RefineTest;
|
||||
import com.google.refine.tests.util.TestUtils;
|
||||
import com.google.refine.util.ParsingUtilities;
|
||||
|
||||
|
||||
public class TimeRangeFacetTests extends RefineTest {
|
||||
@ -50,14 +54,13 @@ public class TimeRangeFacetTests extends RefineTest {
|
||||
" }";
|
||||
|
||||
@Test
|
||||
public void serializeTimeRangeFacetConfig() {
|
||||
TimeRangeFacetConfig config = new TimeRangeFacetConfig();
|
||||
config.initializeFromJSON(new JSONObject(configJson));
|
||||
public void serializeTimeRangeFacetConfig() throws JsonParseException, JsonMappingException, IOException {
|
||||
TimeRangeFacetConfig config = ParsingUtilities.mapper.readValue(configJson, TimeRangeFacetConfig.class);
|
||||
TestUtils.isSerializedTo(config, configJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializeTimeRangeFacet() {
|
||||
public void serializeTimeRangeFacet() throws JsonParseException, JsonMappingException, IOException {
|
||||
Project project = createCSVProject("my column\n"
|
||||
+ "placeholder\n"
|
||||
+ "nontime\n"
|
||||
@ -68,8 +71,7 @@ public class TimeRangeFacetTests extends RefineTest {
|
||||
project.rows.get(3).cells.set(0, new Cell(OffsetDateTime.parse("2012-04-05T02:00:01Z"), null));
|
||||
|
||||
Engine engine = new Engine(project);
|
||||
TimeRangeFacetConfig config = new TimeRangeFacetConfig();
|
||||
config.initializeFromJSON(new JSONObject(configJson));
|
||||
TimeRangeFacetConfig config = ParsingUtilities.mapper.readValue(configJson, TimeRangeFacetConfig.class);
|
||||
TimeRangeFacet facet = config.apply(project);
|
||||
facet.computeChoices(project, engine.getAllFilteredRows());
|
||||
TestUtils.isSerializedTo(facet, facetJson);
|
||||
|
Loading…
Reference in New Issue
Block a user