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.JSONWriter;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import com.google.refine.Jsonizable;
|
||||
import com.google.refine.browsing.facets.Facet;
|
||||
import com.google.refine.browsing.util.ConjunctiveFilteredRecords;
|
||||
@ -56,8 +58,11 @@ import com.google.refine.model.Row;
|
||||
*/
|
||||
public class Engine implements Jsonizable {
|
||||
static public enum Mode {
|
||||
@JsonProperty("row-based")
|
||||
RowBased,
|
||||
@JsonProperty("record-based")
|
||||
RecordBased
|
||||
|
||||
}
|
||||
|
||||
public final static String INCLUDE_DEPENDENT = "includeDependent";
|
||||
|
@ -10,6 +10,8 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import com.google.refine.Jsonizable;
|
||||
import com.google.refine.browsing.Engine.Mode;
|
||||
import com.google.refine.browsing.facets.FacetConfig;
|
||||
@ -30,10 +32,12 @@ public class EngineConfig implements Jsonizable {
|
||||
_mode = mode;
|
||||
}
|
||||
|
||||
@JsonProperty("mode")
|
||||
public Mode getMode() {
|
||||
return _mode;
|
||||
}
|
||||
|
||||
@JsonProperty("facets")
|
||||
public List<FacetConfig> getFacetConfigs() {
|
||||
return _facets;
|
||||
}
|
||||
|
@ -35,8 +35,11 @@ package com.google.refine.model;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import com.google.refine.Jsonizable;
|
||||
import com.google.refine.history.HistoryEntry;
|
||||
import com.google.refine.operations.OperationRegistry;
|
||||
import com.google.refine.process.Process;
|
||||
import com.google.refine.process.QuickHistoryEntryProcess;
|
||||
|
||||
@ -61,4 +64,14 @@ abstract public class AbstractOperation implements Jsonizable {
|
||||
protected String getBriefDescription(Project project) {
|
||||
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.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import com.google.refine.browsing.Engine;
|
||||
import com.google.refine.browsing.EngineConfig;
|
||||
import com.google.refine.browsing.FilteredRows;
|
||||
@ -87,6 +89,11 @@ abstract public class EngineDependentMassCellOperation extends EngineDependentOp
|
||||
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 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;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import com.google.refine.browsing.Engine;
|
||||
import com.google.refine.browsing.EngineConfig;
|
||||
import com.google.refine.model.AbstractOperation;
|
||||
@ -52,6 +54,7 @@ abstract public class EngineDependentOperation extends AbstractOperation {
|
||||
return engine;
|
||||
}
|
||||
|
||||
@JsonProperty("engineConfig")
|
||||
protected EngineConfig getEngineConfig() {
|
||||
return _engineConfig;
|
||||
}
|
||||
|
@ -43,6 +43,8 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import com.google.refine.expr.ExpressionUtils;
|
||||
import com.google.refine.history.HistoryEntry;
|
||||
import com.google.refine.model.AbstractOperation;
|
||||
@ -93,6 +95,21 @@ public class KeyValueColumnizeOperation extends AbstractOperation {
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
@JsonProperty("keyColumnName")
|
||||
public String getKeyColumnName() {
|
||||
return _keyColumnName;
|
||||
}
|
||||
|
||||
@JsonProperty("valueColumnName")
|
||||
public String getValueColumnName() {
|
||||
return _valueColumnName;
|
||||
}
|
||||
|
||||
@JsonProperty("noteColumnName")
|
||||
public String getNoteColumnName() {
|
||||
return _noteColumnName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBriefDescription(Project project) {
|
||||
return "Columnize by key column " +
|
||||
|
@ -45,6 +45,8 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import com.google.refine.Jsonizable;
|
||||
import com.google.refine.browsing.EngineConfig;
|
||||
import com.google.refine.browsing.RowVisitor;
|
||||
@ -67,9 +69,13 @@ public class MassEditOperation extends EngineDependentMassCellOperation {
|
||||
final protected List<Edit> _edits;
|
||||
|
||||
static public class Edit implements Jsonizable {
|
||||
@JsonProperty("from")
|
||||
final public List<String> from;
|
||||
@JsonProperty("fromBlank")
|
||||
final public boolean fromBlank;
|
||||
@JsonProperty("fromError")
|
||||
final public boolean fromError;
|
||||
@JsonProperty("to")
|
||||
final public Serializable to;
|
||||
|
||||
public Edit(List<String> from, boolean fromBlank, boolean fromError, Serializable to) {
|
||||
@ -171,6 +177,16 @@ public class MassEditOperation extends EngineDependentMassCellOperation {
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
@JsonProperty("expression")
|
||||
public String getExpression() {
|
||||
return _expression;
|
||||
}
|
||||
|
||||
@JsonProperty("edits")
|
||||
public List<Edit> getEdits() {
|
||||
return _edits;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBriefDescription(Project project) {
|
||||
return "Mass edit cells in column " + _columnName;
|
||||
|
@ -41,6 +41,8 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import com.google.refine.expr.ExpressionUtils;
|
||||
import com.google.refine.history.HistoryEntry;
|
||||
import com.google.refine.model.AbstractOperation;
|
||||
@ -87,6 +89,21 @@ public class MultiValuedCellJoinOperation extends AbstractOperation {
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
@JsonProperty("columnName")
|
||||
public String getColumnName() {
|
||||
return _columnName;
|
||||
}
|
||||
|
||||
@JsonProperty("keyColumnName")
|
||||
public String getKeyColumnName() {
|
||||
return _keyColumnName;
|
||||
}
|
||||
|
||||
@JsonProperty("separator")
|
||||
public String getSeparator() {
|
||||
return _separator;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBriefDescription(Project project) {
|
||||
return "Join multi-valued cells in column " + _columnName;
|
||||
|
@ -43,6 +43,10 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
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.model.AbstractOperation;
|
||||
import com.google.refine.model.Cell;
|
||||
@ -58,7 +62,7 @@ public class MultiValuedCellSplitOperation extends AbstractOperation {
|
||||
final protected String _keyColumnName;
|
||||
final protected String _mode;
|
||||
final protected String _separator;
|
||||
final protected boolean _regex;
|
||||
final protected Boolean _regex;
|
||||
|
||||
final protected int[] _fieldLengths;
|
||||
|
||||
@ -72,7 +76,7 @@ public class MultiValuedCellSplitOperation extends AbstractOperation {
|
||||
obj.getString("separator"),
|
||||
obj.getBoolean("regex")
|
||||
);
|
||||
} else {
|
||||
} else { // mode == "lengths"
|
||||
return new MultiValuedCellSplitOperation(
|
||||
obj.getString("columnName"),
|
||||
obj.getString("keyColumnName"),
|
||||
@ -106,11 +110,44 @@ public class MultiValuedCellSplitOperation extends AbstractOperation {
|
||||
|
||||
_mode = "lengths";
|
||||
_separator = null;
|
||||
_regex = false;
|
||||
_regex = null;
|
||||
|
||||
_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
|
||||
public void write(JSONWriter writer, Properties options)
|
||||
throws JSONException {
|
||||
|
@ -41,6 +41,8 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import com.google.refine.history.HistoryEntry;
|
||||
import com.google.refine.model.AbstractOperation;
|
||||
import com.google.refine.model.Cell;
|
||||
@ -81,6 +83,16 @@ public class TransposeRowsIntoColumnsOperation extends AbstractOperation {
|
||||
writer.endObject();
|
||||
}
|
||||
|
||||
@JsonProperty("rowCount")
|
||||
public int getRowCount() {
|
||||
return _rowCount;
|
||||
}
|
||||
|
||||
@JsonProperty("columnName")
|
||||
public String getColumnName() {
|
||||
return _columnName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBriefDescription(Project project) {
|
||||
return "Transpose every " + _rowCount + " cells in column " + _columnName + " into separate columns";
|
||||
|
@ -72,7 +72,7 @@ public class SplitMultiValuedCellsTests extends RefineTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializeMultiValuedCellSplitOperation() throws JSONException, Exception {
|
||||
public void serializeMultiValuedCellSplitOperationWithSeparator() throws JSONException, Exception {
|
||||
String json = "{\"op\":\"core/multivalued-cell-split\","
|
||||
+ "\"description\":\"Split multi-valued cells in column Value\","
|
||||
+ "\"columnName\":\"Value\","
|
||||
@ -83,6 +83,17 @@ public class SplitMultiValuedCellsTests extends RefineTest {
|
||||
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
|
||||
* https://github.com/OpenRefine/OpenRefine/issues/1268
|
||||
|
Loading…
Reference in New Issue
Block a user