Jackson deserialization for TransposeColumnsIntoRowsOperation
This commit is contained in:
parent
8647e3d586
commit
6358a4aeb5
@ -38,6 +38,12 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
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;
|
||||||
@ -45,42 +51,80 @@ import com.google.refine.model.Column;
|
|||||||
import com.google.refine.model.Project;
|
import com.google.refine.model.Project;
|
||||||
import com.google.refine.model.Row;
|
import com.google.refine.model.Row;
|
||||||
import com.google.refine.model.changes.MassRowColumnChange;
|
import com.google.refine.model.changes.MassRowColumnChange;
|
||||||
import com.google.refine.util.JSONUtilities;
|
import com.google.refine.util.ParsingUtilities;
|
||||||
|
|
||||||
public class TransposeColumnsIntoRowsOperation extends AbstractOperation {
|
public class TransposeColumnsIntoRowsOperation extends AbstractOperation {
|
||||||
|
@JsonProperty("startColumnName")
|
||||||
final protected String _startColumnName;
|
final protected String _startColumnName;
|
||||||
|
@JsonProperty("columnCount")
|
||||||
final protected int _columnCount;
|
final protected int _columnCount;
|
||||||
|
@JsonProperty("ignoreBlankCells")
|
||||||
final protected boolean _ignoreBlankCells;
|
final protected boolean _ignoreBlankCells;
|
||||||
|
@JsonProperty("fillDown")
|
||||||
final protected boolean _fillDown;
|
final protected boolean _fillDown;
|
||||||
|
|
||||||
|
@JsonProperty("combinedColumnName")
|
||||||
|
@JsonInclude(Include.NON_NULL)
|
||||||
final protected String _combinedColumnName;
|
final protected String _combinedColumnName;
|
||||||
|
@JsonIgnore
|
||||||
final protected boolean _prependColumnName;
|
final protected boolean _prependColumnName;
|
||||||
|
@JsonProperty("separator")
|
||||||
final protected String _separator;
|
final protected String _separator;
|
||||||
|
|
||||||
|
@JsonProperty("keyColumnName")
|
||||||
final protected String _keyColumnName;
|
final protected String _keyColumnName;
|
||||||
|
@JsonProperty("valueColumnName")
|
||||||
final protected String _valueColumnName;
|
final protected String _valueColumnName;
|
||||||
|
|
||||||
|
@JsonProperty("prependColumnName")
|
||||||
|
@JsonInclude(Include.NON_NULL)
|
||||||
|
public Boolean getPrependColumnName() {
|
||||||
|
return _combinedColumnName == null ? null : _prependColumnName;
|
||||||
|
}
|
||||||
|
|
||||||
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
||||||
String combinedColumnName = JSONUtilities.getString(obj, "combinedColumnName", null);
|
return ParsingUtilities.mapper.readValue(obj.toString(), TransposeColumnsIntoRowsOperation.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
static public TransposeColumnsIntoRowsOperation deserialize(
|
||||||
|
@JsonProperty("combinedColumnName")
|
||||||
|
String combinedColumnName,
|
||||||
|
@JsonProperty("startColumnName")
|
||||||
|
String startColumnName,
|
||||||
|
@JsonProperty("columnCount")
|
||||||
|
int columnCount,
|
||||||
|
@JsonProperty("ignoreBlankCells")
|
||||||
|
Boolean ignoreBlankCells,
|
||||||
|
@JsonProperty("fillDown")
|
||||||
|
Boolean fillDown,
|
||||||
|
@JsonProperty("prependColumnName")
|
||||||
|
boolean prependColumnName,
|
||||||
|
@JsonProperty("separator")
|
||||||
|
String separator,
|
||||||
|
@JsonProperty("keyColumnName")
|
||||||
|
String keyColumnName,
|
||||||
|
@JsonProperty("valueColumnName")
|
||||||
|
String valueColumnName) {
|
||||||
|
ignoreBlankCells = ignoreBlankCells == null ? true : ignoreBlankCells;
|
||||||
|
fillDown = fillDown == null ? false : fillDown;
|
||||||
if (combinedColumnName != null) {
|
if (combinedColumnName != null) {
|
||||||
return new TransposeColumnsIntoRowsOperation(
|
return new TransposeColumnsIntoRowsOperation(
|
||||||
obj.getString("startColumnName"),
|
startColumnName,
|
||||||
obj.getInt("columnCount"),
|
columnCount,
|
||||||
JSONUtilities.getBoolean(obj, "ignoreBlankCells", true),
|
ignoreBlankCells,
|
||||||
JSONUtilities.getBoolean(obj, "fillDown", false),
|
fillDown,
|
||||||
combinedColumnName,
|
combinedColumnName,
|
||||||
obj.getBoolean("prependColumnName"),
|
prependColumnName,
|
||||||
obj.getString("separator")
|
separator);
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
return new TransposeColumnsIntoRowsOperation(
|
return new TransposeColumnsIntoRowsOperation(
|
||||||
obj.getString("startColumnName"),
|
startColumnName,
|
||||||
obj.getInt("columnCount"),
|
columnCount,
|
||||||
JSONUtilities.getBoolean(obj, "ignoreBlankCells", true),
|
ignoreBlankCells,
|
||||||
JSONUtilities.getBoolean(obj, "fillDown", false),
|
fillDown,
|
||||||
obj.getString("keyColumnName"),
|
keyColumnName,
|
||||||
obj.getString("valueColumnName")
|
valueColumnName);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +164,5 @@ public class SplitMultiValuedCellsTests extends RefineTest {
|
|||||||
Assert.assertEquals(project.rows.get(3).getCellValue(keyCol), null);
|
Assert.assertEquals(project.rows.get(3).getCellValue(keyCol), null);
|
||||||
Assert.assertEquals(project.rows.get(3).getCellValue(valueCol), "four");
|
Assert.assertEquals(project.rows.get(3).getCellValue(valueCol), "four");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user