Store engine configuration as EngineConfig rather than JSONObject

This commit is contained in:
Antonin Delpeuch 2018-09-05 14:49:39 +01:00
parent f6256aae62
commit fbc9b27640
61 changed files with 214 additions and 189 deletions

View File

@ -25,9 +25,9 @@ package org.openrefine.wikidata.commands;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject;
import org.openrefine.wikidata.operations.PerformWikibaseEditsOperation;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.commands.EngineDependentCommand;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
@ -35,7 +35,7 @@ import com.google.refine.model.Project;
public class PerformWikibaseEditsCommand extends EngineDependentCommand {
@Override
protected AbstractOperation createOperation(Project project, HttpServletRequest request, JSONObject engineConfig)
protected AbstractOperation createOperation(Project project, HttpServletRequest request, EngineConfig engineConfig)
throws Exception {
String summary = request.getParameter("summary");
return new PerformWikibaseEditsOperation(engineConfig, summary);

View File

@ -49,6 +49,7 @@ import org.wikidata.wdtk.wikibaseapi.WikibaseDataFetcher;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.refine.browsing.Engine;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.history.Change;
import com.google.refine.history.HistoryEntry;
import com.google.refine.model.AbstractOperation;
@ -65,7 +66,7 @@ public class PerformWikibaseEditsOperation extends EngineDependentOperation {
private String summary;
public PerformWikibaseEditsOperation(JSONObject engineConfig, String summary) {
public PerformWikibaseEditsOperation(EngineConfig engineConfig, String summary) {
super(engineConfig);
Validate.notNull(summary, "An edit summary must be provided.");
Validate.notEmpty(summary, "An edit summary must be provided.");
@ -79,7 +80,8 @@ public class PerformWikibaseEditsOperation extends EngineDependentOperation {
if (obj.has("summary")) {
summary = obj.getString("summary");
}
return new PerformWikibaseEditsOperation(engineConfig, summary);
return new PerformWikibaseEditsOperation(
EngineConfig.reconstruct(engineConfig), summary);
}
@Override
@ -93,7 +95,7 @@ public class PerformWikibaseEditsOperation extends EngineDependentOperation {
writer.key("summary");
writer.value(summary);
writer.key("engineConfig");
writer.value(getEngineConfig());
getEngineConfig().write(writer, options);
writer.endObject();
}

View File

@ -32,6 +32,7 @@ import org.openrefine.wikidata.testing.TestingData;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.history.Change;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Recon;
@ -58,7 +59,7 @@ public class PerformWikibaseEditsOperationTest extends OperationTest {
@Test(expectedExceptions=IllegalArgumentException.class)
public void testConstructor() {
new PerformWikibaseEditsOperation(new JSONObject("{}"), "");
new PerformWikibaseEditsOperation(EngineConfig.reconstruct(new JSONObject("{}")), "");
}
@Test

View File

@ -55,6 +55,7 @@ import org.wikidata.wdtk.datamodel.interfaces.TimeValue;
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
import com.google.refine.browsing.Engine;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.model.Project;
import com.google.refine.tests.RefineTest;
import com.google.refine.util.ParsingUtilities;
@ -149,12 +150,21 @@ public class WikibaseSchemaTest extends RefineTest {
JSONObject serialized = TestingData.jsonFromFile("data/schema/inception.json");
WikibaseSchema schema = WikibaseSchema.reconstruct(serialized);
Engine engine = new Engine(project);
JSONObject engineConfig = new JSONObject("{\n" + " \"mode\": \"row-based\",\n" + " \"facets\": [\n"
+ " {\n" + " \"mode\": \"text\",\n" + " \"invert\": false,\n"
+ " \"caseSensitive\": false,\n" + " \"query\": \"www\",\n"
+ " \"name\": \"reference\",\n" + " \"type\": \"text\",\n"
+ " \"columnName\": \"reference\"\n" + " }\n" + " ]\n" + " }");
engine.initializeFromJSON(engineConfig);
EngineConfig engineConfig = EngineConfig.reconstruct(new JSONObject("{\n"
+ " \"mode\": \"row-based\",\n"
+ " \"facets\": [\n"
+ " {\n"
+ " \"mode\": \"text\",\n"
+ " \"invert\": false,\n"
+ " \"caseSensitive\": false,\n"
+ " \"query\": \"www\",\n"
+ " \"name\": \"reference\",\n"
+ " \"type\": \"text\",\n"
+ " \"columnName\": \"reference\"\n"
+ " }\n"
+ " ]\n"
+ " }"));
engine.initializeFromConfig(engineConfig);
List<ItemUpdate> updates = schema.evaluate(project, engine);
List<ItemUpdate> expected = new ArrayList<>();
ItemUpdate update1 = new ItemUpdateBuilder(qid1).addStatement(statement1).build();

View File

@ -168,6 +168,7 @@ public class Engine implements Jsonizable {
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);

View File

@ -12,6 +12,7 @@ import org.json.JSONWriter;
import com.google.refine.Jsonizable;
import com.google.refine.browsing.Engine.Mode;
import com.google.refine.browsing.facets.Facet;
import com.google.refine.browsing.facets.FacetConfig;
import com.google.refine.browsing.facets.ListFacet.ListFacetConfig;
import com.google.refine.browsing.facets.RangeFacet.RangeFacetConfig;

View File

@ -54,6 +54,7 @@ import com.google.refine.Jsonizable;
import com.google.refine.ProjectManager;
import com.google.refine.RefineServlet;
import com.google.refine.browsing.Engine;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.history.HistoryEntry;
import com.google.refine.model.Project;
import com.google.refine.model.metadata.ProjectMetadata;
@ -115,7 +116,7 @@ public abstract class Command {
* @return
* @throws JSONException
*/
static protected JSONObject getEngineConfig(HttpServletRequest request)
static protected EngineConfig getEngineConfig(HttpServletRequest request)
throws JSONException {
if (request == null) {
throw new IllegalArgumentException("parameter 'request' should not be null");
@ -123,7 +124,8 @@ public abstract class Command {
String json = request.getParameter("engine");
try{
return (json == null) ? null : ParsingUtilities.evaluateJsonStringToObject(json);
return (json == null) ? null :
EngineConfig.reconstruct(ParsingUtilities.evaluateJsonStringToObject(json));
} catch (JSONException e){
logger.debug( json + " could not be parsed to JSON");
return null;
@ -149,9 +151,9 @@ public abstract class Command {
}
Engine engine = new Engine(project);
JSONObject o = getEngineConfig(request);
if (o != null) {
engine.initializeFromJSON(o);
EngineConfig c = getEngineConfig(request);
if (c != null) {
engine.initializeFromConfig(c);
}
return engine;
}

View File

@ -40,8 +40,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.JSONObject;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
import com.google.refine.process.Process;
@ -85,5 +84,5 @@ abstract public class EngineDependentCommand extends Command {
}
abstract protected AbstractOperation createOperation(
Project project, HttpServletRequest request, JSONObject engineConfig) throws Exception;
Project project, HttpServletRequest request, EngineConfig engineConfig) throws Exception;
}

View File

@ -35,8 +35,7 @@ package com.google.refine.commands.cell;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.commands.EngineDependentCommand;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
@ -45,7 +44,7 @@ import com.google.refine.operations.cell.BlankDownOperation;
public class BlankDownCommand extends EngineDependentCommand {
@Override
protected AbstractOperation createOperation(Project project,
HttpServletRequest request, JSONObject engineConfig) throws Exception {
HttpServletRequest request, EngineConfig engineConfig) throws Exception {
String columnName = request.getParameter("columnName");

View File

@ -35,8 +35,7 @@ package com.google.refine.commands.cell;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.commands.EngineDependentCommand;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
@ -45,7 +44,7 @@ import com.google.refine.operations.cell.FillDownOperation;
public class FillDownCommand extends EngineDependentCommand {
@Override
protected AbstractOperation createOperation(Project project,
HttpServletRequest request, JSONObject engineConfig) throws Exception {
HttpServletRequest request, EngineConfig engineConfig) throws Exception {
String columnName = request.getParameter("columnName");

View File

@ -35,8 +35,7 @@ package com.google.refine.commands.cell;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.commands.EngineDependentCommand;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
@ -46,7 +45,7 @@ import com.google.refine.util.ParsingUtilities;
public class MassEditCommand extends EngineDependentCommand {
@Override
protected AbstractOperation createOperation(Project project,
HttpServletRequest request, JSONObject engineConfig) throws Exception {
HttpServletRequest request, EngineConfig engineConfig) throws Exception {
String columnName = request.getParameter("columnName");
String expression = request.getParameter("expression");

View File

@ -35,8 +35,7 @@ package com.google.refine.commands.cell;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.commands.EngineDependentCommand;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
@ -45,7 +44,7 @@ import com.google.refine.operations.cell.TextTransformOperation;
public class TextTransformCommand extends EngineDependentCommand {
@Override
protected AbstractOperation createOperation(Project project,
HttpServletRequest request, JSONObject engineConfig) throws Exception {
HttpServletRequest request, EngineConfig engineConfig) throws Exception {
String columnName = request.getParameter("columnName");
String expression = request.getParameter("expression");

View File

@ -35,9 +35,9 @@ package com.google.refine.commands.column;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject;
import org.json.JSONArray;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.commands.EngineDependentCommand;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
@ -47,7 +47,7 @@ import com.google.refine.operations.column.ColumnAdditionByFetchingURLsOperation
public class AddColumnByFetchingURLsCommand extends EngineDependentCommand {
@Override
protected AbstractOperation createOperation(Project project,
HttpServletRequest request, JSONObject engineConfig) throws Exception {
HttpServletRequest request, EngineConfig engineConfig) throws Exception {
String baseColumnName = request.getParameter("baseColumnName");
String urlExpression = request.getParameter("urlExpression");

View File

@ -35,8 +35,7 @@ package com.google.refine.commands.column;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.commands.EngineDependentCommand;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
@ -46,7 +45,7 @@ import com.google.refine.operations.column.ColumnAdditionOperation;
public class AddColumnCommand extends EngineDependentCommand {
@Override
protected AbstractOperation createOperation(Project project,
HttpServletRequest request, JSONObject engineConfig) throws Exception {
HttpServletRequest request, EngineConfig engineConfig) throws Exception {
String baseColumnName = request.getParameter("baseColumnName");
String expression = request.getParameter("expression");

View File

@ -35,8 +35,7 @@ package com.google.refine.commands.column;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.commands.EngineDependentCommand;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
@ -48,7 +47,7 @@ public class ReorderColumnsCommand extends EngineDependentCommand {
@Override
protected AbstractOperation createOperation(Project project,
HttpServletRequest request, JSONObject engineConfig) throws Exception {
HttpServletRequest request, EngineConfig engineConfig) throws Exception {
String columnNames = request.getParameter("columnNames");
return new ColumnReorderOperation(

View File

@ -36,8 +36,8 @@ package com.google.refine.commands.column;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONArray;
import org.json.JSONObject;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.commands.EngineDependentCommand;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
@ -47,7 +47,7 @@ import com.google.refine.util.ParsingUtilities;
public class SplitColumnCommand extends EngineDependentCommand {
@Override
protected AbstractOperation createOperation(Project project,
HttpServletRequest request, JSONObject engineConfig) throws Exception {
HttpServletRequest request, EngineConfig engineConfig) throws Exception {
String columnName = request.getParameter("columnName");
boolean guessCellType = Boolean.parseBoolean(request.getParameter("guessCellType"));

View File

@ -37,6 +37,7 @@ import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.commands.EngineDependentCommand;
import com.google.refine.operations.recon.ExtendDataOperation;
import com.google.refine.model.AbstractOperation;
@ -46,7 +47,7 @@ import com.google.refine.util.ParsingUtilities;
public class ExtendDataCommand extends EngineDependentCommand {
@Override
protected AbstractOperation createOperation(Project project,
HttpServletRequest request, JSONObject engineConfig) throws Exception {
HttpServletRequest request, EngineConfig engineConfig) throws Exception {
String baseColumnName = request.getParameter("baseColumnName");
int columnInsertIndex = Integer.parseInt(request.getParameter("columnInsertIndex"));

View File

@ -35,8 +35,7 @@ package com.google.refine.commands.recon;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.commands.EngineDependentCommand;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
@ -46,7 +45,7 @@ public class ReconClearSimilarCellsCommand extends EngineDependentCommand {
@Override
protected AbstractOperation createOperation(
Project project, HttpServletRequest request, JSONObject engineConfig) throws Exception {
Project project, HttpServletRequest request, EngineConfig engineConfig) throws Exception {
String columnName = request.getParameter("columnName");
String similarValue = request.getParameter("similarValue");

View File

@ -35,8 +35,7 @@ package com.google.refine.commands.recon;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.commands.EngineDependentCommand;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
@ -45,7 +44,7 @@ import com.google.refine.operations.recon.ReconCopyAcrossColumnsOperation;
public class ReconCopyAcrossColumnsCommand extends EngineDependentCommand {
@Override
protected AbstractOperation createOperation(Project project,
HttpServletRequest request, JSONObject engineConfig) throws Exception {
HttpServletRequest request, EngineConfig engineConfig) throws Exception {
String fromColumnName = request.getParameter("fromColumnName");
String[] toColumnNames = request.getParameterValues("toColumnName[]");

View File

@ -35,8 +35,7 @@ package com.google.refine.commands.recon;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.commands.EngineDependentCommand;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
@ -45,7 +44,7 @@ import com.google.refine.operations.recon.ReconDiscardJudgmentsOperation;
public class ReconDiscardJudgmentsCommand extends EngineDependentCommand {
@Override
protected AbstractOperation createOperation(Project project,
HttpServletRequest request, JSONObject engineConfig) throws Exception {
HttpServletRequest request, EngineConfig engineConfig) throws Exception {
String columnName = request.getParameter("columnName");
boolean clearData = Boolean.parseBoolean(request.getParameter("clearData"));

View File

@ -35,8 +35,7 @@ package com.google.refine.commands.recon;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.commands.EngineDependentCommand;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
@ -49,7 +48,7 @@ public class ReconJudgeSimilarCellsCommand extends EngineDependentCommand {
@Override
protected AbstractOperation createOperation(
Project project, HttpServletRequest request, JSONObject engineConfig) throws Exception {
Project project, HttpServletRequest request, EngineConfig engineConfig) throws Exception {
String columnName = request.getParameter("columnName");
String similarValue = request.getParameter("similarValue");

View File

@ -35,8 +35,7 @@ package com.google.refine.commands.recon;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.commands.EngineDependentCommand;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
@ -46,7 +45,7 @@ public class ReconMarkNewTopicsCommand extends EngineDependentCommand {
@Override
protected AbstractOperation createOperation(Project project,
HttpServletRequest request, JSONObject engineConfig) throws Exception {
HttpServletRequest request, EngineConfig engineConfig) throws Exception {
return new ReconMarkNewTopicsOperation(
engineConfig,

View File

@ -35,8 +35,7 @@ package com.google.refine.commands.recon;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.commands.EngineDependentCommand;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
@ -46,7 +45,7 @@ public class ReconMatchBestCandidatesCommand extends EngineDependentCommand {
@Override
protected AbstractOperation createOperation(Project project,
HttpServletRequest request, JSONObject engineConfig) throws Exception {
HttpServletRequest request, EngineConfig engineConfig) throws Exception {
String columnName = request.getParameter("columnName");

View File

@ -35,8 +35,7 @@ package com.google.refine.commands.recon;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.commands.EngineDependentCommand;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
@ -47,7 +46,7 @@ public class ReconMatchSpecificTopicCommand extends EngineDependentCommand {
@Override
protected AbstractOperation createOperation(Project project,
HttpServletRequest request, JSONObject engineConfig) throws Exception {
HttpServletRequest request, EngineConfig engineConfig) throws Exception {
String columnName = request.getParameter("columnName");
ReconCandidate match = new ReconCandidate(

View File

@ -38,6 +38,7 @@ import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject;
import org.json.JSONTokener;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.commands.EngineDependentCommand;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
@ -48,7 +49,7 @@ public class ReconcileCommand extends EngineDependentCommand {
@Override
protected AbstractOperation createOperation(Project project,
HttpServletRequest request, JSONObject engineConfig) throws Exception {
HttpServletRequest request, EngineConfig engineConfig) throws Exception {
String columnName = request.getParameter("columnName");
String configString = request.getParameter("config");

View File

@ -35,8 +35,7 @@ package com.google.refine.commands.row;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.commands.EngineDependentCommand;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
@ -47,7 +46,7 @@ public class AnnotateRowsCommand extends EngineDependentCommand {
@Override
protected AbstractOperation createOperation(Project project,
HttpServletRequest request, JSONObject engineConfig) throws Exception {
HttpServletRequest request, EngineConfig engineConfig) throws Exception {
String starredString = request.getParameter("starred");
if (starredString != null) {

View File

@ -35,8 +35,7 @@ package com.google.refine.commands.row;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONObject;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.commands.EngineDependentCommand;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
@ -46,7 +45,7 @@ public class RemoveRowsCommand extends EngineDependentCommand {
@Override
protected AbstractOperation createOperation(Project project,
HttpServletRequest request, JSONObject engineConfig) throws Exception {
HttpServletRequest request, EngineConfig engineConfig) throws Exception {
return new RowRemovalOperation(engineConfig);
}

View File

@ -39,6 +39,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import com.google.refine.browsing.Engine;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.commands.EngineDependentCommand;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
@ -49,7 +50,7 @@ public class ReorderRowsCommand extends EngineDependentCommand {
@Override
protected AbstractOperation createOperation(Project project,
HttpServletRequest request, JSONObject engineConfig) throws Exception {
HttpServletRequest request, EngineConfig engineConfig) throws Exception {
String mode = request.getParameter("mode");
JSONObject sorting = null;

View File

@ -36,9 +36,8 @@ package com.google.refine.operations;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONObject;
import com.google.refine.browsing.Engine;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.browsing.FilteredRows;
import com.google.refine.browsing.RowVisitor;
import com.google.refine.history.Change;
@ -53,7 +52,7 @@ abstract public class EngineDependentMassCellOperation extends EngineDependentOp
final protected boolean _updateRowContextDependencies;
protected EngineDependentMassCellOperation(
JSONObject engineConfig, String columnName, boolean updateRowContextDependencies) {
EngineConfig engineConfig, String columnName, boolean updateRowContextDependencies) {
super(engineConfig);
_columnName = columnName;
_updateRowContextDependencies = updateRowContextDependencies;

View File

@ -34,9 +34,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.refine.operations;
import org.json.JSONException;
import org.json.JSONObject;
import com.google.refine.browsing.Engine;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
import com.google.refine.util.ParsingUtilities;
@ -44,24 +44,25 @@ import com.google.refine.util.ParsingUtilities;
abstract public class EngineDependentOperation extends AbstractOperation {
final private String _engineConfigString;
transient protected JSONObject _engineConfig;
transient protected EngineConfig _engineConfig;
protected EngineDependentOperation(JSONObject engineConfig) {
protected EngineDependentOperation(EngineConfig engineConfig) {
_engineConfig = engineConfig;
_engineConfigString = engineConfig == null || engineConfig.length() == 0
_engineConfigString = engineConfig == null
? null : engineConfig.toString();
}
protected Engine createEngine(Project project) throws Exception {
Engine engine = new Engine(project);
engine.initializeFromJSON(getEngineConfig());
engine.initializeFromConfig(getEngineConfig());
return engine;
}
protected JSONObject getEngineConfig() {
protected EngineConfig getEngineConfig() {
if (_engineConfig == null && _engineConfigString != null) {
try {
_engineConfig = ParsingUtilities.evaluateJsonStringToObject(_engineConfigString);
_engineConfig = EngineConfig.reconstruct(
ParsingUtilities.evaluateJsonStringToObject(_engineConfigString));
} catch (JSONException e) {
// ignore
}

View File

@ -41,6 +41,7 @@ import org.json.JSONObject;
import org.json.JSONWriter;
import com.google.refine.browsing.Engine.Mode;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.browsing.RowVisitor;
import com.google.refine.expr.ExpressionUtils;
import com.google.refine.model.AbstractOperation;
@ -58,13 +59,13 @@ public class BlankDownOperation extends EngineDependentMassCellOperation {
JSONObject engineConfig = obj.getJSONObject("engineConfig");
return new BlankDownOperation(
engineConfig,
EngineConfig.reconstruct(engineConfig),
obj.getString("columnName")
);
}
public BlankDownOperation(
JSONObject engineConfig,
EngineConfig engineConfig,
String columnName
) {
super(engineConfig, columnName, true);
@ -77,7 +78,7 @@ public class BlankDownOperation extends EngineDependentMassCellOperation {
writer.object();
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
writer.key("description"); writer.value(getBriefDescription(null));
writer.key("engineConfig"); writer.value(getEngineConfig());
writer.key("engineConfig"); getEngineConfig().write(writer, options);
writer.key("columnName"); writer.value(_columnName);
writer.endObject();
}

View File

@ -42,6 +42,7 @@ import org.json.JSONWriter;
import com.google.refine.browsing.Engine;
import com.google.refine.browsing.Engine.Mode;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.browsing.RowVisitor;
import com.google.refine.expr.ExpressionUtils;
import com.google.refine.model.AbstractOperation;
@ -59,13 +60,13 @@ public class FillDownOperation extends EngineDependentMassCellOperation {
JSONObject engineConfig = obj.getJSONObject("engineConfig");
return new FillDownOperation(
engineConfig,
EngineConfig.reconstruct(engineConfig),
obj.getString("columnName")
);
}
public FillDownOperation(
JSONObject engineConfig,
EngineConfig engineConfig,
String columnName
) {
super(engineConfig, columnName, true);
@ -78,7 +79,7 @@ public class FillDownOperation extends EngineDependentMassCellOperation {
writer.object();
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
writer.key("description"); writer.value(getBriefDescription(null));
writer.key("engineConfig"); writer.value(getEngineConfig());
writer.key("engineConfig"); getEngineConfig().write(writer, options);
writer.key("columnName"); writer.value(_columnName);
writer.endObject();
}

View File

@ -46,6 +46,7 @@ import org.json.JSONObject;
import org.json.JSONWriter;
import com.google.refine.Jsonizable;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.browsing.RowVisitor;
import com.google.refine.expr.Evaluable;
import com.google.refine.expr.ExpressionUtils;
@ -101,7 +102,7 @@ public class MassEditOperation extends EngineDependentMassCellOperation {
obj.getJSONObject("engineConfig") : null;
return new MassEditOperation(
engineConfig,
EngineConfig.reconstruct(engineConfig),
obj.getString("columnName"),
obj.getString("expression"),
reconstructEdits(obj.getJSONArray("edits"))
@ -145,7 +146,7 @@ public class MassEditOperation extends EngineDependentMassCellOperation {
return edits;
}
public MassEditOperation(JSONObject engineConfig, String columnName, String expression, List<Edit> edits) {
public MassEditOperation(EngineConfig engineConfig, String columnName, String expression, List<Edit> edits) {
super(engineConfig, columnName, true);
_expression = expression;
_edits = edits;
@ -158,7 +159,7 @@ public class MassEditOperation extends EngineDependentMassCellOperation {
writer.object();
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
writer.key("description"); writer.value(getBriefDescription(null));
writer.key("engineConfig"); writer.value(getEngineConfig());
writer.key("engineConfig"); getEngineConfig().write(writer, options);
writer.key("columnName"); writer.value(_columnName);
writer.key("expression"); writer.value(_expression);
writer.key("edits");

View File

@ -41,6 +41,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.browsing.RowVisitor;
import com.google.refine.expr.Evaluable;
import com.google.refine.expr.ExpressionUtils;
@ -66,7 +67,7 @@ public class TextTransformOperation extends EngineDependentMassCellOperation {
JSONObject engineConfig = obj.getJSONObject("engineConfig");
return new TextTransformOperation(
engineConfig,
EngineConfig.reconstruct(engineConfig),
obj.getString("columnName"),
obj.getString("expression"),
stringToOnError(obj.getString("onError")),
@ -95,7 +96,7 @@ public class TextTransformOperation extends EngineDependentMassCellOperation {
}
public TextTransformOperation(
JSONObject engineConfig,
EngineConfig engineConfig,
String columnName,
String expression,
OnError onError,
@ -116,7 +117,7 @@ public class TextTransformOperation extends EngineDependentMassCellOperation {
writer.object();
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
writer.key("description"); writer.value(getBriefDescription(null));
writer.key("engineConfig"); writer.value(getEngineConfig());
writer.key("engineConfig"); getEngineConfig().write(writer, options);
writer.key("columnName"); writer.value(_columnName);
writer.key("expression"); writer.value(_expression);
writer.key("onError"); writer.value(onErrorToString(_onError));

View File

@ -42,18 +42,20 @@ import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.ExecutionException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONWriter;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.refine.browsing.Engine;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.browsing.FilteredRows;
import com.google.refine.browsing.RowVisitor;
import com.google.refine.expr.EvalError;
@ -69,8 +71,6 @@ import com.google.refine.model.Project;
import com.google.refine.model.Row;
import com.google.refine.model.changes.CellAtRow;
import com.google.refine.model.changes.ColumnAdditionChange;
import com.google.refine.commands.HttpHeadersSupport;
import com.google.refine.commands.HttpHeadersSupport.HttpHeaderInfo;
import com.google.refine.operations.EngineDependentOperation;
import com.google.refine.operations.OnError;
import com.google.refine.operations.OperationRegistry;
@ -78,9 +78,6 @@ import com.google.refine.operations.cell.TextTransformOperation;
import com.google.refine.process.LongRunningProcess;
import com.google.refine.process.Process;
import com.google.refine.util.ParsingUtilities;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.LoadingCache;
import com.google.common.cache.CacheLoader;
public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperation {
@ -98,7 +95,7 @@ public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperat
JSONObject engineConfig = obj.getJSONObject("engineConfig");
return new ColumnAdditionByFetchingURLsOperation(
engineConfig,
EngineConfig.reconstruct(engineConfig),
obj.getString("baseColumnName"),
obj.getString("urlExpression"),
TextTransformOperation.stringToOnError(obj.getString("onError")),
@ -111,7 +108,7 @@ public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperat
}
public ColumnAdditionByFetchingURLsOperation(
JSONObject engineConfig,
EngineConfig engineConfig,
String baseColumnName,
String urlExpression,
OnError onError,
@ -142,7 +139,7 @@ public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperat
writer.object();
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
writer.key("description"); writer.value(getBriefDescription(null));
writer.key("engineConfig"); writer.value(getEngineConfig());
writer.key("engineConfig"); getEngineConfig().write(writer, options);
writer.key("newColumnName"); writer.value(_newColumnName);
writer.key("columnInsertIndex"); writer.value(_columnInsertIndex);
writer.key("baseColumnName"); writer.value(_baseColumnName);
@ -173,7 +170,7 @@ public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperat
@Override
public Process createProcess(Project project, Properties options) throws Exception {
Engine engine = createEngine(project);
engine.initializeFromJSON(_engineConfig);
engine.initializeFromConfig(_engineConfig);
Evaluable eval = MetaParser.parse(_urlExpression);

View File

@ -43,6 +43,7 @@ import org.json.JSONObject;
import org.json.JSONWriter;
import com.google.refine.browsing.Engine;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.browsing.FilteredRows;
import com.google.refine.browsing.RowVisitor;
import com.google.refine.expr.Evaluable;
@ -75,7 +76,7 @@ public class ColumnAdditionOperation extends EngineDependentOperation {
JSONObject engineConfig = obj.getJSONObject("engineConfig");
return new ColumnAdditionOperation(
engineConfig,
EngineConfig.reconstruct(engineConfig),
obj.getString("baseColumnName"),
obj.getString("expression"),
TextTransformOperation.stringToOnError(obj.getString("onError")),
@ -85,7 +86,7 @@ public class ColumnAdditionOperation extends EngineDependentOperation {
}
public ColumnAdditionOperation(
JSONObject engineConfig,
EngineConfig engineConfig,
String baseColumnName,
String expression,
OnError onError,
@ -109,7 +110,7 @@ public class ColumnAdditionOperation extends EngineDependentOperation {
writer.object();
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
writer.key("description"); writer.value(getBriefDescription(null));
writer.key("engineConfig"); writer.value(getEngineConfig());
writer.key("engineConfig"); getEngineConfig().write(writer, options);
writer.key("newColumnName"); writer.value(_newColumnName);
writer.key("columnInsertIndex"); writer.value(_columnInsertIndex);
writer.key("baseColumnName"); writer.value(_baseColumnName);

View File

@ -45,6 +45,7 @@ import org.json.JSONObject;
import org.json.JSONWriter;
import com.google.refine.browsing.Engine;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.browsing.FilteredRows;
import com.google.refine.browsing.RowVisitor;
import com.google.refine.expr.ExpressionUtils;
@ -78,7 +79,7 @@ public class ColumnSplitOperation extends EngineDependentOperation {
if ("separator".equals(mode)) {
return new ColumnSplitOperation(
engineConfig,
EngineConfig.reconstruct(engineConfig),
obj.getString("columnName"),
obj.getBoolean("guessCellType"),
obj.getBoolean("removeOriginalColumn"),
@ -88,7 +89,7 @@ public class ColumnSplitOperation extends EngineDependentOperation {
);
} else {
return new ColumnSplitOperation(
engineConfig,
EngineConfig.reconstruct(engineConfig),
obj.getString("columnName"),
obj.getBoolean("guessCellType"),
obj.getBoolean("removeOriginalColumn"),
@ -98,7 +99,7 @@ public class ColumnSplitOperation extends EngineDependentOperation {
}
public ColumnSplitOperation(
JSONObject engineConfig,
EngineConfig engineConfig,
String columnName,
boolean guessCellType,
boolean removeOriginalColumn,
@ -121,7 +122,7 @@ public class ColumnSplitOperation extends EngineDependentOperation {
}
public ColumnSplitOperation(
JSONObject engineConfig,
EngineConfig engineConfig,
String columnName,
boolean guessCellType,
boolean removeOriginalColumn,
@ -148,7 +149,7 @@ public class ColumnSplitOperation extends EngineDependentOperation {
writer.object();
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
writer.key("description"); writer.value(getBriefDescription(null));
writer.key("engineConfig"); writer.value(getEngineConfig());
writer.key("engineConfig"); getEngineConfig().write(writer, options);
writer.key("columnName"); writer.value(_columnName);
writer.key("guessCellType"); writer.value(_guessCellType);
writer.key("removeOriginalColumn"); writer.value(_removeOriginalColumn);

View File

@ -41,18 +41,14 @@ import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import com.google.refine.browsing.Engine;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.browsing.FilteredRows;
import com.google.refine.browsing.RowVisitor;
import com.google.refine.model.changes.DataExtensionChange;
import com.google.refine.model.recon.ReconciledDataExtensionJob;
import com.google.refine.model.recon.ReconciledDataExtensionJob.ColumnInfo;
import com.google.refine.model.recon.ReconciledDataExtensionJob.DataExtension;
import com.google.refine.history.HistoryEntry;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Cell;
@ -62,6 +58,10 @@ import com.google.refine.model.ReconCandidate;
import com.google.refine.model.ReconType;
import com.google.refine.model.Row;
import com.google.refine.model.changes.CellAtRow;
import com.google.refine.model.changes.DataExtensionChange;
import com.google.refine.model.recon.ReconciledDataExtensionJob;
import com.google.refine.model.recon.ReconciledDataExtensionJob.ColumnInfo;
import com.google.refine.model.recon.ReconciledDataExtensionJob.DataExtension;
import com.google.refine.operations.EngineDependentOperation;
import com.google.refine.operations.OperationRegistry;
import com.google.refine.process.LongRunningProcess;
@ -79,7 +79,7 @@ public class ExtendDataOperation extends EngineDependentOperation {
JSONObject engineConfig = obj.getJSONObject("engineConfig");
return new ExtendDataOperation(
engineConfig,
EngineConfig.reconstruct(engineConfig),
obj.getString("baseColumnName"),
obj.getString("endpoint"),
obj.getString("identifierSpace"),
@ -90,7 +90,7 @@ public class ExtendDataOperation extends EngineDependentOperation {
}
public ExtendDataOperation(
JSONObject engineConfig,
EngineConfig engineConfig,
String baseColumnName,
String endpoint,
String identifierSpace,
@ -115,7 +115,7 @@ public class ExtendDataOperation extends EngineDependentOperation {
writer.object();
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
writer.key("description"); writer.value(getBriefDescription(null));
writer.key("engineConfig"); writer.value(getEngineConfig());
writer.key("engineConfig"); getEngineConfig().write(writer, options);
writer.key("columnInsertIndex"); writer.value(_columnInsertIndex);
writer.key("baseColumnName"); writer.value(_baseColumnName);
writer.key("endpoint"); writer.value(_endpoint);
@ -148,14 +148,14 @@ public class ExtendDataOperation extends EngineDependentOperation {
public class ExtendDataProcess extends LongRunningProcess implements Runnable {
final protected Project _project;
final protected JSONObject _engineConfig;
final protected EngineConfig _engineConfig;
final protected long _historyEntryID;
protected int _cellIndex;
protected ReconciledDataExtensionJob _job;
public ExtendDataProcess(
Project project,
JSONObject engineConfig,
EngineConfig engineConfig,
String description
) throws JSONException {
super(description);
@ -186,7 +186,7 @@ public class ExtendDataOperation extends EngineDependentOperation {
protected void populateRowsWithMatches(List<Integer> rowIndices) throws Exception {
Engine engine = new Engine(_project);
engine.initializeFromJSON(_engineConfig);
engine.initializeFromConfig(_engineConfig);
Column column = _project.columnModel.getColumnByName(_baseColumnName);
if (column == null) {

View File

@ -40,6 +40,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.browsing.RowVisitor;
import com.google.refine.history.Change;
import com.google.refine.model.AbstractOperation;
@ -58,14 +59,14 @@ public class ReconClearSimilarCellsOperation extends EngineDependentMassCellOper
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
JSONObject engineConfig = obj.getJSONObject("engineConfig");
return new ReconClearSimilarCellsOperation(
engineConfig,
EngineConfig.reconstruct(engineConfig),
obj.getString("columnName"),
obj.getString("similarValue")
);
}
public ReconClearSimilarCellsOperation(
JSONObject engineConfig,
EngineConfig engineConfig,
String columnName,
String similarValue
) {
@ -80,7 +81,7 @@ public class ReconClearSimilarCellsOperation extends EngineDependentMassCellOper
writer.object();
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
writer.key("description"); writer.value(getBriefDescription(null));
writer.key("engineConfig"); writer.value(getEngineConfig());
writer.key("engineConfig"); getEngineConfig().write(writer, options);
writer.key("columnName"); writer.value(_columnName);
writer.key("similarValue"); writer.value(_similarValue);

View File

@ -47,6 +47,7 @@ import org.json.JSONObject;
import org.json.JSONWriter;
import com.google.refine.browsing.Engine;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.browsing.FilteredRows;
import com.google.refine.browsing.RowVisitor;
import com.google.refine.history.HistoryEntry;
@ -72,7 +73,7 @@ public class ReconCopyAcrossColumnsOperation extends EngineDependentOperation {
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
JSONObject engineConfig = obj.getJSONObject("engineConfig");
return new ReconCopyAcrossColumnsOperation(
engineConfig,
EngineConfig.reconstruct(engineConfig),
obj.getString("fromColumnName"),
JSONUtilities.getStringArray(obj, "toColumnNames"),
JSONUtilities.getStringArray(obj, "judgments"),
@ -81,7 +82,7 @@ public class ReconCopyAcrossColumnsOperation extends EngineDependentOperation {
}
public ReconCopyAcrossColumnsOperation(
JSONObject engineConfig,
EngineConfig engineConfig,
String fromColumnName,
String[] toColumnNames,
String[] judgments,
@ -100,7 +101,7 @@ public class ReconCopyAcrossColumnsOperation extends EngineDependentOperation {
writer.object();
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
writer.key("description"); writer.value(getBriefDescription(null));
writer.key("engineConfig"); writer.value(getEngineConfig());
writer.key("engineConfig"); getEngineConfig().write(writer, options);
writer.key("fromColumnName"); writer.value(_fromColumnName);
writer.key("toColumnNames");
writer.array();

View File

@ -42,6 +42,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.browsing.RowVisitor;
import com.google.refine.history.Change;
import com.google.refine.model.AbstractOperation;
@ -62,13 +63,13 @@ public class ReconDiscardJudgmentsOperation extends EngineDependentMassCellOpera
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
JSONObject engineConfig = obj.getJSONObject("engineConfig");
return new ReconDiscardJudgmentsOperation(
engineConfig,
EngineConfig.reconstruct(engineConfig),
obj.getString("columnName"),
obj.has("clearData") && obj.getBoolean("clearData")
);
}
public ReconDiscardJudgmentsOperation(JSONObject engineConfig, String columnName, boolean clearData) {
public ReconDiscardJudgmentsOperation(EngineConfig engineConfig, String columnName, boolean clearData) {
super(engineConfig, columnName, false);
_clearData = clearData;
}
@ -80,7 +81,7 @@ public class ReconDiscardJudgmentsOperation extends EngineDependentMassCellOpera
writer.object();
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
writer.key("description"); writer.value(getBriefDescription(null));
writer.key("engineConfig"); writer.value(getEngineConfig());
writer.key("engineConfig"); getEngineConfig().write(writer, options);
writer.key("columnName"); writer.value(_columnName);
writer.key("clearData"); writer.value(_clearData);
writer.endObject();

View File

@ -43,6 +43,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.browsing.RowVisitor;
import com.google.refine.expr.ExpressionUtils;
import com.google.refine.history.Change;
@ -93,7 +94,7 @@ public class ReconJudgeSimilarCellsOperation extends EngineDependentMassCellOper
}
return new ReconJudgeSimilarCellsOperation(
engineConfig,
EngineConfig.reconstruct(engineConfig),
obj.getString("columnName"),
obj.getString("similarValue"),
judgment,
@ -103,7 +104,7 @@ public class ReconJudgeSimilarCellsOperation extends EngineDependentMassCellOper
}
public ReconJudgeSimilarCellsOperation(
JSONObject engineConfig,
EngineConfig engineConfig,
String columnName,
String similarValue,
Judgment judgment,
@ -124,7 +125,7 @@ public class ReconJudgeSimilarCellsOperation extends EngineDependentMassCellOper
writer.object();
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
writer.key("description"); writer.value(getBriefDescription(null));
writer.key("engineConfig"); writer.value(getEngineConfig());
writer.key("engineConfig"); getEngineConfig().write(writer, options);
writer.key("columnName"); writer.value(_columnName);
writer.key("similarValue"); writer.value(_similarValue);
writer.key("judgment"); writer.value(Recon.judgmentToString(_judgment));

View File

@ -42,6 +42,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.browsing.RowVisitor;
import com.google.refine.history.Change;
import com.google.refine.model.AbstractOperation;
@ -64,13 +65,13 @@ public class ReconMarkNewTopicsOperation extends EngineDependentMassCellOperatio
JSONObject engineConfig = obj.getJSONObject("engineConfig");
return new ReconMarkNewTopicsOperation(
engineConfig,
EngineConfig.reconstruct(engineConfig),
obj.getString("columnName"),
obj.has("shareNewTopics") ? obj.getBoolean("shareNewTopics") : false
);
}
public ReconMarkNewTopicsOperation(JSONObject engineConfig, String columnName, boolean shareNewTopics) {
public ReconMarkNewTopicsOperation(EngineConfig engineConfig, String columnName, boolean shareNewTopics) {
super(engineConfig, columnName, false);
_shareNewTopics = shareNewTopics;
}
@ -82,7 +83,7 @@ public class ReconMarkNewTopicsOperation extends EngineDependentMassCellOperatio
writer.object();
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
writer.key("description"); writer.value(getBriefDescription(null));
writer.key("engineConfig"); writer.value(getEngineConfig());
writer.key("engineConfig"); getEngineConfig().write(writer, options);
writer.key("columnName"); writer.value(_columnName);
writer.key("shareNewTopics"); writer.value(_shareNewTopics);
writer.endObject();

View File

@ -42,6 +42,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.browsing.RowVisitor;
import com.google.refine.history.Change;
import com.google.refine.model.AbstractOperation;
@ -63,12 +64,12 @@ public class ReconMatchBestCandidatesOperation extends EngineDependentMassCellOp
String columnName = obj.getString("columnName");
return new ReconMatchBestCandidatesOperation(
engineConfig,
EngineConfig.reconstruct(engineConfig),
columnName
);
}
public ReconMatchBestCandidatesOperation(JSONObject engineConfig, String columnName) {
public ReconMatchBestCandidatesOperation(EngineConfig engineConfig, String columnName) {
super(engineConfig, columnName, false);
}
@ -79,7 +80,7 @@ public class ReconMatchBestCandidatesOperation extends EngineDependentMassCellOp
writer.object();
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
writer.key("description"); writer.value(getBriefDescription(null));
writer.key("engineConfig"); writer.value(getEngineConfig());
writer.key("engineConfig"); getEngineConfig().write(writer, options);
writer.key("columnName"); writer.value(_columnName);
writer.endObject();
}

View File

@ -43,6 +43,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.browsing.RowVisitor;
import com.google.refine.history.Change;
import com.google.refine.model.AbstractOperation;
@ -75,7 +76,7 @@ public class ReconMatchSpecificTopicOperation extends EngineDependentMassCellOpe
}
return new ReconMatchSpecificTopicOperation(
engineConfig,
EngineConfig.reconstruct(engineConfig),
obj.getString("columnName"),
new ReconCandidate(
match.getString("id"),
@ -89,7 +90,7 @@ public class ReconMatchSpecificTopicOperation extends EngineDependentMassCellOpe
}
public ReconMatchSpecificTopicOperation(
JSONObject engineConfig,
EngineConfig engineConfig,
String columnName,
ReconCandidate match,
String identifierSpace,
@ -108,7 +109,7 @@ public class ReconMatchSpecificTopicOperation extends EngineDependentMassCellOpe
writer.object();
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
writer.key("description"); writer.value(getBriefDescription(null));
writer.key("engineConfig"); writer.value(getEngineConfig());
writer.key("engineConfig"); getEngineConfig().write(writer, options);
writer.key("columnName"); writer.value(_columnName);
writer.key("match");
writer.object();

View File

@ -46,6 +46,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.refine.browsing.Engine;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.browsing.FilteredRows;
import com.google.refine.browsing.RowVisitor;
import com.google.refine.expr.ExpressionUtils;
@ -77,14 +78,14 @@ public class ReconOperation extends EngineDependentOperation {
JSONObject engineConfig = obj.getJSONObject("engineConfig");
return new ReconOperation(
engineConfig,
EngineConfig.reconstruct(engineConfig),
obj.getString("columnName"),
ReconConfig.reconstruct(obj.getJSONObject("config"))
);
}
public ReconOperation(
JSONObject engineConfig,
EngineConfig engineConfig,
String columnName,
ReconConfig reconConfig
) {
@ -116,7 +117,7 @@ public class ReconOperation extends EngineDependentOperation {
writer.key("description"); writer.value(getBriefDescription(null));
writer.key("columnName"); writer.value(_columnName);
writer.key("config"); _reconConfig.write(writer, options);
writer.key("engineConfig"); writer.value(getEngineConfig());
writer.key("engineConfig"); getEngineConfig().write(writer, options);
writer.endObject();
}
@ -140,15 +141,15 @@ public class ReconOperation extends EngineDependentOperation {
}
public class ReconProcess extends LongRunningProcess implements Runnable {
final protected Project _project;
final protected JSONObject _engineConfig;
final protected long _historyEntryID;
protected List<ReconEntry> _entries;
protected int _cellIndex;
final protected Project _project;
final protected EngineConfig _engineConfig;
final protected long _historyEntryID;
protected List<ReconEntry> _entries;
protected int _cellIndex;
public ReconProcess(
Project project,
JSONObject engineConfig,
EngineConfig engineConfig,
String description
) {
super(description);
@ -208,7 +209,7 @@ public class ReconOperation extends EngineDependentOperation {
protected void populateEntries() throws Exception {
Engine engine = new Engine(_project);
engine.initializeFromJSON(_engineConfig);
engine.initializeFromConfig(_engineConfig);
Column column = _project.columnModel.getColumnByName(_columnName);
if (column == null) {

View File

@ -42,6 +42,7 @@ import org.json.JSONObject;
import org.json.JSONWriter;
import com.google.refine.browsing.Engine;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.browsing.FilteredRows;
import com.google.refine.browsing.RowVisitor;
import com.google.refine.history.Change;
@ -62,12 +63,12 @@ public class RowFlagOperation extends EngineDependentOperation {
boolean flagged = obj.getBoolean("flagged");
return new RowFlagOperation(
engineConfig,
EngineConfig.reconstruct(engineConfig),
flagged
);
}
public RowFlagOperation(JSONObject engineConfig, boolean flagged) {
public RowFlagOperation(EngineConfig engineConfig, boolean flagged) {
super(engineConfig);
_flagged = flagged;
}
@ -79,7 +80,7 @@ public class RowFlagOperation extends EngineDependentOperation {
writer.object();
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
writer.key("description"); writer.value(getBriefDescription(null));
writer.key("engineConfig"); writer.value(getEngineConfig());
writer.key("engineConfig"); getEngineConfig().write(writer, options);
writer.key("flagged"); writer.value(_flagged);
writer.endObject();
}

View File

@ -42,6 +42,7 @@ import org.json.JSONObject;
import org.json.JSONWriter;
import com.google.refine.browsing.Engine;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.browsing.FilteredRows;
import com.google.refine.browsing.RowVisitor;
import com.google.refine.history.HistoryEntry;
@ -57,11 +58,11 @@ public class RowRemovalOperation extends EngineDependentOperation {
JSONObject engineConfig = obj.getJSONObject("engineConfig");
return new RowRemovalOperation(
engineConfig
EngineConfig.reconstruct(engineConfig)
);
}
public RowRemovalOperation(JSONObject engineConfig) {
public RowRemovalOperation(EngineConfig engineConfig) {
super(engineConfig);
}
@ -72,7 +73,7 @@ public class RowRemovalOperation extends EngineDependentOperation {
writer.object();
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
writer.key("description"); writer.value(getBriefDescription(null));
writer.key("engineConfig"); writer.value(getEngineConfig());
writer.key("engineConfig"); getEngineConfig().write(writer, options);
writer.endObject();
}

View File

@ -42,6 +42,7 @@ import org.json.JSONObject;
import org.json.JSONWriter;
import com.google.refine.browsing.Engine;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.browsing.FilteredRows;
import com.google.refine.browsing.RowVisitor;
import com.google.refine.history.Change;
@ -62,12 +63,12 @@ public class RowStarOperation extends EngineDependentOperation {
boolean starred = obj.getBoolean("starred");
return new RowStarOperation(
engineConfig,
EngineConfig.reconstruct(engineConfig),
starred
);
}
public RowStarOperation(JSONObject engineConfig, boolean starred) {
public RowStarOperation(EngineConfig engineConfig, boolean starred) {
super(engineConfig);
_starred = starred;
}
@ -79,7 +80,7 @@ public class RowStarOperation extends EngineDependentOperation {
writer.object();
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
writer.key("description"); writer.value(getBriefDescription(null));
writer.key("engineConfig"); writer.value(getEngineConfig());
writer.key("engineConfig"); getEngineConfig().write(writer, options);
writer.key("starred"); writer.value(_starred);
writer.endObject();
}

View File

@ -7,7 +7,7 @@ import com.google.refine.tests.util.TestUtils;
public class EvalErrorTests {
@Test
public void serializeEvalError() {
EvalError e = new EvalError("this is a critical error");
EvalError e = new EvalError("This is a critical error");
TestUtils.isSerializedTo(e, "{\"type\":\"error\",\"message\":\"This is a critical error\"}");
}
}

View File

@ -7,8 +7,6 @@ import com.google.refine.browsing.Engine;
import com.google.refine.model.Project;
import com.google.refine.tests.util.TestUtils;
// TODO Engine and engine config should be separated
// create an EngineConfig class that can be used in operations directly (to avoid manipulating JSONObject)
public class EngineTests {
@Test

View File

@ -40,6 +40,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import com.google.refine.browsing.Engine;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.commands.Command;
import com.google.refine.model.Project;
@ -53,7 +54,7 @@ public class CommandStub extends Command {
return getProject(request);
}
public JSONObject wrapGetEngineConfig(HttpServletRequest request)
public EngineConfig wrapGetEngineConfig(HttpServletRequest request)
throws JSONException {
return getEngineConfig(request);
}

View File

@ -52,6 +52,8 @@ import org.testng.annotations.Test;
import com.google.refine.ProjectManager;
import com.google.refine.browsing.Engine;
import com.google.refine.browsing.Engine.Mode;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.model.Project;
import com.google.refine.tests.RefineTest;
@ -151,11 +153,11 @@ public class CommandTests extends RefineTest {
@Test
public void getEngineConfigRegressionTest() {
when(request.getParameter("engine")).thenReturn("{\"hello\":\"world\"}");
JSONObject o = null;
when(request.getParameter("engine")).thenReturn("{\"mode\":\"row-based\"}");
EngineConfig o = null;
try {
o = SUT.wrapGetEngineConfig(request);
Assert.assertEquals("world", o.getString("hello"));
Assert.assertEquals(Mode.RowBased, o.getMode());
} catch (JSONException e) {
Assert.fail();
} catch (Exception e) {

View File

@ -45,6 +45,7 @@ import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.refine.browsing.Engine;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.browsing.RowVisitor;
import com.google.refine.expr.functions.FacetCount;
import com.google.refine.grel.Function;
@ -72,7 +73,7 @@ public class CacheTests extends RefineTest {
// dependencies
Project project;
Properties options;
JSONObject engine_config;
EngineConfig engine_config;
Engine engine;
Properties bindings;
@ -81,8 +82,8 @@ public class CacheTests extends RefineTest {
project = createProjectWithColumns("CacheTests", "Column A");
engine = new Engine(project);
engine_config = new JSONObject(ENGINE_JSON_DUPLICATES);
engine.initializeFromJSON(engine_config);
engine_config = EngineConfig.reconstruct(new JSONObject(ENGINE_JSON_DUPLICATES));
engine.initializeFromConfig(engine_config);
engine.setMode(Engine.Mode.RowBased);
bindings = new Properties();

View File

@ -11,6 +11,7 @@ import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import com.google.refine.ProjectManager;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
import com.google.refine.operations.OperationRegistry;
@ -56,7 +57,7 @@ public class BlankDownTests extends RefineTest {
@Test
public void testBlankDownRecords() throws Exception {
AbstractOperation op = new BlankDownOperation(
new JSONObject("{\"mode\":\"record-based\",\"facets\":[]}"),
EngineConfig.reconstruct(new JSONObject("{\"mode\":\"record-based\",\"facets\":[]}")),
"second");
Process process = op.createProcess(project, new Properties());
process.performImmediate();
@ -70,7 +71,7 @@ public class BlankDownTests extends RefineTest {
@Test
public void testBlankDownRows() throws Exception {
AbstractOperation op = new BlankDownOperation(
new JSONObject("{\"mode\":\"row-based\",\"facets\":[]}"),
EngineConfig.reconstruct(new JSONObject("{\"mode\":\"row-based\",\"facets\":[]}")),
"second");
Process process = op.createProcess(project, new Properties());
process.performImmediate();

View File

@ -11,6 +11,7 @@ import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import com.google.refine.ProjectManager;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
import com.google.refine.operations.OperationRegistry;
@ -55,7 +56,7 @@ public class FillDownTests extends RefineTest {
@Test
public void testFillDownRecordKey() throws Exception {
AbstractOperation op = new FillDownOperation(
new JSONObject("{\"mode\":\"record-based\",\"facets\":[]}"),
EngineConfig.reconstruct(new JSONObject("{\"mode\":\"record-based\",\"facets\":[]}")),
"key");
Process process = op.createProcess(project, new Properties());
process.performImmediate();
@ -71,7 +72,7 @@ public class FillDownTests extends RefineTest {
@Test
public void testFillDownRecords() throws Exception {
AbstractOperation op = new FillDownOperation(
new JSONObject("{\"mode\":\"record-based\",\"facets\":[]}"),
EngineConfig.reconstruct(new JSONObject("{\"mode\":\"record-based\",\"facets\":[]}")),
"second");
Process process = op.createProcess(project, new Properties());
process.performImmediate();
@ -87,7 +88,7 @@ public class FillDownTests extends RefineTest {
@Test
public void testFillDownRows() throws Exception {
AbstractOperation op = new FillDownOperation(
new JSONObject("{\"mode\":\"row-based\",\"facets\":[]}"),
EngineConfig.reconstruct(new JSONObject("{\"mode\":\"row-based\",\"facets\":[]}")),
"second");
Process process = op.createProcess(project, new Properties());
process.performImmediate();

View File

@ -46,6 +46,7 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.expr.ExpressionUtils;
import com.google.refine.model.Cell;
import com.google.refine.model.ModelException;
@ -75,7 +76,7 @@ public class ColumnAdditionByFetchingURLsOperationTests extends RefineTest {
// dependencies
private Project project;
private Properties options;
private JSONObject engine_config;
private EngineConfig engine_config = EngineConfig.reconstruct(new JSONObject(ENGINE_JSON_URLS));
@BeforeMethod
public void SetUp() throws JSONException, IOException, ModelException {

View File

@ -50,6 +50,7 @@ import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.refine.browsing.Engine;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.model.Cell;
import com.google.refine.model.ModelException;
import com.google.refine.model.Project;
@ -81,7 +82,7 @@ public class ExtendDataOperationTests extends RefineTest {
// dependencies
Project project;
Properties options;
JSONObject engine_config;
EngineConfig engine_config;
Engine engine;
@BeforeMethod
@ -91,8 +92,8 @@ public class ExtendDataOperationTests extends RefineTest {
options = mock(Properties.class);
engine = new Engine(project);
engine_config = new JSONObject(ENGINE_JSON_URLS);
engine.initializeFromJSON(engine_config);
engine_config = EngineConfig.reconstruct(new JSONObject(ENGINE_JSON_URLS));
engine.initializeFromConfig(engine_config);
engine.setMode(Engine.Mode.RowBased);
Row row = new Row(2);

View File

@ -21,7 +21,7 @@ public class ReconCopyAcrossColumnsOperationTests extends RefineTest {
public void serializeReconCopyAcrossColumnsOperation() throws Exception {
String json = "{\"op\":\"core/recon-copy-across-columns\","
+ "\"description\":\"Copy recon judgments from column source column to firstsecond\","
+ "\"engineConfig\":{\"mode\":\"row-based\"},"
+ "\"engineConfig\":{\"mode\":\"row-based\",\"facets\":[]},"
+ "\"fromColumnName\":\"source column\","
+ "\"toColumnNames\":[\"first\",\"second\"],"
+ "\"judgments\":[\"matched\",\"new\"],"

View File

@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.refine.browsing.EngineConfig;
import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Cell;
import com.google.refine.model.Column;
@ -26,7 +27,7 @@ import com.google.refine.tests.util.TestUtils;
public class ReconJudgeSimilarCellsTests extends RefineTest {
static final JSONObject ENGINE_CONFIG = new JSONObject("{\"mode\":\"row-based\"}}");
static final EngineConfig ENGINE_CONFIG = EngineConfig.reconstruct(new JSONObject("{\"mode\":\"row-based\"}}"));
@Override
@BeforeTest
@ -45,7 +46,7 @@ public class ReconJudgeSimilarCellsTests extends RefineTest {
null, true);
TestUtils.isSerializedTo(op, "{\"op\":\"core/recon-judge-similar-cells\","
+ "\"description\":\"Mark to create one single new item for all cells containing \\\"foo\\\" in column A\","
+ "\"engineConfig\":{\"mode\":\"row-based\"},"
+ "\"engineConfig\":{\"mode\":\"row-based\",\"facets\":[]},"
+ "\"columnName\":\"A\","
+ "\"similarValue\":\"foo\","
+ "\"judgment\":\"new\","

View File

@ -21,7 +21,7 @@ public class ReconMarkNewTopicsOperationTests extends RefineTest {
public void serializeReconMarkNewTopicsOperation() throws Exception {
String json = "{"
+ "\"op\":\"core/recon-mark-new-topics\","
+ "\"engineConfig\":{\"mode\":\"row-based\"},"
+ "\"engineConfig\":{\"mode\":\"row-based\",\"facets\":[]},"
+ "\"columnName\":\"my column\","
+ "\"shareNewTopics\":true,"
+ "\"description\":\"Mark to create new items for cells in column my column, one item for each group of similar cells\""