Jackson deserialization for AbstractOperation
This commit is contained in:
parent
8f9004f7ee
commit
2ef955f24b
@ -78,7 +78,7 @@ public class ApplyOperationsCommand extends Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void reconstructOperation(Project project, JSONObject obj) {
|
protected void reconstructOperation(Project project, JSONObject obj) throws IOException {
|
||||||
AbstractOperation operation = OperationRegistry.reconstruct(project, obj);
|
AbstractOperation operation = OperationRegistry.reconstruct(project, obj);
|
||||||
if (operation != null) {
|
if (operation != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -36,6 +36,8 @@ package com.google.refine.model;
|
|||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonTypeIdResolver;
|
||||||
|
|
||||||
import com.google.refine.history.HistoryEntry;
|
import com.google.refine.history.HistoryEntry;
|
||||||
import com.google.refine.operations.OperationRegistry;
|
import com.google.refine.operations.OperationRegistry;
|
||||||
@ -46,6 +48,11 @@ import com.google.refine.process.QuickHistoryEntryProcess;
|
|||||||
* An abstract operation can be applied to different but similar
|
* An abstract operation can be applied to different but similar
|
||||||
* projects.
|
* projects.
|
||||||
*/
|
*/
|
||||||
|
@JsonTypeInfo(
|
||||||
|
use=JsonTypeInfo.Id.CUSTOM,
|
||||||
|
include=JsonTypeInfo.As.PROPERTY,
|
||||||
|
property="op")
|
||||||
|
@JsonTypeIdResolver(OperationResolver.class)
|
||||||
abstract public class AbstractOperation {
|
abstract public class AbstractOperation {
|
||||||
public Process createProcess(Project project, Properties options) throws Exception {
|
public Process createProcess(Project project, Properties options) throws Exception {
|
||||||
return new QuickHistoryEntryProcess(project, getBriefDescription(null)) {
|
return new QuickHistoryEntryProcess(project, getBriefDescription(null)) {
|
||||||
|
@ -33,6 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
package com.google.refine.operations;
|
package com.google.refine.operations;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@ -41,8 +42,12 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonParseException;
|
||||||
|
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||||
|
|
||||||
import com.google.refine.model.AbstractOperation;
|
import com.google.refine.model.AbstractOperation;
|
||||||
import com.google.refine.model.Project;
|
import com.google.refine.model.Project;
|
||||||
|
import com.google.refine.util.ParsingUtilities;
|
||||||
|
|
||||||
import edu.mit.simile.butterfly.ButterflyModule;
|
import edu.mit.simile.butterfly.ButterflyModule;
|
||||||
|
|
||||||
@ -67,25 +72,18 @@ public abstract class OperationRegistry {
|
|||||||
classes.add(klass);
|
classes.add(klass);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public AbstractOperation reconstruct(Project project, JSONObject obj) {
|
static public Class<? extends AbstractOperation> resolveOperationId(String op) {
|
||||||
try {
|
if (!op.contains("/")) {
|
||||||
String op = obj.getString("op");
|
op = "core/" + op; // backward compatible
|
||||||
if (!op.contains("/")) {
|
}
|
||||||
op = "core/" + op; // backward compatible
|
List<Class<? extends AbstractOperation>> classes = s_opNameToClass.get(op);
|
||||||
}
|
if (classes != null && classes.size() > 0) {
|
||||||
|
return classes.get(classes.size() - 1);
|
||||||
List<Class<? extends AbstractOperation>> classes = s_opNameToClass.get(op);
|
|
||||||
if (classes != null && classes.size() > 0) {
|
|
||||||
Class<? extends AbstractOperation> klass = classes.get(classes.size() - 1);
|
|
||||||
|
|
||||||
Method reconstruct = klass.getMethod("reconstruct", Project.class, JSONObject.class);
|
|
||||||
if (reconstruct != null) {
|
|
||||||
return (AbstractOperation) reconstruct.invoke(null, project, obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws IOException {
|
||||||
|
return ParsingUtilities.mapper.readValue(obj.toString(), AbstractOperation.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user