Migrate Engine to Jackson
This commit is contained in:
parent
f02b3edd0b
commit
86d1159926
@ -38,9 +38,6 @@ import java.util.LinkedList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.google.refine.browsing.facets.Facet;
|
import com.google.refine.browsing.facets.Facet;
|
||||||
@ -177,12 +174,6 @@ public class Engine {
|
|||||||
}
|
}
|
||||||
throw new InternalError("This method should not be called when the engine is not in record mode.");
|
throw new InternalError("This method should not be called when the engine is not in record mode.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void initializeFromJSON(JSONObject o) throws JSONException {
|
|
||||||
EngineConfig config = EngineConfig.reconstruct(o);
|
|
||||||
initializeFromConfig(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initializeFromConfig(EngineConfig config) {
|
public void initializeFromConfig(EngineConfig config) {
|
||||||
_config = config;
|
_config = config;
|
||||||
@ -191,7 +182,7 @@ public class Engine {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void computeFacets() throws JSONException {
|
public void computeFacets() {
|
||||||
if (_config.getMode().equals(Mode.RowBased)) {
|
if (_config.getMode().equals(Mode.RowBased)) {
|
||||||
for (Facet facet : _facets) {
|
for (Facet facet : _facets) {
|
||||||
FilteredRows filteredRows = getFilteredRows(facet);
|
FilteredRows filteredRows = getFilteredRows(facet);
|
||||||
|
@ -4,8 +4,6 @@ import java.io.IOException;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.google.refine.browsing.Engine.Mode;
|
import com.google.refine.browsing.Engine.Mode;
|
||||||
@ -38,12 +36,12 @@ public class EngineConfig {
|
|||||||
return _facets;
|
return _facets;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EngineConfig reconstruct(JSONObject o) {
|
public static EngineConfig reconstruct(String json) {
|
||||||
if(o == null) {
|
if(json == null) {
|
||||||
return new EngineConfig(Collections.emptyList(), Mode.RowBased);
|
return new EngineConfig(Collections.emptyList(), Mode.RowBased);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return ParsingUtilities.mapper.readValue(o.toString(), EngineConfig.class);
|
return ParsingUtilities.mapper.readValue(json, EngineConfig.class);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
|
@ -125,7 +125,7 @@ public abstract class Command {
|
|||||||
String json = request.getParameter("engine");
|
String json = request.getParameter("engine");
|
||||||
try{
|
try{
|
||||||
return (json == null) ? null :
|
return (json == null) ? null :
|
||||||
EngineConfig.reconstruct(ParsingUtilities.evaluateJsonStringToObject(json));
|
EngineConfig.reconstruct(json);
|
||||||
} catch (JSONException e){
|
} catch (JSONException e){
|
||||||
logger.debug( json + " could not be parsed to JSON");
|
logger.debug( json + " could not be parsed to JSON");
|
||||||
return null;
|
return null;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.google.refine.tests.browsing.facets;
|
package com.google.refine.tests.browsing.facets;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
@ -36,13 +35,13 @@ public class EngineConfigTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void serializeEngineConfig() {
|
public void serializeEngineConfig() {
|
||||||
EngineConfig ec = EngineConfig.reconstruct(new JSONObject(engineConfigJson));
|
EngineConfig ec = EngineConfig.reconstruct(engineConfigJson);
|
||||||
TestUtils.isSerializedTo(ec, engineConfigJson);
|
TestUtils.isSerializedTo(ec, engineConfigJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void serializeEngineConfigRecordMode() {
|
public void serializeEngineConfigRecordMode() {
|
||||||
EngineConfig ec = EngineConfig.reconstruct(new JSONObject(engineConfigRecordModeJson));
|
EngineConfig ec = EngineConfig.reconstruct(engineConfigRecordModeJson);
|
||||||
TestUtils.isSerializedTo(ec, engineConfigRecordModeJson);
|
TestUtils.isSerializedTo(ec, engineConfigRecordModeJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +54,7 @@ public class EngineConfigTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void reconstructNoFacetsProvided() {
|
public void reconstructNoFacetsProvided() {
|
||||||
EngineConfig ec = EngineConfig.reconstruct(new JSONObject(noFacetProvided));
|
EngineConfig ec = EngineConfig.reconstruct(noFacetProvided);
|
||||||
Assert.assertEquals(ec.getMode(), Mode.RowBased);
|
Assert.assertEquals(ec.getMode(), Mode.RowBased);
|
||||||
Assert.assertTrue(ec.getFacetConfigs().isEmpty());
|
Assert.assertTrue(ec.getFacetConfigs().isEmpty());
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ public class CacheTests extends RefineTest {
|
|||||||
project = createProjectWithColumns("CacheTests", "Column A");
|
project = createProjectWithColumns("CacheTests", "Column A");
|
||||||
|
|
||||||
engine = new Engine(project);
|
engine = new Engine(project);
|
||||||
engine_config = EngineConfig.reconstruct(new JSONObject(ENGINE_JSON_DUPLICATES));
|
engine_config = EngineConfig.reconstruct(ENGINE_JSON_DUPLICATES);
|
||||||
engine.initializeFromConfig(engine_config);
|
engine.initializeFromConfig(engine_config);
|
||||||
engine.setMode(Engine.Mode.RowBased);
|
engine.setMode(Engine.Mode.RowBased);
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ public class BlankDownTests extends RefineTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testBlankDownRecords() throws Exception {
|
public void testBlankDownRecords() throws Exception {
|
||||||
AbstractOperation op = new BlankDownOperation(
|
AbstractOperation op = new BlankDownOperation(
|
||||||
EngineConfig.reconstruct(new JSONObject("{\"mode\":\"record-based\",\"facets\":[]}")),
|
EngineConfig.reconstruct("{\"mode\":\"record-based\",\"facets\":[]}"),
|
||||||
"second");
|
"second");
|
||||||
Process process = op.createProcess(project, new Properties());
|
Process process = op.createProcess(project, new Properties());
|
||||||
process.performImmediate();
|
process.performImmediate();
|
||||||
@ -77,7 +77,7 @@ public class BlankDownTests extends RefineTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testBlankDownRows() throws Exception {
|
public void testBlankDownRows() throws Exception {
|
||||||
AbstractOperation op = new BlankDownOperation(
|
AbstractOperation op = new BlankDownOperation(
|
||||||
EngineConfig.reconstruct(new JSONObject("{\"mode\":\"row-based\",\"facets\":[]}")),
|
EngineConfig.reconstruct("{\"mode\":\"row-based\",\"facets\":[]}"),
|
||||||
"second");
|
"second");
|
||||||
Process process = op.createProcess(project, new Properties());
|
Process process = op.createProcess(project, new Properties());
|
||||||
process.performImmediate();
|
process.performImmediate();
|
||||||
|
@ -5,7 +5,6 @@ import java.util.List;
|
|||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.AfterMethod;
|
import org.testng.annotations.AfterMethod;
|
||||||
import org.testng.annotations.BeforeMethod;
|
import org.testng.annotations.BeforeMethod;
|
||||||
@ -61,7 +60,7 @@ public class FillDownTests extends RefineTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testFillDownRecordKey() throws Exception {
|
public void testFillDownRecordKey() throws Exception {
|
||||||
AbstractOperation op = new FillDownOperation(
|
AbstractOperation op = new FillDownOperation(
|
||||||
EngineConfig.reconstruct(new JSONObject("{\"mode\":\"record-based\",\"facets\":[]}")),
|
EngineConfig.reconstruct("{\"mode\":\"record-based\",\"facets\":[]}"),
|
||||||
"key");
|
"key");
|
||||||
Process process = op.createProcess(project, new Properties());
|
Process process = op.createProcess(project, new Properties());
|
||||||
process.performImmediate();
|
process.performImmediate();
|
||||||
@ -77,7 +76,7 @@ public class FillDownTests extends RefineTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testFillDownRecords() throws Exception {
|
public void testFillDownRecords() throws Exception {
|
||||||
AbstractOperation op = new FillDownOperation(
|
AbstractOperation op = new FillDownOperation(
|
||||||
EngineConfig.reconstruct(new JSONObject("{\"mode\":\"record-based\",\"facets\":[]}")),
|
EngineConfig.reconstruct("{\"mode\":\"record-based\",\"facets\":[]}"),
|
||||||
"second");
|
"second");
|
||||||
Process process = op.createProcess(project, new Properties());
|
Process process = op.createProcess(project, new Properties());
|
||||||
process.performImmediate();
|
process.performImmediate();
|
||||||
@ -93,7 +92,7 @@ public class FillDownTests extends RefineTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testFillDownRows() throws Exception {
|
public void testFillDownRows() throws Exception {
|
||||||
AbstractOperation op = new FillDownOperation(
|
AbstractOperation op = new FillDownOperation(
|
||||||
EngineConfig.reconstruct(new JSONObject("{\"mode\":\"row-based\",\"facets\":[]}")),
|
EngineConfig.reconstruct("{\"mode\":\"row-based\",\"facets\":[]}"),
|
||||||
"second");
|
"second");
|
||||||
Process process = op.createProcess(project, new Properties());
|
Process process = op.createProcess(project, new Properties());
|
||||||
process.performImmediate();
|
process.performImmediate();
|
||||||
|
@ -105,7 +105,7 @@ public class ColumnAdditionByFetchingURLsOperationTests extends RefineTest {
|
|||||||
// dependencies
|
// dependencies
|
||||||
private Project project;
|
private Project project;
|
||||||
private Properties options;
|
private Properties options;
|
||||||
private EngineConfig engine_config = EngineConfig.reconstruct(new JSONObject(ENGINE_JSON_URLS));
|
private EngineConfig engine_config = EngineConfig.reconstruct(ENGINE_JSON_URLS);
|
||||||
|
|
||||||
@BeforeMethod
|
@BeforeMethod
|
||||||
public void SetUp() throws JSONException, IOException, ModelException {
|
public void SetUp() throws JSONException, IOException, ModelException {
|
||||||
|
@ -146,7 +146,7 @@ public class ExtendDataOperationTests extends RefineTest {
|
|||||||
|
|
||||||
options = mock(Properties.class);
|
options = mock(Properties.class);
|
||||||
engine = new Engine(project);
|
engine = new Engine(project);
|
||||||
engine_config = EngineConfig.reconstruct(new JSONObject(ENGINE_JSON_URLS));
|
engine_config = EngineConfig.reconstruct(ENGINE_JSON_URLS);
|
||||||
engine.initializeFromConfig(engine_config);
|
engine.initializeFromConfig(engine_config);
|
||||||
engine.setMode(Engine.Mode.RowBased);
|
engine.setMode(Engine.Mode.RowBased);
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ import java.io.IOException;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
@ -29,7 +28,7 @@ import com.google.refine.util.ParsingUtilities;
|
|||||||
|
|
||||||
public class ReconJudgeSimilarCellsTests extends RefineTest {
|
public class ReconJudgeSimilarCellsTests extends RefineTest {
|
||||||
|
|
||||||
static final EngineConfig ENGINE_CONFIG = EngineConfig.reconstruct(new JSONObject("{\"mode\":\"row-based\"}}"));
|
static final EngineConfig ENGINE_CONFIG = EngineConfig.reconstruct("{\"mode\":\"row-based\"}}");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@BeforeTest
|
@BeforeTest
|
||||||
|
Loading…
Reference in New Issue
Block a user