Jackson deserialization for ReconCopyAcrossColumnsOperation

This commit is contained in:
Antonin Delpeuch 2018-10-22 10:15:56 +01:00
parent f573f37a97
commit e40d68afaf

View File

@ -33,6 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.refine.operations.recon; package com.google.refine.operations.recon;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -43,6 +44,7 @@ import java.util.Set;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject; import org.json.JSONObject;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.refine.browsing.Engine; import com.google.refine.browsing.Engine;
@ -61,6 +63,7 @@ import com.google.refine.model.changes.CellChange;
import com.google.refine.model.changes.MassChange; import com.google.refine.model.changes.MassChange;
import com.google.refine.operations.EngineDependentOperation; import com.google.refine.operations.EngineDependentOperation;
import com.google.refine.util.JSONUtilities; import com.google.refine.util.JSONUtilities;
import com.google.refine.util.ParsingUtilities;
public class ReconCopyAcrossColumnsOperation extends EngineDependentOperation { public class ReconCopyAcrossColumnsOperation extends EngineDependentOperation {
final protected String _fromColumnName; final protected String _fromColumnName;
@ -68,22 +71,21 @@ public class ReconCopyAcrossColumnsOperation extends EngineDependentOperation {
final protected String[] _judgments; final protected String[] _judgments;
final protected boolean _applyToJudgedCells; final protected boolean _applyToJudgedCells;
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { static public AbstractOperation reconstruct(Project project, JSONObject obj) throws IOException {
JSONObject engineConfig = obj.getJSONObject("engineConfig"); return ParsingUtilities.mapper.readValue(obj.toString(), ReconCopyAcrossColumnsOperation.class);
return new ReconCopyAcrossColumnsOperation(
EngineConfig.reconstruct(engineConfig),
obj.getString("fromColumnName"),
JSONUtilities.getStringArray(obj, "toColumnNames"),
JSONUtilities.getStringArray(obj, "judgments"),
obj.getBoolean("applyToJudgedCells")
);
} }
@JsonCreator
public ReconCopyAcrossColumnsOperation( public ReconCopyAcrossColumnsOperation(
@JsonProperty("engineConfig")
EngineConfig engineConfig, EngineConfig engineConfig,
@JsonProperty("fromColumnName")
String fromColumnName, String fromColumnName,
@JsonProperty("toColumnNames")
String[] toColumnNames, String[] toColumnNames,
@JsonProperty("judgments")
String[] judgments, String[] judgments,
@JsonProperty("applyToJudgedCells")
boolean applyToJudgedCells) { boolean applyToJudgedCells) {
super(engineConfig); super(engineConfig);
_fromColumnName = fromColumnName; _fromColumnName = fromColumnName;