diff --git a/main/src/com/google/refine/browsing/Engine.java b/main/src/com/google/refine/browsing/Engine.java index c3e33120d..f0ef66770 100644 --- a/main/src/com/google/refine/browsing/Engine.java +++ b/main/src/com/google/refine/browsing/Engine.java @@ -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"; diff --git a/main/src/com/google/refine/browsing/EngineConfig.java b/main/src/com/google/refine/browsing/EngineConfig.java index 0ae50313b..6a058a29f 100644 --- a/main/src/com/google/refine/browsing/EngineConfig.java +++ b/main/src/com/google/refine/browsing/EngineConfig.java @@ -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 getFacetConfigs() { return _facets; } diff --git a/main/src/com/google/refine/model/AbstractOperation.java b/main/src/com/google/refine/model/AbstractOperation.java index af68364e6..f21c930d9 100644 --- a/main/src/com/google/refine/model/AbstractOperation.java +++ b/main/src/com/google/refine/model/AbstractOperation.java @@ -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); + } } diff --git a/main/src/com/google/refine/operations/EngineDependentMassCellOperation.java b/main/src/com/google/refine/operations/EngineDependentMassCellOperation.java index d5e02e165..1ebbe8bec 100644 --- a/main/src/com/google/refine/operations/EngineDependentMassCellOperation.java +++ b/main/src/com/google/refine/operations/EngineDependentMassCellOperation.java @@ -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 cellChanges, long historyEntryID) throws Exception; abstract protected String createDescription(Column column, List cellChanges); } diff --git a/main/src/com/google/refine/operations/EngineDependentOperation.java b/main/src/com/google/refine/operations/EngineDependentOperation.java index 8067d160c..3cf969164 100644 --- a/main/src/com/google/refine/operations/EngineDependentOperation.java +++ b/main/src/com/google/refine/operations/EngineDependentOperation.java @@ -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; } diff --git a/main/src/com/google/refine/operations/cell/KeyValueColumnizeOperation.java b/main/src/com/google/refine/operations/cell/KeyValueColumnizeOperation.java index 7ca3380cf..37ca3a7af 100644 --- a/main/src/com/google/refine/operations/cell/KeyValueColumnizeOperation.java +++ b/main/src/com/google/refine/operations/cell/KeyValueColumnizeOperation.java @@ -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; @@ -92,6 +94,21 @@ public class KeyValueColumnizeOperation extends AbstractOperation { writer.key("noteColumnName"); writer.value(_noteColumnName); 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) { diff --git a/main/src/com/google/refine/operations/cell/MassEditOperation.java b/main/src/com/google/refine/operations/cell/MassEditOperation.java index b6c21e396..3a288b2fe 100644 --- a/main/src/com/google/refine/operations/cell/MassEditOperation.java +++ b/main/src/com/google/refine/operations/cell/MassEditOperation.java @@ -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 _edits; static public class Edit implements Jsonizable { + @JsonProperty("from") final public List from; + @JsonProperty("fromBlank") final public boolean fromBlank; + @JsonProperty("fromError") final public boolean fromError; + @JsonProperty("to") final public Serializable to; public Edit(List from, boolean fromBlank, boolean fromError, Serializable to) { @@ -170,6 +176,16 @@ public class MassEditOperation extends EngineDependentMassCellOperation { writer.endArray(); writer.endObject(); } + + @JsonProperty("expression") + public String getExpression() { + return _expression; + } + + @JsonProperty("edits") + public List getEdits() { + return _edits; + } @Override protected String getBriefDescription(Project project) { diff --git a/main/src/com/google/refine/operations/cell/MultiValuedCellJoinOperation.java b/main/src/com/google/refine/operations/cell/MultiValuedCellJoinOperation.java index 8a7376894..ba1b37a18 100644 --- a/main/src/com/google/refine/operations/cell/MultiValuedCellJoinOperation.java +++ b/main/src/com/google/refine/operations/cell/MultiValuedCellJoinOperation.java @@ -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; diff --git a/main/src/com/google/refine/operations/cell/MultiValuedCellSplitOperation.java b/main/src/com/google/refine/operations/cell/MultiValuedCellSplitOperation.java index 83d2fdbca..d9537f941 100644 --- a/main/src/com/google/refine/operations/cell/MultiValuedCellSplitOperation.java +++ b/main/src/com/google/refine/operations/cell/MultiValuedCellSplitOperation.java @@ -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,10 +110,43 @@ 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) diff --git a/main/src/com/google/refine/operations/cell/TransposeRowsIntoColumnsOperation.java b/main/src/com/google/refine/operations/cell/TransposeRowsIntoColumnsOperation.java index 0782c70b0..bb145be4a 100644 --- a/main/src/com/google/refine/operations/cell/TransposeRowsIntoColumnsOperation.java +++ b/main/src/com/google/refine/operations/cell/TransposeRowsIntoColumnsOperation.java @@ -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; @@ -80,6 +82,16 @@ public class TransposeRowsIntoColumnsOperation extends AbstractOperation { writer.key("rowCount"); writer.value(_rowCount); writer.endObject(); } + + @JsonProperty("rowCount") + public int getRowCount() { + return _rowCount; + } + + @JsonProperty("columnName") + public String getColumnName() { + return _columnName; + } @Override protected String getBriefDescription(Project project) { diff --git a/main/tests/server/src/com/google/refine/tests/operations/cell/SplitMultiValuedCellsTests.java b/main/tests/server/src/com/google/refine/tests/operations/cell/SplitMultiValuedCellsTests.java index 2db201031..81788b9ac 100644 --- a/main/tests/server/src/com/google/refine/tests/operations/cell/SplitMultiValuedCellsTests.java +++ b/main/tests/server/src/com/google/refine/tests/operations/cell/SplitMultiValuedCellsTests.java @@ -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\"," @@ -82,6 +82,17 @@ public class SplitMultiValuedCellsTests extends RefineTest { + "\"regex\":false}"; 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