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