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