Jackson serialization for cell operations
This commit is contained in:
parent
c140f90db1
commit
539585fc5e
@ -43,6 +43,8 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import com.google.refine.Jsonizable;
|
import com.google.refine.Jsonizable;
|
||||||
import com.google.refine.browsing.facets.Facet;
|
import com.google.refine.browsing.facets.Facet;
|
||||||
import com.google.refine.browsing.util.ConjunctiveFilteredRecords;
|
import com.google.refine.browsing.util.ConjunctiveFilteredRecords;
|
||||||
@ -56,8 +58,11 @@ import com.google.refine.model.Row;
|
|||||||
*/
|
*/
|
||||||
public class Engine implements Jsonizable {
|
public class Engine implements Jsonizable {
|
||||||
static public enum Mode {
|
static public enum Mode {
|
||||||
|
@JsonProperty("row-based")
|
||||||
RowBased,
|
RowBased,
|
||||||
|
@JsonProperty("record-based")
|
||||||
RecordBased
|
RecordBased
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static String INCLUDE_DEPENDENT = "includeDependent";
|
public final static String INCLUDE_DEPENDENT = "includeDependent";
|
||||||
|
@ -10,6 +10,8 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import com.google.refine.Jsonizable;
|
import com.google.refine.Jsonizable;
|
||||||
import com.google.refine.browsing.Engine.Mode;
|
import com.google.refine.browsing.Engine.Mode;
|
||||||
import com.google.refine.browsing.facets.FacetConfig;
|
import com.google.refine.browsing.facets.FacetConfig;
|
||||||
@ -30,10 +32,12 @@ public class EngineConfig implements Jsonizable {
|
|||||||
_mode = mode;
|
_mode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonProperty("mode")
|
||||||
public Mode getMode() {
|
public Mode getMode() {
|
||||||
return _mode;
|
return _mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonProperty("facets")
|
||||||
public List<FacetConfig> getFacetConfigs() {
|
public List<FacetConfig> getFacetConfigs() {
|
||||||
return _facets;
|
return _facets;
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,11 @@ package com.google.refine.model;
|
|||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import com.google.refine.Jsonizable;
|
import com.google.refine.Jsonizable;
|
||||||
import com.google.refine.history.HistoryEntry;
|
import com.google.refine.history.HistoryEntry;
|
||||||
|
import com.google.refine.operations.OperationRegistry;
|
||||||
import com.google.refine.process.Process;
|
import com.google.refine.process.Process;
|
||||||
import com.google.refine.process.QuickHistoryEntryProcess;
|
import com.google.refine.process.QuickHistoryEntryProcess;
|
||||||
|
|
||||||
@ -61,4 +64,14 @@ abstract public class AbstractOperation implements Jsonizable {
|
|||||||
protected String getBriefDescription(Project project) {
|
protected String getBriefDescription(Project project) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonProperty("op")
|
||||||
|
public String getOperationId() {
|
||||||
|
return OperationRegistry.s_opClassToName.get(this.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("description")
|
||||||
|
public String getJsonDescription() {
|
||||||
|
return getBriefDescription(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,8 @@ package com.google.refine.operations;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import com.google.refine.browsing.Engine;
|
import com.google.refine.browsing.Engine;
|
||||||
import com.google.refine.browsing.EngineConfig;
|
import com.google.refine.browsing.EngineConfig;
|
||||||
import com.google.refine.browsing.FilteredRows;
|
import com.google.refine.browsing.FilteredRows;
|
||||||
@ -87,6 +89,11 @@ abstract public class EngineDependentMassCellOperation extends EngineDependentOp
|
|||||||
cellChanges, column.getName(), _updateRowContextDependencies);
|
cellChanges, column.getName(), _updateRowContextDependencies);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonProperty("columnName")
|
||||||
|
protected String getColumnName() {
|
||||||
|
return _columnName;
|
||||||
|
}
|
||||||
|
|
||||||
abstract protected RowVisitor createRowVisitor(Project project, List<CellChange> cellChanges, long historyEntryID) throws Exception;
|
abstract protected RowVisitor createRowVisitor(Project project, List<CellChange> cellChanges, long historyEntryID) throws Exception;
|
||||||
abstract protected String createDescription(Column column, List<CellChange> cellChanges);
|
abstract protected String createDescription(Column column, List<CellChange> cellChanges);
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
package com.google.refine.operations;
|
package com.google.refine.operations;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import com.google.refine.browsing.Engine;
|
import com.google.refine.browsing.Engine;
|
||||||
import com.google.refine.browsing.EngineConfig;
|
import com.google.refine.browsing.EngineConfig;
|
||||||
import com.google.refine.model.AbstractOperation;
|
import com.google.refine.model.AbstractOperation;
|
||||||
@ -52,6 +54,7 @@ abstract public class EngineDependentOperation extends AbstractOperation {
|
|||||||
return engine;
|
return engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonProperty("engineConfig")
|
||||||
protected EngineConfig getEngineConfig() {
|
protected EngineConfig getEngineConfig() {
|
||||||
return _engineConfig;
|
return _engineConfig;
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,8 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import com.google.refine.expr.ExpressionUtils;
|
import com.google.refine.expr.ExpressionUtils;
|
||||||
import com.google.refine.history.HistoryEntry;
|
import com.google.refine.history.HistoryEntry;
|
||||||
import com.google.refine.model.AbstractOperation;
|
import com.google.refine.model.AbstractOperation;
|
||||||
@ -92,6 +94,21 @@ public class KeyValueColumnizeOperation extends AbstractOperation {
|
|||||||
writer.key("noteColumnName"); writer.value(_noteColumnName);
|
writer.key("noteColumnName"); writer.value(_noteColumnName);
|
||||||
writer.endObject();
|
writer.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonProperty("keyColumnName")
|
||||||
|
public String getKeyColumnName() {
|
||||||
|
return _keyColumnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("valueColumnName")
|
||||||
|
public String getValueColumnName() {
|
||||||
|
return _valueColumnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("noteColumnName")
|
||||||
|
public String getNoteColumnName() {
|
||||||
|
return _noteColumnName;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getBriefDescription(Project project) {
|
protected String getBriefDescription(Project project) {
|
||||||
|
@ -45,6 +45,8 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import com.google.refine.Jsonizable;
|
import com.google.refine.Jsonizable;
|
||||||
import com.google.refine.browsing.EngineConfig;
|
import com.google.refine.browsing.EngineConfig;
|
||||||
import com.google.refine.browsing.RowVisitor;
|
import com.google.refine.browsing.RowVisitor;
|
||||||
@ -67,9 +69,13 @@ public class MassEditOperation extends EngineDependentMassCellOperation {
|
|||||||
final protected List<Edit> _edits;
|
final protected List<Edit> _edits;
|
||||||
|
|
||||||
static public class Edit implements Jsonizable {
|
static public class Edit implements Jsonizable {
|
||||||
|
@JsonProperty("from")
|
||||||
final public List<String> from;
|
final public List<String> from;
|
||||||
|
@JsonProperty("fromBlank")
|
||||||
final public boolean fromBlank;
|
final public boolean fromBlank;
|
||||||
|
@JsonProperty("fromError")
|
||||||
final public boolean fromError;
|
final public boolean fromError;
|
||||||
|
@JsonProperty("to")
|
||||||
final public Serializable to;
|
final public Serializable to;
|
||||||
|
|
||||||
public Edit(List<String> from, boolean fromBlank, boolean fromError, Serializable to) {
|
public Edit(List<String> from, boolean fromBlank, boolean fromError, Serializable to) {
|
||||||
@ -170,6 +176,16 @@ public class MassEditOperation extends EngineDependentMassCellOperation {
|
|||||||
writer.endArray();
|
writer.endArray();
|
||||||
writer.endObject();
|
writer.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonProperty("expression")
|
||||||
|
public String getExpression() {
|
||||||
|
return _expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("edits")
|
||||||
|
public List<Edit> getEdits() {
|
||||||
|
return _edits;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getBriefDescription(Project project) {
|
protected String getBriefDescription(Project project) {
|
||||||
|
@ -41,6 +41,8 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import com.google.refine.expr.ExpressionUtils;
|
import com.google.refine.expr.ExpressionUtils;
|
||||||
import com.google.refine.history.HistoryEntry;
|
import com.google.refine.history.HistoryEntry;
|
||||||
import com.google.refine.model.AbstractOperation;
|
import com.google.refine.model.AbstractOperation;
|
||||||
@ -87,6 +89,21 @@ public class MultiValuedCellJoinOperation extends AbstractOperation {
|
|||||||
writer.endObject();
|
writer.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonProperty("columnName")
|
||||||
|
public String getColumnName() {
|
||||||
|
return _columnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("keyColumnName")
|
||||||
|
public String getKeyColumnName() {
|
||||||
|
return _keyColumnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("separator")
|
||||||
|
public String getSeparator() {
|
||||||
|
return _separator;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getBriefDescription(Project project) {
|
protected String getBriefDescription(Project project) {
|
||||||
return "Join multi-valued cells in column " + _columnName;
|
return "Join multi-valued cells in column " + _columnName;
|
||||||
|
@ -43,6 +43,10 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import com.google.refine.history.HistoryEntry;
|
import com.google.refine.history.HistoryEntry;
|
||||||
import com.google.refine.model.AbstractOperation;
|
import com.google.refine.model.AbstractOperation;
|
||||||
import com.google.refine.model.Cell;
|
import com.google.refine.model.Cell;
|
||||||
@ -58,7 +62,7 @@ public class MultiValuedCellSplitOperation extends AbstractOperation {
|
|||||||
final protected String _keyColumnName;
|
final protected String _keyColumnName;
|
||||||
final protected String _mode;
|
final protected String _mode;
|
||||||
final protected String _separator;
|
final protected String _separator;
|
||||||
final protected boolean _regex;
|
final protected Boolean _regex;
|
||||||
|
|
||||||
final protected int[] _fieldLengths;
|
final protected int[] _fieldLengths;
|
||||||
|
|
||||||
@ -72,7 +76,7 @@ public class MultiValuedCellSplitOperation extends AbstractOperation {
|
|||||||
obj.getString("separator"),
|
obj.getString("separator"),
|
||||||
obj.getBoolean("regex")
|
obj.getBoolean("regex")
|
||||||
);
|
);
|
||||||
} else {
|
} else { // mode == "lengths"
|
||||||
return new MultiValuedCellSplitOperation(
|
return new MultiValuedCellSplitOperation(
|
||||||
obj.getString("columnName"),
|
obj.getString("columnName"),
|
||||||
obj.getString("keyColumnName"),
|
obj.getString("keyColumnName"),
|
||||||
@ -106,10 +110,43 @@ public class MultiValuedCellSplitOperation extends AbstractOperation {
|
|||||||
|
|
||||||
_mode = "lengths";
|
_mode = "lengths";
|
||||||
_separator = null;
|
_separator = null;
|
||||||
_regex = false;
|
_regex = null;
|
||||||
|
|
||||||
_fieldLengths = fieldLengths;
|
_fieldLengths = fieldLengths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonProperty("columnName")
|
||||||
|
public String getColumnName() {
|
||||||
|
return _columnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("keyColumnName")
|
||||||
|
public String getKeyColumnName() {
|
||||||
|
return _keyColumnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("mode")
|
||||||
|
public String getMode() {
|
||||||
|
return _mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("separator")
|
||||||
|
@JsonInclude(Include.NON_NULL)
|
||||||
|
public String getSeparator() {
|
||||||
|
return _separator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("regex")
|
||||||
|
@JsonInclude(Include.NON_NULL)
|
||||||
|
public Boolean getRegex() {
|
||||||
|
return _regex;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("fieldLengths")
|
||||||
|
@JsonInclude(Include.NON_NULL)
|
||||||
|
public int[] getFieldLengths() {
|
||||||
|
return _fieldLengths;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
|
@ -41,6 +41,8 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import com.google.refine.history.HistoryEntry;
|
import com.google.refine.history.HistoryEntry;
|
||||||
import com.google.refine.model.AbstractOperation;
|
import com.google.refine.model.AbstractOperation;
|
||||||
import com.google.refine.model.Cell;
|
import com.google.refine.model.Cell;
|
||||||
@ -80,6 +82,16 @@ public class TransposeRowsIntoColumnsOperation extends AbstractOperation {
|
|||||||
writer.key("rowCount"); writer.value(_rowCount);
|
writer.key("rowCount"); writer.value(_rowCount);
|
||||||
writer.endObject();
|
writer.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonProperty("rowCount")
|
||||||
|
public int getRowCount() {
|
||||||
|
return _rowCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("columnName")
|
||||||
|
public String getColumnName() {
|
||||||
|
return _columnName;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getBriefDescription(Project project) {
|
protected String getBriefDescription(Project project) {
|
||||||
|
@ -72,7 +72,7 @@ public class SplitMultiValuedCellsTests extends RefineTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void serializeMultiValuedCellSplitOperation() throws JSONException, Exception {
|
public void serializeMultiValuedCellSplitOperationWithSeparator() throws JSONException, Exception {
|
||||||
String json = "{\"op\":\"core/multivalued-cell-split\","
|
String json = "{\"op\":\"core/multivalued-cell-split\","
|
||||||
+ "\"description\":\"Split multi-valued cells in column Value\","
|
+ "\"description\":\"Split multi-valued cells in column Value\","
|
||||||
+ "\"columnName\":\"Value\","
|
+ "\"columnName\":\"Value\","
|
||||||
@ -82,6 +82,17 @@ public class SplitMultiValuedCellsTests extends RefineTest {
|
|||||||
+ "\"regex\":false}";
|
+ "\"regex\":false}";
|
||||||
TestUtils.isSerializedTo(MultiValuedCellSplitOperation.reconstruct(project, new JSONObject(json)), json);
|
TestUtils.isSerializedTo(MultiValuedCellSplitOperation.reconstruct(project, new JSONObject(json)), json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void serializeMultiValuedCellSplitOperationWithLengths() throws JSONException, Exception {
|
||||||
|
String json = "{\"op\":\"core/multivalued-cell-split\","
|
||||||
|
+ "\"description\":\"Split multi-valued cells in column Value\","
|
||||||
|
+ "\"columnName\":\"Value\","
|
||||||
|
+ "\"keyColumnName\":\"Key\","
|
||||||
|
+ "\"mode\":\"lengths\","
|
||||||
|
+ "\"fieldLengths\":[1,1]}";
|
||||||
|
TestUtils.isSerializedTo(MultiValuedCellSplitOperation.reconstruct(project, new JSONObject(json)), json);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test to demonstrate the intended behaviour of the function, for issue #1268
|
* Test to demonstrate the intended behaviour of the function, for issue #1268
|
||||||
|
Loading…
Reference in New Issue
Block a user